From 6493d15df0ba84ebc7063a9e396b7e85024e841c Mon Sep 17 00:00:00 2001 From: 206530225 <1225859578@qq.com> Date: Sun, 20 Jun 2021 15:47:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Alien_Invasion.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Alien_Invasion.py diff --git a/Alien_Invasion.py b/Alien_Invasion.py new file mode 100644 index 0000000..5450adc --- /dev/null +++ b/Alien_Invasion.py @@ -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() \ No newline at end of file