- 帖子
- 4
- 精华
- 0
- 积分
- 22
- 阅读权限
- 10
- 注册时间
- 2017-12-6
- 最后登录
- 2018-3-9
|
# -*- coding: utf-8 -*-
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 __int__(self):
'''初始化游戏的设置'''
#屏幕设置
self.screen_width = 1200
self.screen_height = 800
self.bg_color = (230, 230, 230)
老哥门上面那个脚本一直报错,求助呀
C:\Users\qlh\AppData\Local\Programs\Python\Python35\python.exe E:/python项目/打飞机第一步.py
Traceback (most recent call last):
File "E:/python项目/打飞机第一步.py", line 32, in <module>
run_game()
File "E:/python项目/打飞机第一步.py", line 12, in run_game
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
AttributeError: 'Settings' object has no attribute 'screen_width'
进程已结束,退出代码1
|
|