Ejemplo n.º 1
0
def check_play_button(ai_settings, screen, stats, sb, play_button, ship,
                      aliens, bullets, mouse_x, mouse_y):
    """在玩家单击Play按钮时开始新游戏"""
    button_clicked = play_button.rect.collidepoint(mouse_x, mouse_y)
    if button_clicked and not stats.game_active:
        # 重置游戏设置
        ai_settings.initialize_dynamic_settings()

        # 隐藏光标
        pygame.mouse.set_visible(False)

        # 重置游戏统计信息
        stats.reset_stats()
        stats.game_active = True

        # 重置记分牌图像
        sb.prep_score()
        sb.prep_high_score()
        sb.prep_level()
        sb.prep_ships()

        # 清空外星人列表和子弹列表
        aliens.empty()
        bullets.empty()

        # 创建一群新的外星人,并让飞船居中
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()
Ejemplo n.º 2
0
def check_play_button(ai_settings, screen, stats, sb, play_button, ship,
                      aliens, bullets, mouse_x, mouse_y):
    # Start a new game when the player clicks Play.
    button_clicked = play_button.rect.collidepoint(mouse_x, mouse_y)
    if button_clicked and not stats.game_active:
        # Reset the game settings.
        ai_settings.initialize_dynamic_settings()

        # Hide the mouse cursor.
        pygame.mouse.set_visible(False)

        # Reset the game statistics
        stats.reset_stats()
        stats.game_active = True

        # Reset the scoreboard images.
        sb.prep_score()
        sb.prep_high_score()
        sb.prep_level()
        sb.prep_ships()

        # Empty the list of aliens and bullets.
        aliens.empty()
        bullets.empty()

        # Create a new fleet and center the ship.
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()
Ejemplo n.º 3
0
def ship_hit(ai_settings, screen, stats, sb, ship, bullets, aliens):
    if stats.ships_left > 0:
        stats.ships_left -= 1
        sb.prep_ships()
        aliens.empty()
        bullets.empty()
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()
        pygame.mixer.music.load('gameover.mp3')
        pygame.mixer.music.play()
        sleep(1)
    else:
        stats.game_active = False
        pygame.mouse.set_visible(True)
Ejemplo n.º 4
0
def ship_hit(ai_setting, screen, ship, aliens, bullets, game_stats):
    """结束游戏的相关操作"""
    sleep(0.5)
    """发生碰撞后先暂停1秒,之后清空子弹和外星人飞船列表"""
    aliens.empty()
    bullets.empty()

    #创建新的一群外星人,飞船生命减一,重置飞船位置
    create_fleet(ai_setting, screen, aliens, ship, game_stats)
    game_stats.ship_left -= 1

    ship.center_ship()
    sleep(1)

    print("游戏结束")
    """方法spritecollideany()接受两个实参:一个精灵和一个编组。
Ejemplo n.º 5
0
def empire_hit(ai_settings, stats, screen, ship, fleet, bullets):
    """Respond to ship being hit by alien."""
    if stats.ships_left > 0:
        # Decrement ships_left.
        stats.ships_left -= 1
        # Empty the list of empire ships and bullets.
        fleet.empty()
        bullets.empty()
        #Create a new fleet and center the ship.
        create_fleet(ai_settings,screen,fleet,ship)
        ship.center_ship()
        # Pause.
        sleep(0.5)
    else:
        stats.game_active = False
        pygame.mouse.set_visible(True)
Ejemplo n.º 6
0
def ship_hit(ai_settings, stats, screen, ship, aliens, bullets):
    """Working with aliens-ship hit"""
    if stats.ships_left > 0:
        # Decreasing of ship_left
        stats.ships_left -= 1
        #deleting list of aliens and bullets
        aliens.empty()
        bullets.empty()
        # Creation of new fleet and ship in the center
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()
        # Pause
        sleep(1)
    else:
        stats.game_active = False
        pygame.mouse.set_visible(True)
Ejemplo n.º 7
0
def start_game(ai_settings, stats, screen, ship, aliens, bullets):
    ai_settings.initialize_dynamic_settings()

    # 隐藏光标
    pygame.mouse.set_visible(False)

    # 重置游戏统计信息
    stats.reset_stats()
    stats.game_active = True

    # 清空外星人列表和子弹列表
    aliens.empty()
    bullets.empty()

    # 创建一群新的外星人,并让飞船居中
    create_fleet(ai_settings, screen, ship, aliens)
    ship.center_ship()
Ejemplo n.º 8
0
def check_play_button(stats, play_button, mouse_x, mouse_y,ai_settings, screen, ship, fleet,bullets,sb):
    button_clicked = play_button.rect.collidepoint(mouse_x, mouse_y)
    if button_clicked and not stats.game_active:
        # Reset Game Settings
        ai_settings.dynamic_settings()
        pygame.mouse.set_visible(False)
        stats.reset_stats()
        stats.game_active = True
        # Reset Level and Score
        sb.prep_score()
        sb.prep_level()
        # Empty Groups
        fleet.empty()
        bullets.empty()
        # Create new fleet and center rebellion ship
        create_fleet(ai_settings,screen,fleet,ship)
        ship.center_ship()
Ejemplo n.º 9
0
def check_play_button(ai_settings, screen, ship, aliens, bullets, stats, sb,
                      play_button, mouse_x, mouse_y):
    button_clicked = play_button.rect.collidepoint(mouse_x, mouse_y)
    if button_clicked and not stats.game_active:
        pygame.mixer.music.load('sochenge.mp3')
        pygame.mixer.music.play()
        ai_settings.intialize_dynamic_settings()
        pygame.mouse.set_visible(False)
        stats.reset_stats()
        stats.game_active = True
        sb.prep_score()
        sb.prep_high_score()
        sb.prep_level()
        sb.prep_ships()
        aliens.empty()
        bullets.empty()
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()
Ejemplo n.º 10
0
def ship_hit(ai_settings, stats, screen, ship, aliens, bullets):
    """Respond to ship being hit by alien."""
    if stats.ships_left > 0:
        # Decrement ships_left.
        stats.ships_left -= 1

        # Empty the list of aliens and bullets.
        aliens.empty()
        bullets.empty()

        # Create a new fleet and center the ship.
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()

        # Pause.
        sleep(0.5)
    else:
        stats.game_active = False
Ejemplo n.º 11
0
def check_play_button(ai_settings, screen, stats, sb, play_button, ship,
                      aliens, bullets, mouse_x, mouse_y):
    """Starting new game after press Play"""
    button_clicked = play_button.rect.collidepoint(mouse_x, mouse_y)
    if button_clicked and not stats.game_active:
        # Drop of game settings
        ai_settings.initialize_dynamic_settings()
        # Hide mouse cursor
        pygame.mouse.set_visible(False)
        # Drop of statistics
        stats.reset_stats()
        stats.game_active = True
        # Drop of score and level image
        sb.prep_score()
        sb.prep_high_score()
        sb.prep_level()
        #cleaning up bullets and aliens
        aliens.empty()
        bullets.empty()
        # Creating new ship and setting it up in center
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()
Ejemplo n.º 12
0
def ship_hit(ai_settings, screen, stats, sb, ship, aliens, bullets):
    # Respond to ship being hit by alien.
    if stats.ships_left > 0:
        # Decrement ships left.
        stats.ships_left -= 1

        # Update the scoreboard.
        sb.prep_ships()

        # Empty the list of aliens and bullets.
        aliens.empty()
        bullets.empty()

        # Create a new fleet and center the ship.
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()

        # Pause
        sleep(0.5)

    else:
        stats.game_active = False
        pygame.mouse.set_visible(True)
Ejemplo n.º 13
0
def ship_hit(ai_settings, stats, screen, sb, ship, aliens, bullets):
    """响应被外星人撞到的飞船"""
    if stats.ship_left > 0:

        # 将ships_left减1
        stats.ship_left -= 1

        # 更新记分牌
        sb.prep_ships()

        # 清空外星人列表和子弹列表
        aliens.empty()
        bullets.empty()

        # 创建一群新的外星人,并将飞船放到屏幕底端中央
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()

        # 暂停
        sleep(0.5)

    else:
        stats.game_active = False
        pygame.mouse.set_visible(True)