pycharm环境下Python编译报错问题——飞船大战外星人问题

Yanir7 2018-08-03 02:55:44

import sys
import pygame
from settings import Settings


def run_game():
# 初始化游戏并创建一个屏幕对象
pygame.init()
ai_settings = Settings
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# 设置背景色
# bg_color = (230,230,230,)
# 开始游戏的主循环
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()


class Settings:
"""存储《外星人入侵》的所有设置的类"""

def __init__(self):
"""初始化游戏的设置"""
# 屏幕设置
self.screen_width = 1200
self.screen_height = 800
self.bg_color = (230, 230, 230)



报错:
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
AttributeError: type object 'Settings' has no attribute 'screen_width'
...全文
401 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxlzxvs 2020-11-09
  • 打赏
  • 举报
回复 1
改成ai_settings=Settings()
一笑程序猴 2019-07-24
  • 打赏
  • 举报
回复
ai_settings = Settings
改为
ai_settings = Settings()
Qn汪小洋 2019-07-24
  • 打赏
  • 举报
回复
ai_settings = Settings这里应该再Settings后面加上()
kuangbao9 2018-08-07
  • 打赏
  • 举报
回复
def __init__(self)改成这样def __init__(self,screen_width,screen_height,bg_color)??

37,719

社区成员

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

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