Пример #1
0
def opening_screen(ai_settings, game_stats, screen):
    """Display the menu in the beginning"""

    # Set up screen attributes
    menu = Intro(ai_settings, game_stats, screen)
    play_button = Button(ai_settings, screen, 'Play Game', y_factor=0.70)
    hs_button = Button(ai_settings, screen, 'High Scores', y_factor=0.80)
    intro = True

    # Manages the key presses of the game
    while intro:
        for events in pygame.event.get():
            if events.type == pygame.QUIT:
                return False
            elif events.type == pygame.MOUSEBUTTONDOWN:
                click_x, click_y = pygame.mouse.get_pos()
                game_stats.game_active = play_button.check_button(click_x, click_y)
                intro = not game_stats.game_active
                if hs_button.check_button(click_x, click_y):
                    ret_hs = high_score_screen(ai_settings, screen)
                    if not ret_hs:
                        return False

        screen.fill(ai_settings.bg_color)
        # Allow the menu to display on the top layer
        menu.show_menu()
        # Draw the button on the main screen
        hs_button.draw_button()
        play_button.draw_button()

        # Display past
        pygame.display.flip()

    return True
Пример #2
0
def startup_screen(ai_settings, game_stats, screen):
    """Display the startup menu on the screen, return False if the user wishes to quit,
    True if they are ready to play"""
    menu = Intro(ai_settings, game_stats, screen)
    play_button = Button(ai_settings, screen, 'Play Game', y_factor=0.70)
    hs_button = Button(ai_settings, screen, 'High Scores', y_factor=0.80)
    intro = True

    while intro:
        play_button.alter_text_color(*pygame.mouse.get_pos())
        hs_button.alter_text_color(*pygame.mouse.get_pos())
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                click_x, click_y = pygame.mouse.get_pos()
                game_stats.game_active = play_button.check_button(
                    click_x, click_y)
                intro = not game_stats.game_active
                if hs_button.check_button(click_x, click_y):
                    ret_hs = high_score_screen(ai_settings, game_stats, screen)
                    if not ret_hs:
                        return False
        screen.fill(ai_settings.bg_color)
        menu.show_menu()
        hs_button.draw_button()
        play_button.draw_button()
        pygame.display.flip()

    return True
def high_score_screen(ai_settings, game_stats, screen):
    hs_screen = HighScoreScreen(ai_settings, screen, game_stats)
    back_button = Button(ai_settings, screen, 'Back To Menu', y_factor=0.85)

    while True:
        back_button.alter_text_color(*pygame.mouse.get_pos())
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if back_button.check_button(*pygame.mouse.get_pos()):
                    return True
        screen.fill(ai_settings.bg_color)
        hs_screen.show_scores()
        back_button.draw_button()
        pygame.display.flip()
Пример #4
0
def startup_screen(config, game_stats, screen):
    """Display an introductory startup screen for the game, return False if the user wishes to quit,
    True if the user is ready to play"""
    title_screen = Intro(config, game_stats, screen)
    title_screen.prep_image()
    button = Button(config, screen, 'Play')
    intro = True

    while intro:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                click_x, click_y = pygame.mouse.get_pos()
                game_stats.game_active = button.check_button(click_x, click_y)
                intro = not game_stats.game_active
        screen.fill(config.bg_color)
        title_screen.show_menu()
        button.draw_button()
        pygame.display.flip()

    return True
Пример #5
0
def high_score_screen(ai_settings, screen):
    """Display all high scores in a separate screen with a back button"""
    # Set the screen attributes
    hs_screen = HighScoreScreen(ai_settings, screen)
    back_button = Button(ai_settings, screen, 'Back To Menu', y_factor=0.85)

    while True:
        # Functions of the game when key presses touched
        for events in pygame.event.get():
            if events.type == pygame.QUIT:
                return False
            elif events.type == pygame.MOUSEBUTTONDOWN:
                if back_button.check_button(*pygame.mouse.get_pos()):
                    return True

        screen.fill(ai_settings.bg_color)
        # Allow to show the scores on the high score screen
        hs_screen.show_scores()
        # Redraw button
        back_button.draw_button()
        # Display past
        pygame.display.flip()