上传文件至 ''

This commit is contained in:
206530225 2021-06-20 15:47:14 +08:00
parent 96a2dfa981
commit 6493d15df0
1 changed files with 28 additions and 0 deletions

28
Alien_Invasion.py Normal file
View File

@ -0,0 +1,28 @@
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("消灭外星人")
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.bg_color) # 每次循环时都重绘屏幕
self.ship.blitme() # 让最近绘制的屏幕可见
pygame.display.flip()
if __name__ == '__main__': # 创建游戏实例并运行游戏
ai = AlienInvasion()
ai.run_game()