|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
game.py
import 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'
实在不懂为什么?
|
|