如题。
调试很久也不知道问题出自哪里,代码如下:
import pygame
import sys
class Settings:
def __init__(self):
self.screen_width = 800
self.screen_height = 800
self.bg_color = (230, 230, 230)
class Ship:
def __init__(self, ai_game):
self.ship_image = pygame.image.load("D:\python\ship.bmp")
self.ship_rect = self.ship_image.get_rect()
self.screen = ai_game.screen
self.screen_rect = ai_game.screen.get_rect()
self.ship_rect.midbottom = self.screen_rect.midbottom
def show(self):
self.screen.blit(self.ship_image, self.ship_rect)
class AlienInvasion:
def __init__(self):
pygame.init()
self.ship = Ship(self)
self.settings = Settings()
self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
pygame.display.set_caption("飞机大站")
def check_events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
def update_events(self):
self.screen.fill(self.settings.bg_color)
pygame.display.flip()
def run_game(self):
while True:
self.check_events()
self.ship.show()
self.update_events()
ai = AlienInvasion()
ai.run_game()