Exemplo n.º 1
0
def question(q,
             pos,
             size=(300, 50),
             fontsize=fontSize,
             allowanswer=1,
             default='',
             waitForAnswer=1):
    qsurf = InputBox(screen,
                     pos,
                     size,
                     q,
                     allowanswer,
                     fontsize=fontsize,
                     a=default)
    pygame.display.update()
    finished = 0
    answer = None
    if waitForAnswer:
        while not finished:
            for event in pygame.event.get():
                finished, answer = qsurf.handle_event(event)
                qsurf.draw(screen)
                pygame.display.update()
    return answer
Exemplo n.º 2
0
def game_over():
    score_list = get_scoreboard()
    good_run = is_good_run(score_list)

    large_text = LARGE_FONT.render("Game Over", True, PURPLE)
    text_rect = large_text.get_rect()
    text_rect.center = (window_width // 2, window_height // 2 - 100)
    window.blit(large_text, text_rect)

    restart_button = Button("Restart", window_width // 2 + 50, 500, 100, 200,
                            PURPLE, GREEN, BLACK, 40)
    menu_button = Button("Main Menu", window_width // 2 - 250, 500, 100, 200,
                         PURPLE, GREEN, BLACK, 40)

    if good_run:
        input_box = InputBox(window_width // 2, 420, 130, 30)
        text = None

        name_text = SMALL_FONT.render("Enter your name: ", True, PURPLE)
        text_rect = name_text.get_rect()
        text_rect.center = (window_width // 2, window_height // 2)
        window.blit(name_text, text_rect)

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()

                text = input_box.handle_event(event)
            if text:
                update_scoreboard(score_list, text)

            input_box.draw(window)

            mouse_pos = pygame.mouse.get_pos()
            mouse_clicks = pygame.mouse.get_pressed()
            restart_button.draw(mouse_pos, window)
            menu_button.draw(mouse_pos, window)

            if restart_button.is_clicked(mouse_pos, mouse_clicks):
                main_game()
            elif menu_button.is_clicked(mouse_pos, mouse_clicks):
                game_menu(True)

            pygame.display.update()
            clock.tick(15)
    else:
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()

            mouse_pos = pygame.mouse.get_pos()
            mouse_clicks = pygame.mouse.get_pressed()
            restart_button.draw(mouse_pos, window)
            menu_button.draw(mouse_pos, window)

            if restart_button.is_clicked(mouse_pos, mouse_clicks):
                main_game()
            elif menu_button.is_clicked(mouse_pos, mouse_clicks):
                game_menu(True)

            keys = pygame.key.get_pressed()
            if keys[pygame.K_r]:
                main_game()

            pygame.display.update()
            clock.tick(15)