コード例 #1
0
ファイル: game.py プロジェクト: Carbonem1/Arcade-Game
def drawPlayAgainMenu(DISPLAYSURF):
    play_again_option = Option(DISPLAYSURF, WHITE, font, "PLAY AGAIN?", (config.display_x // 2 - 100, config.display_y // 2 - 100))
    while (True):
        play_again_option.draw()
        for option in playAgainMenuOptions:
            option.draw()
        drawStatsMenu(DISPLAYSURF)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            for option in playAgainMenuOptions:
                if option.rect.collidepoint(pygame.mouse.get_pos()):
                    option.hovered = True
                    #sound_hover_menu_item.play()
                    if event.type == MOUSEBUTTONUP:
                        # play sound
                        sound_select_menu_item.play()

                        if option.text == "YES":
                            os.execl(sys.executable, sys.executable, *sys.argv)
                            return False
                        if option.text == "NO":
                            pygame.quit()
                            sys.exit()
                        if option.text == "MAIN MENU":
                            drawMainMenu(DISPLAYSURF)
                        option.hovered = False
                else:
                    option.hovered = False

        pygame.display.update()
    return True
コード例 #2
0
ファイル: game.py プロジェクト: Carbonem1/Arcade-Game
def drawLeaderboardMenu(DISPLAYSURF):
    DISPLAYSURF.fill((0,0,0))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

    connection = mysql.connector.connect(user = config.USER, password = config.PASSWORD, host = config.HOST, database = config.DATABASE)
    cursor = connection.cursor()

    query = ("SELECT name, total_kills FROM high_scores "
         "ORDER BY total_kills DESC "
         "LIMIT 10")

    cursor.execute(query)

    x_spacing = 250
    y_spacing = 0

    for (name, score) in cursor:
        name_option = Option(DISPLAYSURF, BLUE, font, "Name: " + str(name), (config.display_x // 2 - config.display_x // 4, (config.display_y // 5 + y_spacing)))
        score_option = Option(DISPLAYSURF, BLUE, font, "Score: " + str(score), (config.display_x // 2 + config.display_x // 10, (config.display_y // 5 + y_spacing)))
        name_option.draw()
        score_option.draw()
        y_spacing += 50

    back_option = Option(DISPLAYSURF, BLUE, font, "BACK", (config.display_x // 2 - len("BACK") * 10, (config.display_y - 100)))
    while(True):
        for event in pygame.event.get():
            if back_option.rect.collidepoint(pygame.mouse.get_pos()):
                back_option.hovered = True
                #sound_hover_menu_item.play()
                if event.type == MOUSEBUTTONUP:
                    # play sound
                    sound_select_menu_item.play()
                    cursor.close()
                    connection.close()
                    drawMainMenu(DISPLAYSURF)
                    return
            else:
                back_option.hovered = False
        pygame.display.update()
        back_option.draw()
    cursor.close()
    connection.close()