Ejemplo n.º 1
0
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")

    # 创建Play按钮
    play_button = Button(ai_settings, screen, "Play")

    #创建一艘飞船,创建一个用于存储子弹的编组和一个外星人编组,一个用于存储游戏统计信息的实例,创建记分牌
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    #创建一个外星人群
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # 开始游戏的主循环
    while True:
        # 监视键盘和鼠标事件
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)

        if stats.game_active:
            ship.updata()
            gf.updata_bullets(ai_settings, screen, stats, sb, ship, bullets, aliens)
            gf.updata_aliens(ai_settings, stats, screen, ship, aliens, bullets, sb)

        gf.updata_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
Ejemplo n.º 2
0
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")

    #创建一个飞船
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

    gf.create_fleet(ai_settings, screen, ship, aliens)

    stats = GameStats(ai_settings)

    play_button = Button(ai_settings, screen, "Play")

    scoreboard = Scoreboard(ai_settings, screen, stats)

    while True:

        gf.check_events(ai_settings, screen, stats, play_button, ship, aliens,
                        bullets, scoreboard)
        if stats.game_active == True:
            ship.update()
            gf.updata_bullets(bullets, aliens, ai_settings, screen, ship,
                              scoreboard, stats)
            gf.update_aliens(ai_settings, aliens, ship, screen, stats, bullets,
                             scoreboard)

        gf.updata_screen(ai_settings, screen, ship, aliens, bullets,
                         play_button, stats, scoreboard)
Ejemplo n.º 3
0
def run_game():
    """初始化游戏并创建一个屏幕对象"""
    pygame.init()
    ai_setting = Settings()
    screen = pygame.display.set_mode(
        (ai_setting.screen_width,
         ai_setting.screen_height))  #设立一个像素为1200,800的显示窗口
    pygame.display.set_caption("alien_game")  #set_mode的实参为一个元组
    ship = Ship(screen, ai_setting)  #创建飞船
    bullets = Group()  #创建一个子弹元组
    #alien = Alien(screen,ai_setting)                            #创建一个外星人
    aliens = Group()  #创建一个外星人编组

    #用于构建一个群
    gf.create_fleet(ai_setting, screen, ship, aliens)

    #用于绘制按钮
    play_button = Button(ai_setting, screen, "play")

    #用于统计游戏信息
    stats = Gamestats(ai_setting)

    #计分牌
    sb = Scoreboard(ai_setting, stats, screen)

    #开始 游戏主循环

    while True:

        #用于管理事件(要处在游戏启动之外)
        gf.chck_events(ai_setting, screen, ship, aliens, bullets, stats,
                       play_button, sb)

        if stats.game_active:
            #用于移动飞船
            ship.updata()
            #用于发射子弹
            gf.updata_bullets(bullets, aliens, ai_setting, screen, ship, stats,
                              sb)
            #用于外星人移动
            gf.update_aliens(ai_setting, screen, stats, ship, bullets, aliens,
                             sb)

        #用于显示图像
        gf.update_screen(screen, ai_setting, ship, aliens, bullets, stats,
                         play_button, sb)
Ejemplo n.º 4
0
def run_game():
    #初始化pygame、设置和屏幕对象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_with,ai_settings.screen_height))
    pygame.display.set_caption("Alien Tnvasion")
    #创建一艘飞船
    ship = Ship(ai_settings,screen)
    #创建一个用于存储子弹的编组
    bullets = Group()

    #开始游戏的主循环
    while True:
        gf.check_events(ai_settings,screen,ship,bullets)
        ship.update()
        gf.updata_bullets(bullets)

        gf.update_screen(ai_settings,screen,ship,bullets)
Ejemplo n.º 5
0
def run_game():
    #初始化pygame、设置、和屏幕对象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    #screen = pygame.display.set_mode((1200,800))
    pygame.display.set_caption("Aline Invasion")

    #创建一个用于存储游戏统计信息的实例
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    #创建一艘飞船
    ship = Ship(ai_settings, screen)
    #创建一个外星人编组
    aliens = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)
    #创建一个存储子弹的编组
    bullets = Group()
    #创建play按钮
    play_button = Button(ai_settings, screen, "Play")

    #开始游戏的主循环
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)
        if stats.game_active:
            ship.update()
            print(len(bullets))
            gf.updata_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, stats, screen, sb, ship, aliens,
                             bullets)
        #每次循环时都重绘屏幕
        gf.updata_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         play_button)