为什么我实践书里的例子出错?

江南大富翁 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'
...全文
137 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
chuifengde 2017-09-09
  • 打赏
  • 举报
回复
def _init_(self):==》def __init__(self):

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧