望大神解答!!!
game.pyimport sys
import pygame
from settings import Settings
def run_game():
#初始化游戏并创建一个游戏对象
pygame.init()
#初始化pygame、设置和屏幕对象
ai_settings = Settings()
screen = pygame.display.set_mode(
(ai_settings.screen_width,ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
#开始游戏的循环
while True:
#监视键盘和鼠标事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#每次循环都重绘屏幕
screen.fill(ai_settings.bg_color)
#让最近绘制的屏幕可见
pygame.display.flip()
run_game()
setting.py
class Settings():
"""存储《外星人入侵》的所有设置的类"""
def __int__(self):
"""初始化游戏的设置"""
#屏幕设置
self.screen_width = 1200
self.screen_height = 700
self.bg_color = (230,230,230)
game.py中调用setting.py中的Settings类时出现以下错误:
screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
AttributeError: 'Settings' object has no attribute 'screen_width'
实在不懂为什么?
def __init__(self):
你写成了__int__ fish_游鱼 发表于 2018-11-5 16:15
def __init__(self):
你写成了__int__
问题已解决,谢谢!
页:
[1]