为什么我实践书里的例子出错?
江南大富翁 2017-09-09 05:07:48 import pygame
class Settings():
'''存储《外星人入侵》的所有设置的类'''
def _init_(self):
self.screen_width = 800
self.screen_height = 600
self.bg_color = (230,230,230)
def run_game():
#初始化游戏并创建一个屏幕
pygame.init()
ai = Settings()
screen=pygame.display.set_mode((800,600))
pygame.display.set_caption("game over")
#开始游戏的主循环
while True:
#监视键盘和鼠标事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(ai.bg_color)
#让最近绘制的屏幕可见
pygame.display.flip()
run_game()
报错如下:
Traceback (most recent call last):
File "G:\1.py", line 25, in <module>
run_game()
File "G:\1.py", line 22, in run_game
screen.fill(ai.bg_color)
AttributeError: 'Settings' object has no attribute 'bg_color'