入门的飞船问题报错,哪位大佬帮帮小弟 Traceback (most recent call last): File "C:/Users/Mario、/PycharmProjects/alien game/main.py", line 19, in <module> run_game() File "C:/Users/Mario、/PycharmProjects/alien game/main.py", line 8, in run_game print(ai_settings.screen_height) AttributeError: 'Settings' object has no attribute 'screen_height' Process finished with exit code 1 main.py
import sys
import pygame
from settings import Settings
from ship import Ship
def run_game():
pygame.init()
ai_settings = Settings()
print(ai_settings.screen_height)
screen=pygame.display.set_mode(
(ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
ship = Ship(screen)
while True:
for event in pygame.event.get():
if event.type == game.QUIT:
sys.exit()
screen.fill(ai_settings.bg_color)
pygame.diplay.flip()
run_game()
setting.py
class Settings():
def __int__(self):
self.screen_width = 1200
self.screen_height = 800
self.bg_color = (230,230,230)
class adminSettings(): def __int__(self): self.screen_width=0 self.screen_height =0 self.bg_color = 0 def add_screen_height(self): self.screen_height = 800 def add_screen_width(self): self.screen_width = 1200 def add_bg_color(self): self.bg_color = (230, 230, 230)
ai_settings = adminSettings() ai_settings.add_screen_width() print(ai_settings.screen_width)
兄弟,你的setting.py的__init__写成了__int__,所以才错了啊。。。。。。