马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
哪里错了import sys
import pygame
from settings import Settings
from ship import Ship
class AlienInvasion:
"""管理游戏资源和行为的类"""
def __init__(self):
"""初始化游戏并创建游戏资源。"""
pygame.init()
self.settings = Settings()
self.screen = pygame.display.set_mode(
(self.settings.screen_width, self.settings.screen_height))
pygame.display.set_caption("Alien Invasion")
self.ship = Ship(self)
def run_game(self):
"""开始游戏主循环"""
while True:
#监视键盘与鼠标事件.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#每次循环都重绘屏幕
self.screen.fill(self.settings.by_colour)
self.ship.blitme()
#让最近绘制的屏幕可见.
pygame.display.flip()
if __name__ == '__main__':
#创建游戏事例并运行游戏.
ai = AlienInvasion()
ai.run_game
————————————————————
以下是下一个程序
class Settings:
"""储存游戏中所有项"""
def __init__(self):
"""初始化游戏设置"""
#屏幕设置
self.screen_width = 1200
self.screen_height = 800
self.bg_colour = ( 230, 230, 230)
————————————————————
import pygame
class Ship:
"""管理飞船的类"""
def __init__(self,ai_game):
"""初始化飞船并确认位置"""
self.screen = ai_game.screen
self.screen_rect = ai_game.screen.get_rect()
#加载飞船图像并获取其外接矩形
self.image = pygame.image.load("D:\llllllllllllllllllllllllllllllll\kunkun\ship.bmp")
self.rect = self.image.get_rect()
#每一艘飞船都放在屏幕底部
self.rect.midbottom = self.screen_rect.midbottom
def blitme(self):
"""在指定位置绘制飞船"""
self.screen.blit(self.image, self.rect)
|