Esempio n. 1
0
def start_screen_setup(update_status=""):
    SCREEN.fill(Static.WHITE)
    logo = "BuzzingaLogo.bmp"
    picture = load_image(logo, 'images')
    picture_size = picture.get_rect().size
    rela = picture_size[0] / picture_size[0]
    picture = pygame.transform.scale(
        picture, (int(SCREEN_WIDTH / 4), int((SCREEN_WIDTH / 4) * rela)))
    SCREEN.blit(
        picture,
        picture.get_rect(center=(int(SCREEN_WIDTH / 2),
                                 int(SCREEN_HEIGHT / 3))))
    text_surf, text_rect = text_objects(
        'Press any key or <u> to update Buzzinga', SMALL_TEXT)
    text_rect.center = (int(SCREEN_WIDTH / 2), int(SCREEN_HEIGHT / 10 * 7))
    SCREEN.blit(text_surf, text_rect)
    if not type(update_status) == str:
        update_status = str(update_status, "utf-8")
    update_status = update_status.split("\n")
    if len(update_status) >= 2 and update_status[-2] == "None":
        update_status = update_status[:-2]
    line = 0
    for l in update_status:
        text_surf, text_rect = text_objects(l, MINI_TEXT)
        text_rect.center = (int(SCREEN_WIDTH / 2),
                            int(SCREEN_HEIGHT / 10 * (7.5 + line)))
        SCREEN.blit(text_surf, text_rect)
        line += 0.3
    pygame.display.update()
Esempio n. 2
0
def button(text,
           x,
           y,
           w,
           h,
           click,
           inactive_color=Static.RED,
           active_color=Static.LIGHT_RED,
           text_color=Static.WHITE,
           image=False):
    mouse = pygame.mouse.get_pos()
    return_value = False
    if x < mouse[0] < x + w and y < mouse[1] < y + h:
        pygame.draw.rect(SCREEN, active_color, (x, y, w, h))
        if click and pygame.time.get_ticks() > 100:
            return_value = True
    else:
        pygame.draw.rect(SCREEN, inactive_color, (x, y, w, h))
    if not image:
        text_surf, text_rect = text_objects(text, SMALL_TEXT, color=text_color)
        text_rect.center = (int(x + w / 2), int(y + h / 2))
        SCREEN.blit(text_surf, text_rect)
    else:
        image_file = load_image(text, '/home/pi/Desktop/venv/mycode/images')
        image_size = image_file.get_rect().size
        rela = image_size[0] / float(image_size[1])
        image_file = pygame.transform.scale(image_file,
                                            (int(h / 2 * rela), int(h / 2)))
        SCREEN.blit(image_file,
                    image_file.get_rect(center=pygame.Rect(x, y, w, h).center))
    return return_value
Esempio n. 3
0
 def random_pick_content():
     global random_key
     global random_val
     global random_sound
     global winner_found
     try:
         random_key = random.choice(list(content_dict.keys()))
         random_val = content_dict[random_key]
         del content_dict[random_key]
     except:
         winner_found = True
     if game_type == "images":
         if not winner_found:
             random_content = load_image(random_val, content_dir)
             image_size = random_content.get_rect().size
             if image_size[0] >= image_size[1]:
                 if int((image_size[1] / float(image_size[0])) *
                        picture_width) < picture_length:
                     image_size = (
                         picture_width,
                         int((image_size[1] / float(image_size[0])) *
                             picture_width))
                 else:
                     image_size = (int(
                         (image_size[0] / float(image_size[1])) *
                         picture_length), picture_length)
             else:
                 if int((image_size[0] / float(image_size[1])) *
                        picture_length) < picture_width:
                     image_size = (int(
                         (image_size[0] / float(image_size[1])) *
                         picture_length), picture_length)
                 else:
                     image_size = (
                         picture_width,
                         int((image_size[1] / float(image_size[0])) *
                             picture_width))
             random_content = pygame.transform.scale(
                 random_content, image_size)
             pygame.draw.rect(screen, Static.WHITE, picture_container)
             screen.blit(
                 random_content,
                 random_content.get_rect(center=picture_container.center))
             screen.blit(
                 progress,
                 progress.get_rect(center=picture_counter_container.center))
         else:
             show_winner()
     else:
         random_sound = pygame.mixer.Sound(random_val)
         sound_channel.play(random_sound)
         if not winner_found:
             pygame.draw.rect(screen, Static.WHITE, solution_container)
             screen.blit(
                 progress,
                 progress.get_rect(center=picture_counter_container.center))
         else:
             show_winner()
     return random_key, winner_found
Esempio n. 4
0
def print_player_name(x, playerName):
    x, y, w, h = button_layout_28[x + 7]
    pygame.draw.rect(SCREEN, Static.WHITE, (x, y, w, h))
    pygame.draw.rect(SCREEN, Static.LIGHT_RED, (x, y, w, h), 5)
    pygame.draw.rect(SCREEN, Static.LIGHT_RED,
                     (x - w / 4, y - 2, w / 4, h + 3))
    image_file = load_image('user.bmp', '/home/pi/Desktop/venv/mycode/images')
    image_size = image_file.get_rect().size
    rela = image_size[0] / float(image_size[1])
    image_file = pygame.transform.scale(image_file,
                                        (int(h / 2 * rela), int(h / 2)))
    SCREEN.blit(
        image_file,
        image_file.get_rect(center=pygame.Rect(x - w / 4, y, w / 4, h).center))
    text_surf, text_rect = text_objects(playerName, SMALL_TEXT, Static.RED)
    text_rect.center = (int(x + w / 2), int(y + h / 2))
    SCREEN.blit(text_surf, text_rect)
    pygame.display.update()
Esempio n. 5
0
def multiple_choice_game(players, playerNamesList, content_dir, screen,
                         screenx, screeny, game_modus, points_to_win):
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.mixer.init()

    # declare and array for player names and initial score
    playerNames = playerNamesList
    playerScore = [0] * players
    # key definitions
    player1Keys = [1, 2, 3, 4]
    player2Keys = [6, 7, 8, 9]
    player3Keys = [11, 12, 13, 14]
    player4Keys = [16, 17, 18, 19]

    # Set the fonts for the textf
    myfont = pygame.font.SysFont("Ariel", 50)
    scorefont = pygame.font.SysFont("Ariel", 100)

    # defining the container for the graphical elements
    game_label_container_width = screenx / 10 * 8
    game_label_container_height = screeny / 10
    game_label_container = pygame.Rect(0, 0, game_label_container_width,
                                       game_label_container_height)
    picture_container_width = game_label_container_width
    picture_container_height = screeny / 10 * 8
    picture_container = pygame.Rect(0, game_label_container_height,
                                    picture_container_width,
                                    picture_container_height)
    question_container_width = game_label_container_width
    question_container_height = screeny / 10 * 3
    question_container = pygame.Rect(0, game_label_container_height,
                                     question_container_width,
                                     question_container_height)
    option_container_width = (game_label_container_width / 2) - 10
    option_container_height = (screeny / 10 * 2.5) - 10
    option1_container = pygame.Rect(
        10, game_label_container_height + question_container_height,
        option_container_width, option_container_height)
    option2_container = pygame.Rect(
        10 + option_container_width,
        game_label_container_height + question_container_height,
        option_container_width, option_container_height)
    option3_container = pygame.Rect(
        10, game_label_container_height + question_container_height +
        option_container_height, option_container_width,
        option_container_height)
    option4_container = pygame.Rect(
        10 + option_container_width, game_label_container_height +
        question_container_height + option_container_height,
        option_container_width, option_container_height)
    solution_container_width = picture_container_width
    solution_container_height = screeny / 10
    solution_container = pygame.Rect(
        0, (game_label_container_height + picture_container_height),
        solution_container_width, solution_container_height)
    picture_counter_container_width = screenx / 10 * 2
    picture_counter_container_height = screeny / 10
    picture_counter_container = pygame.Rect(game_label_container_width, 0,
                                            picture_counter_container_width,
                                            picture_counter_container_height)
    scoreboard_container_width = picture_counter_container_width
    scoreboard_container_height = screeny / 10 * 8
    player_container_width = scoreboard_container_width
    player_container_height = scoreboard_container_height / 4
    player_label_container_width = player_container_width
    player_label_container_height = player_container_height / 10 * 3
    player_buzzer_container_width = player_container_width / 2
    player_buzzer_container_height = player_container_height / 10 * 7
    player_score_container_width = player_container_width / 2
    player_score_container_height = player_container_height / 10 * 7

    # text displayed at the beginning
    head, tail = os.path.split(content_dir)
    game_name = tail[:-5].replace('_', ' ')
    welcome = u"Willkommen zu " + game_name

    logo = "BuzzingaLogo.bmp"
    picture = load_image(logo, 'images')

    content_dict = {}
    with open(content_dir) as json_file:
        data = json.load(json_file)
    for q in data:
        content_dict[q["fields"]["quiz_question"]] = {
            'solution': q["fields"]["solution"],
            'option1': q["fields"]["option1"],
            'option2': q["fields"]["option2"],
            'option3': q["fields"]["option3"]
        }

    # loading info
    loading = myfont.render("loading...", 1, Static.RED)
    screen.fill(Static.WHITE)
    screen.blit(loading, loading.get_rect(center=picture_container.center))
    pygame.display.flip()

    amount_of_content = len(content_dict)

    global winner_found
    global player1_locked
    global player2_locked
    global player3_locked
    global player4_locked
    global random_key
    global random_val
    global solution_dict
    global player_answers
    winner_found = player1_locked = player2_locked = player3_locked = player4_locked = False

    # randomly chosing content from content dictionary
    def random_pick_content():
        global winner_found
        global player1_locked
        global player2_locked
        global player3_locked
        global player4_locked
        global random_key
        global random_val
        global solution_dict
        global player_answers
        try:
            random_key = random.choice(list(content_dict.keys()))
            random_val = content_dict[random_key]
            del content_dict[random_key]
        except:
            winner_found = True
        if not winner_found:
            player1_locked = player2_locked = player3_locked = player4_locked = False
            player_answers = {1: False, 2: False, 3: False, 4: False}
            pygame.draw.rect(screen, Static.WHITE, picture_container)
            question = myfont.render(random_key, 1, Static.RED)
            screen.blit(question,
                        question.get_rect(center=question_container.center))
            options = [
                random_val["option1"], random_val["option2"],
                random_val["option3"], random_val["solution"]
            ]
            random.shuffle(options)
            solution_dict = {}
            pygame.draw.rect(screen, Static.BLUE, option1_container)
            pygame.draw.rect(screen, Static.RED, option1_container, 10)
            option1 = myfont.render(options[0], 1, Static.RED)
            solution_dict[4] = [options[0], Static.BLUE]
            del options[0]
            pygame.draw.rect(screen, Static.ORANGE, option2_container)
            pygame.draw.rect(screen, Static.RED, option2_container, 10)
            option2 = myfont.render(options[0], 1, Static.RED)
            solution_dict[3] = [options[0], Static.ORANGE]
            del options[0]
            pygame.draw.rect(screen, Static.GREEN, option3_container)
            pygame.draw.rect(screen, Static.RED, option3_container, 10)
            option3 = myfont.render(options[0], 1, Static.RED)
            solution_dict[2] = [options[0], Static.GREEN]
            del options[0]
            pygame.draw.rect(screen, Static.YELLOW, option4_container)
            pygame.draw.rect(screen, Static.RED, option4_container, 10)
            option4 = myfont.render(options[0], 1, Static.RED)
            solution_dict[1] = [options[0], Static.YELLOW]
            screen.blit(option1,
                        option1.get_rect(center=option1_container.center))
            screen.blit(option2,
                        option2.get_rect(center=option2_container.center))
            screen.blit(option3,
                        option3.get_rect(center=option3_container.center))
            screen.blit(option4,
                        option4.get_rect(center=option4_container.center))
            screen.blit(
                progress,
                progress.get_rect(center=picture_counter_container.center))
        else:
            show_winner()
        return random_key, winner_found

    def show_winner():
        pygame.draw.rect(screen, Static.WHITE, picture_container)
        pygame.draw.rect(screen, Static.WHITE, picture_counter_container)
        pygame.draw.rect(screen, Static.WHITE, solution_container)
        winner_ix = [
            i for i, x in enumerate(playerScore) if x == max(playerScore)
        ]
        winners = [scorefont.render("Gewinner:", 1, Static.RED)]
        [
            winners.append(scorefont.render(playerNames[i], 1, Static.RED))
            for i in winner_ix
        ]
        scorefont_width, scorefont_height = scorefont.size("Test")
        for line in range(len(winners)):
            screen.blit(
                winners[line],
                (0 + picture_container_width / 3,
                 game_label_container_height + picture_container_height / 4 +
                 (line * scorefont_height) + (15 * line)))

    # show solution
    def show_solution():
        if solution_dict[4][0] == random_val["solution"]:
            pygame.draw.rect(screen, Static.LIGHT_GREEN, option1_container, 20)
        elif solution_dict[3][0] == random_val["solution"]:
            pygame.draw.rect(screen, Static.LIGHT_GREEN, option2_container, 20)
        elif solution_dict[2][0] == random_val["solution"]:
            pygame.draw.rect(screen, Static.LIGHT_GREEN, option3_container, 20)
        elif solution_dict[1][0] == random_val["solution"]:
            pygame.draw.rect(screen, Static.LIGHT_GREEN, option4_container, 20)

    def points_reached():
        global winner_found
        if not game_modus:
            if points_to_win == max(playerScore):
                winner_found = True

    screen.fill(Static.WHITE)
    pygame.display.set_caption(game_name)

    # Created Variable for the text on the screen
    game_label = myfont.render(game_name, 1, Static.RED)
    solution_label = myfont.render(welcome, 1, Static.RED)
    nr = 1
    progress = myfont.render(
        str(amount_of_content) + " Dateien", 1, Static.RED)
    screen.blit(game_label,
                game_label.get_rect(center=game_label_container.center))
    screen.blit(progress,
                progress.get_rect(center=picture_counter_container.center))
    screen.blit(picture, picture.get_rect(center=picture_container.center))
    screen.blit(solution_label,
                solution_label.get_rect(center=solution_container.center))

    # Draw name of players, 4 empty rectangles and players score
    for n in range(0, players):
        player_label = myfont.render(playerNames[n], 1, Static.BLACK)
        player_label_container = pygame.Rect(
            picture_container_width,
            (picture_counter_container_height + n * player_container_height),
            player_label_container_width, player_label_container_height)
        screen.blit(
            player_label,
            player_label.get_rect(center=player_label_container.center))
        player_buzzer_container = pygame.Rect(
            picture_container_width,
            (game_label_container_height + player_label_container_height +
             n * player_container_height), player_buzzer_container_width,
            player_buzzer_container_height)
        pygame.draw.rect(screen, Static.BLACK, player_buzzer_container)
        player_score = scorefont.render(str(playerScore[n]), 1, Static.BLACK)
        player_score_container = pygame.Rect(
            (picture_container_width + player_buzzer_container_width),
            (game_label_container_height + player_label_container_height +
             n * player_container_height), player_score_container_width,
            player_score_container_height)
        screen.blit(
            player_score,
            player_score.get_rect(center=player_score_container.center))

    pygame.display.flip()

    question_answered = False  # all players have answered the question
    solution_shown = "Waiting"
    initialize = True
    running = True
    break_flag = False

    while running:
        pressed_keys = pygame.key.get_pressed()
        for event in pygame.event.get():
            alt_f4 = (
                event.type == pygame.KEYDOWN and
                (event.key == pygame.K_F4 and
                 (pressed_keys[pygame.K_LALT] or pressed_keys[pygame.K_RALT])))
            if alt_f4:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    os.chdir("/home/pi/Desktop/venv/mycode/")
                    break_flag = True
                    running = False
                if event.key == pygame.K_RETURN and winner_found:
                    show_winner()
                    pygame.display.flip()
        while initialize and not break_flag:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        os.chdir("/home/pi/Desktop/venv/mycode/")
                        break_flag = True
                        running = False
                    if event.key == pygame.K_RETURN:
                        pygame.draw.rect(screen, Static.WHITE,
                                         picture_container)
                        pygame.display.flip()
                        try:
                            random_pick_content()
                            pygame.display.flip()
                        except Exception as e:
                            break_flag = True
                            running = False
                        initialize = False
                        pygame.draw.rect(screen, Static.WHITE,
                                         solution_container)
                        pygame.display.flip()

        # player provide answer, game coordinator closes question eventually
        while not question_answered and not winner_found and not break_flag:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        os.chdir("/home/pi/Desktop/venv/mycode/")
                        break_flag = True
                        running = False
                    if event.key == pygame.K_RETURN:
                        question_answered = True
                        solution_shown = "playersAnswers"
                        for n in range(0, players):
                            player_buzzer_container = pygame.Rect(
                                picture_container_width,
                                (game_label_container_height +
                                 player_label_container_height +
                                 n * player_container_height),
                                player_buzzer_container_width,
                                player_buzzer_container_height)
                            buzzer_blocked = scorefont.render(
                                "X", 1, Static.RED)
                            screen.blit(
                                buzzer_blocked,
                                buzzer_blocked.get_rect(
                                    center=player_buzzer_container.center))
                        pygame.display.flip()

                if event.type == pygame.JOYBUTTONDOWN:
                    buttonpressed = event.button
                    if buttonpressed in player1Keys and not player1_locked:
                        player1_locked = True
                        player_answers[1] = solution_dict[buttonpressed]
                        player_buzzer_container = pygame.Rect(
                            picture_container_width,
                            (game_label_container_height +
                             player_label_container_height +
                             0 * player_container_height),
                            player_buzzer_container_width,
                            player_buzzer_container_height)
                        pygame.draw.rect(screen, Static.RED,
                                         player_buzzer_container)
                    elif buttonpressed in player2Keys and not player2_locked:
                        player2_locked = True
                        player_answers[2] = solution_dict[buttonpressed - 5]
                        player_buzzer_container = pygame.Rect(
                            picture_container_width,
                            (game_label_container_height +
                             player_label_container_height +
                             1 * player_container_height),
                            player_buzzer_container_width,
                            player_buzzer_container_height)
                        pygame.draw.rect(screen, Static.RED,
                                         player_buzzer_container)
                    elif buttonpressed in player3Keys and not player3_locked:
                        player3_locked = True
                        player_answers[3] = solution_dict[buttonpressed - 10]
                        player_buzzer_container = pygame.Rect(
                            picture_container_width,
                            (game_label_container_height +
                             player_label_container_height +
                             2 * player_container_height),
                            player_buzzer_container_width,
                            player_buzzer_container_height)
                        pygame.draw.rect(screen, Static.RED,
                                         player_buzzer_container)
                    elif buttonpressed in player4Keys and not player4_locked:
                        player4_locked = True
                        player_answers[4] = solution_dict[buttonpressed - 15]
                        player_buzzer_container = pygame.Rect(
                            picture_container_width,
                            (game_label_container_height +
                             player_label_container_height +
                             3 * player_container_height),
                            player_buzzer_container_width,
                            player_buzzer_container_height)
                        pygame.draw.rect(screen, Static.RED,
                                         player_buzzer_container)
                    if player1_locked and player2_locked and player3_locked and player4_locked:
                        solution_shown = "playersAnswers"
                        question_answered = True
                    pygame.display.flip()

        # all player have given an answer or game coordinator has closed the question
        # points are given by K_RETURN
        while question_answered and not winner_found and not break_flag:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    buttonpressed = event.key
                    if buttonpressed == pygame.K_F4 and (
                            pressed_keys[pygame.K_LALT]
                            or pressed_keys[pygame.K_RALT]):
                        sys.exit()
                    if buttonpressed == pygame.K_ESCAPE:
                        os.chdir("/home/pi/Desktop/venv/mycode/")
                        break_flag = True
                        running = False

            while solution_shown == "Reset" and not break_flag:
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        buttonpressed = event.key
                        if buttonpressed == pygame.K_F4 and (
                                pressed_keys[pygame.K_LALT]
                                or pressed_keys[pygame.K_RALT]):
                            sys.exit()
                        if buttonpressed == pygame.K_ESCAPE:
                            os.chdir("/home/pi/Desktop/venv/mycode/")
                            break_flag = True
                            running = False
                        if buttonpressed == pygame.K_RETURN:
                            # reset the buzzers to black
                            for n in range(0, players):
                                player_buzzer_container = pygame.Rect(
                                    picture_container_width,
                                    (game_label_container_height +
                                     player_label_container_height +
                                     n * player_container_height),
                                    player_buzzer_container_width,
                                    player_buzzer_container_height)
                                pygame.draw.rect(screen, Static.BLACK,
                                                 player_buzzer_container)
                            pygame.draw.rect(screen, Static.WHITE,
                                             picture_counter_container)
                            nr += 1
                            progress = myfont.render(
                                str(nr) + "/" + str(amount_of_content), 1,
                                Static.RED)
                            pygame.display.flip()
                            random_pick_content()
                            pygame.display.flip()
                            question_answered = False
                            solution_shown = "Waiting"
                            pygame.display.flip()

            # answers have been shown
            while solution_shown == "Prepared" and not break_flag:
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        buttonpressed = event.key
                        if buttonpressed == pygame.K_F4 and (
                                pressed_keys[pygame.K_LALT]
                                or pressed_keys[pygame.K_RALT]):
                            sys.exit()
                        if buttonpressed == pygame.K_ESCAPE:
                            os.chdir("/home/pi/Desktop/venv/mycode/")
                            break_flag = True
                            running = False
                        # Check if answer is correct to increase score
                        if buttonpressed == pygame.K_RETURN:
                            show_solution()
                            for n in range(1, players + 1):
                                player_buzzer_container = pygame.Rect(
                                    picture_container_width,
                                    (game_label_container_height +
                                     player_label_container_height +
                                     (n - 1) * player_container_height),
                                    player_buzzer_container_width,
                                    player_buzzer_container_height)
                                if not player_answers[n]:
                                    continue
                                else:
                                    if player_answers[n][0] == random_val[
                                            "solution"]:
                                        pygame.draw.rect(
                                            screen, Static.LIGHT_GREEN,
                                            player_buzzer_container)
                                        pygame.draw.rect(
                                            screen, player_answers[n][1],
                                            player_buzzer_container.inflate(
                                                -50, -50))
                                        player_score_container = pygame.Rect(
                                            (picture_container_width +
                                             player_buzzer_container_width),
                                            (game_label_container_height +
                                             player_label_container_height +
                                             (n - 1) * player_container_height
                                             ), player_score_container_width,
                                            player_score_container_height)
                                        pygame.draw.rect(
                                            screen, Static.WHITE,
                                            player_score_container)
                                        playerScore[(
                                            n - 1)] = playerScore[(n - 1)] + 1
                                        player_score = scorefont.render(
                                            str(playerScore[(n - 1)]), 1,
                                            Static.BLACK)
                                        screen.blit(
                                            player_score,
                                            player_score.get_rect(
                                                center=player_score_container.
                                                center))
                                        points_reached()
                            solution_shown = "Reset"
                            pygame.event.clear()
                            pygame.display.flip()

            # Show answers of players
            while solution_shown == "playersAnswers" and not break_flag:
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        buttonpressed = event.key
                        if buttonpressed == pygame.K_F4 and (
                                pressed_keys[pygame.K_LALT]
                                or pressed_keys[pygame.K_RALT]):
                            sys.exit()
                        if buttonpressed == pygame.K_ESCAPE:
                            os.chdir("/home/pi/Desktop/venv/mycode/")
                            break_flag = True
                            running = False
                        # Check if answer is correct to increase score
                        if buttonpressed == pygame.K_RETURN:
                            if player_answers == {
                                    1: False,
                                    2: False,
                                    3: False,
                                    4: False
                            }:
                                for n in range(0, players):
                                    player_buzzer_container = pygame.Rect(
                                        picture_container_width,
                                        (game_label_container_height +
                                         player_label_container_height +
                                         n * player_container_height),
                                        player_buzzer_container_width,
                                        player_buzzer_container_height)
                                    pygame.draw.rect(screen, Static.BLACK,
                                                     player_buzzer_container)
                                pygame.draw.rect(screen, Static.WHITE,
                                                 picture_counter_container)
                                nr += 1
                                progress = myfont.render(
                                    str(nr) + "/" + str(amount_of_content), 1,
                                    Static.RED)
                                pygame.display.flip()
                                random_pick_content()
                                pygame.display.flip()
                                question_answered = False
                                solution_shown = "Waiting"
                                pygame.display.flip()
                            else:
                                for n in range(1, players + 1):
                                    player_buzzer_container = pygame.Rect(
                                        picture_container_width,
                                        (game_label_container_height +
                                         player_label_container_height +
                                         (n - 1) * player_container_height),
                                        player_buzzer_container_width,
                                        player_buzzer_container_height)
                                    if not player_answers[n]:
                                        continue
                                    else:
                                        pygame.draw.rect(
                                            screen, player_answers[n][1],
                                            player_buzzer_container)
                                solution_shown = "Prepared"
                                pygame.display.flip()

        if break_flag:
            break
Esempio n. 6
0
def buzzer_game(players, playerNamesList, content_dir, screen, screenx,
                screeny, game_type, game_sounds, game_modus, points_to_win):
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.mixer.init()

    # declare and array for player names and initial score
    playerNames = playerNamesList
    playerScore = [0] * players
    # key definitions
    playerKeys = [0, 5, 10, 15]
    answer = [pygame.K_r, pygame.K_f]

    # Set the fonts for the textf
    myfont = pygame.font.SysFont("Ariel", 50)
    scorefont = pygame.font.SysFont("Ariel", 100)

    # defining the container for the graphical elements
    game_label_container_width = screenx / 10 * 8
    game_label_container_height = screeny / 10
    game_label_container = pygame.Rect(0, 0, game_label_container_width,
                                       game_label_container_height)
    picture_container_width = game_label_container_width
    picture_container_height = screeny / 10 * 8
    picture_container = pygame.Rect(0, game_label_container_height,
                                    picture_container_width,
                                    picture_container_height)
    solution_container_width = picture_container_width
    solution_container_height = screeny / 10
    solution_container = pygame.Rect(
        0, (game_label_container_height + picture_container_height),
        solution_container_width, solution_container_height)
    picture_counter_container_width = screenx / 10 * 2
    picture_counter_container_height = screeny / 10
    picture_counter_container = pygame.Rect(game_label_container_width, 0,
                                            picture_counter_container_width,
                                            picture_counter_container_height)
    countdown_container_width = picture_counter_container_width
    countdown_container_height = screeny / 10
    countdown_container = pygame.Rect(
        solution_container_width,
        (game_label_container_height + picture_container_height),
        countdown_container_width, countdown_container_height)
    player_container_width = picture_counter_container_width
    player_container_height = screeny / 10 * 2
    player_label_container_width = player_container_width
    player_label_container_height = player_container_height / 10 * 3
    player_buzzer_container_width = player_container_width / 2
    player_buzzer_container_height = player_container_height / 10 * 7
    player_score_container_width = player_container_width / 2
    player_score_container_height = player_container_height / 10 * 7

    # define picture format
    picture_width = int(picture_container_width / 10 * 9)
    picture_length = int(picture_container_height / 10 * 9)

    # text displayed at the beginning
    game_name = os.path.basename(os.path.dirname(content_dir)).replace(
        '_', ' ')
    welcome = u"Willkommen zu " + game_name

    # build content dictionary from content directory

    content_list = os.listdir(content_dir)

    logo = "BuzzingaLogo.bmp"
    picture = load_image(logo, 'images')

    os.chdir(content_dir)

    def print_status(status_str):
        status = myfont.render(status_str, 1, Static.RED)
        screen.fill(Static.WHITE)
        screen.blit(status, status.get_rect(center=picture_container.center))
        pygame.display.flip()

    content_dict = {}

    def build_content_dict(content, file_counter):
        if not file_in.lower().endswith(('.bmp', '.wav')):
            print_status(
                "{} has not been added to the content directory because it could not be converted to .bmp or .wav."
                .format(content))
        else:
            base = os.path.basename(content_dir + content)
            name_o = os.path.splitext(base)[0]
            name = name_o.replace("_", " ")
            name = name.replace("zzz", "(")
            name = name.replace("uuu", ")")
            content_dict[name] = content_dir + content
            print_status("added file #{}".format(file_counter))

    # loading info
    print_status("loading...")

    file_counter = 1
    for file_in in content_list:
        if os.path.isdir(file_in):
            print_status("{} is a directory.".format(file_in))
        if file_in.startswith("."):
            print_status(
                "{} starts with '.'. That's not allowed.".format(file_in))
        elif file_in.lower().endswith(
            ('.png', '.jpg', '.jpeg', '.bmp', '.mp3', '.wav')):
            if game_type == "images":
                try:
                    # images in image directory are converted into .bmp
                    print_status("converting file #{}".format(file_counter))
                    file_in = convert_image_to(file_in, "bmp")
                except:
                    print_status(
                        "{} could not be converted to .bmp format.".format(
                            file_in))
            elif game_type == "sounds":
                try:
                    # sounds in sound directory are converted into .wav
                    print_status("converting file #{}".format(file_counter))
                    file_in = mp3_to_wav(file_in)
                except:
                    print_status(
                        "{} could not be converted to .wav format.".format(
                            file_in))
            build_content_dict(file_in, file_counter)
        else:
            print_status("{} has no suitable format.".format(file_in))
        file_counter += 1

    print_status("content dictionary build!")

    amount_of_content = len(content_dict)

    global winner_found
    winner_found = False

    # randomly chosing content from content dictionary and updating solution label
    sound_channel = pygame.mixer.Channel(0)
    game_sound_channel = pygame.mixer.Channel(1)

    print_status("sound channels initialized")

    def random_pick_content():
        global random_key
        global random_val
        global random_sound
        global winner_found
        try:
            random_key = random.choice(list(content_dict.keys()))
            random_val = content_dict[random_key]
            del content_dict[random_key]
        except:
            winner_found = True
        if game_type == "images":
            if not winner_found:
                random_content = load_image(random_val, content_dir)
                image_size = random_content.get_rect().size
                if image_size[0] >= image_size[1]:
                    if int((image_size[1] / float(image_size[0])) *
                           picture_width) < picture_length:
                        image_size = (
                            picture_width,
                            int((image_size[1] / float(image_size[0])) *
                                picture_width))
                    else:
                        image_size = (int(
                            (image_size[0] / float(image_size[1])) *
                            picture_length), picture_length)
                else:
                    if int((image_size[0] / float(image_size[1])) *
                           picture_length) < picture_width:
                        image_size = (int(
                            (image_size[0] / float(image_size[1])) *
                            picture_length), picture_length)
                    else:
                        image_size = (
                            picture_width,
                            int((image_size[1] / float(image_size[0])) *
                                picture_width))
                random_content = pygame.transform.scale(
                    random_content, image_size)
                pygame.draw.rect(screen, Static.WHITE, picture_container)
                screen.blit(
                    random_content,
                    random_content.get_rect(center=picture_container.center))
                screen.blit(
                    progress,
                    progress.get_rect(center=picture_counter_container.center))
            else:
                show_winner()
        else:
            random_sound = pygame.mixer.Sound(random_val)
            sound_channel.play(random_sound)
            if not winner_found:
                pygame.draw.rect(screen, Static.WHITE, solution_container)
                screen.blit(
                    progress,
                    progress.get_rect(center=picture_counter_container.center))
            else:
                show_winner()
        return random_key, winner_found

    def show_winner():
        sound_channel.stop()
        pygame.draw.rect(screen, Static.WHITE, picture_container)
        pygame.draw.rect(screen, Static.WHITE, picture_counter_container)
        pygame.draw.rect(screen, Static.WHITE, solution_container)
        winner_ix = [
            i for i, x in enumerate(playerScore) if x == max(playerScore)
        ]
        winners = [scorefont.render("Gewinner:", 1, Static.RED)]
        [
            winners.append(scorefont.render(playerNames[i], 1, Static.RED))
            for i in winner_ix
        ]
        scorefont_width, scorefont_height = scorefont.size("Test")
        for line in range(len(winners)):
            screen.blit(
                winners[line],
                (0 + picture_container_width / 3,
                 game_label_container_height + picture_container_height / 4 +
                 (line * scorefont_height) + (15 * line)))

    # print solution in solution label
    def show_solution():
        solution = myfont.render(random_key, 1, Static.RED)
        screen.blit(solution,
                    solution.get_rect(center=solution_container.center))

    # countdown printed in solution label
    def countdown(count_from):
        for i in range(1, count_from):
            time_left = count_from - i
            time_left = str(time_left)
            countdown = myfont.render(time_left, 1, Static.RED)
            screen.blit(countdown,
                        countdown.get_rect(center=countdown_container.center))
            pygame.display.flip()
            pygame.time.wait(1000)
            if time_left != 0:
                pygame.draw.rect(screen, Static.WHITE, countdown_container)
                pygame.display.flip()
        if game_sounds:
            countdown_sound = pygame.mixer.Sound(
                "/home/pi/Desktop/venv/mycode/sounds/wrong-answer.wav")
            game_sound_channel.play(countdown_sound)

    def points_reached():
        global winner_found
        if not game_modus:
            if points_to_win == max(playerScore):
                winner_found = True

    screen.fill(Static.WHITE)
    pygame.display.set_caption(game_name)
    pygame.display.flip()

    # Created Variable for the text on the screen
    game_label = myfont.render(game_name, 1, Static.RED)
    solution_label = myfont.render(welcome, 1, Static.RED)
    nr = 1
    progress = myfont.render(
        str(amount_of_content) + " Dateien", 1, Static.RED)
    screen.blit(game_label,
                game_label.get_rect(center=game_label_container.center))
    screen.blit(progress,
                progress.get_rect(center=picture_counter_container.center))
    screen.blit(picture, picture.get_rect(center=picture_container.center))
    screen.blit(solution_label,
                solution_label.get_rect(center=solution_container.center))

    # Draw name of players, 4 empty rectangles and players score
    for n in range(0, players):
        player_label = myfont.render(playerNames[n], 1, Static.BLACK)
        player_label_container = pygame.Rect(
            picture_container_width,
            (picture_counter_container_height + n * player_container_height),
            player_label_container_width, player_label_container_height)
        screen.blit(
            player_label,
            player_label.get_rect(center=player_label_container.center))
        player_buzzer_container = pygame.Rect(
            picture_container_width,
            (game_label_container_height + player_label_container_height +
             n * player_container_height), player_buzzer_container_width,
            player_buzzer_container_height)
        pygame.draw.rect(screen, Static.BLACK, player_buzzer_container)
        player_score = scorefont.render(str(playerScore[n]), 1, Static.BLACK)
        player_score_container = pygame.Rect(
            (picture_container_width + player_buzzer_container_width),
            (game_label_container_height + player_label_container_height +
             n * player_container_height), player_score_container_width,
            player_score_container_height)
        screen.blit(
            player_score,
            player_score.get_rect(center=player_score_container.center))

    pygame.display.flip()

    first = False  # used to signify the first key pressed and stops other being used
    show_solution_var = 1
    initialize = True

    running = True
    break_flag = False
    while running:
        pressed_keys = pygame.key.get_pressed()
        for event in pygame.event.get():
            alt_f4 = (
                event.type == pygame.KEYDOWN and
                (event.key == pygame.K_F4 and
                 (pressed_keys[pygame.K_LALT] or pressed_keys[pygame.K_RALT])))
            if alt_f4:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    sound_channel.stop()
                    os.chdir("/home/pi/Desktop/venv/mycode/")
                    break_flag = True
                    break
                if event.key == pygame.K_RETURN and winner_found:
                    show_winner()
                    pygame.display.flip()

        while initialize:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        sound_channel.stop()
                        os.chdir("/home/pi/Desktop/venv/mycode/")
                        break_flag = True
                        break
                    if event.key == pygame.K_RETURN:
                        if game_type == "images":
                            pygame.draw.rect(screen, Static.WHITE,
                                             picture_container)
                            pygame.display.flip()
                        try:
                            random_pick_content()
                            pygame.display.flip()
                        except Exception as e:
                            sound_channel.stop()
                            os.chdir("/home/pi/Desktop/venv/mycode/")
                            break_flag = True
                            break
                        initialize = False

        while not first and not winner_found and not break_flag:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        sound_channel.stop()
                        os.chdir("/home/pi/Desktop/venv/mycode/")
                        break_flag = True
                        break
                    if event.key == pygame.K_RETURN:
                        first = True
                        try:
                            show_solution_var = 1
                            for n in range(0, players):
                                player_buzzer_container = pygame.Rect(
                                    picture_container_width,
                                    (game_label_container_height +
                                     player_label_container_height +
                                     n * player_container_height),
                                    player_buzzer_container_width,
                                    player_buzzer_container_height)
                                buzzer_blocked = scorefont.render(
                                    "X", 1, Static.RED)
                                screen.blit(
                                    buzzer_blocked,
                                    buzzer_blocked.get_rect(
                                        center=player_buzzer_container.center))
                            pygame.display.flip()
                        except:
                            show_solution_var = 2
                    if event.key == pygame.K_p:
                        sound_channel.stop()
                        sound_channel.play(random_sound)

                if event.type == pygame.JOYBUTTONDOWN:
                    buttonpressed = event.button
                    for n in range(0, players):
                        if buttonpressed == playerKeys[n]:
                            sound_channel.pause()
                            first_buzz = playerKeys.index(buttonpressed)
                            player_buzzer_container = pygame.Rect(
                                picture_container_width,
                                (game_label_container_height +
                                 player_label_container_height +
                                 first_buzz * player_container_height),
                                player_buzzer_container_width,
                                player_buzzer_container_height)
                            pygame.draw.rect(screen, Static.RED,
                                             player_buzzer_container)
                            # buzzer sound
                            if game_sounds:
                                buzzerHit = pygame.mixer.Sound(
                                    "/home/pi/Desktop/venv/mycode/sounds/buzzer_hit.wav"
                                )
                                game_sound_channel.play(buzzerHit)
                            first = True
                            countdown(5)
                    pygame.display.flip()
                # a 'buzzer' was pressed and shown on screen
            # now go to the reset code
        # loop waiting until the 'button' are reset

        while first and not winner_found and not break_flag:
            for event in pygame.event.get():
                # User pressed down on a key
                if event.type == pygame.KEYDOWN:
                    keypressed = event.key
                    if event.key == pygame.K_ESCAPE:
                        sound_channel.stop()
                        os.chdir("/home/pi/Desktop/venv/mycode/")
                        break_flag = True
                        break
                    # Check if Key Pressed to increase score
                    if keypressed in answer:
                        player_score_container = pygame.Rect(
                            (picture_container_width +
                             player_buzzer_container_width),
                            (game_label_container_height +
                             player_label_container_height +
                             first_buzz * player_container_height),
                            player_score_container_width,
                            player_score_container_height)
                        pygame.draw.rect(screen, Static.WHITE,
                                         player_score_container)
                        if keypressed == answer[0]:
                            playerScore[
                                first_buzz] = playerScore[first_buzz] + 1
                        if keypressed == answer[1]:
                            playerScore[
                                first_buzz] = playerScore[first_buzz] - 1
                        player_score = scorefont.render(
                            str(playerScore[first_buzz]), 1, Static.BLACK)
                        screen.blit(
                            player_score,
                            player_score.get_rect(
                                center=player_score_container.center))
                        pygame.display.flip()
                        points_reached()

                    if keypressed == pygame.K_RETURN and show_solution_var == 2:
                        sound_channel.stop()
                        pygame.draw.rect(screen, Static.WHITE,
                                         solution_container)
                        pygame.display.flip()
                        # reset the buzzers to black
                        for n in range(0, players):
                            player_buzzer_container = pygame.Rect(
                                picture_container_width,
                                (game_label_container_height +
                                 player_label_container_height +
                                 n * player_container_height),
                                player_buzzer_container_width,
                                player_buzzer_container_height)
                            pygame.draw.rect(screen, Static.BLACK,
                                             player_buzzer_container)
                        first = False
                        pygame.display.flip()
                        show_solution_var = 0

                    # solution is shown
                    if keypressed == pygame.K_RETURN and show_solution_var == 1:
                        sound_channel.unpause()
                        pygame.draw.rect(screen, Static.WHITE,
                                         solution_container)
                        show_solution()
                        pygame.display.flip()
                        show_solution_var = 2

                    if keypressed == pygame.K_RETURN and show_solution_var == 0:
                        pygame.draw.rect(screen, Static.WHITE,
                                         picture_counter_container)
                        nr += 1
                        progress = myfont.render(
                            str(nr) + "/" + str(amount_of_content), 1,
                            Static.RED)
                        pygame.display.flip()
                        try:
                            random_pick_content()
                            pygame.display.flip()
                        except:
                            sound_channel.stop()
                            os.chdir("/home/pi/Desktop/venv/mycode/")
                            break_flag = True
                            break
                        show_solution_var = 1
        if break_flag:
            break
Esempio n. 7
0
def hint_game(players, playerNamesList, content_dir, screen, screenx, screeny,
              game_sounds, game_modus, points_to_win):
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.mixer.init()
    sound_channel = pygame.mixer.Channel(0)
    game_sound_channel = pygame.mixer.Channel(1)

    # declare and array for player names and initial score
    playerNames = playerNamesList
    playerScore = [0] * players
    # key definitions
    playerKeys = [0, 5, 10, 15]
    answer = [pygame.K_r, pygame.K_f]

    # Set the fonts for the textf
    myfont = pygame.font.SysFont("Ariel", 50)
    scorefont = pygame.font.SysFont("Ariel", 100)

    # defining the container for the graphical elements
    game_label_container_width = screenx / 10 * 8
    game_label_container_height = screeny / 10
    game_label_container = pygame.Rect(0, 0, game_label_container_width,
                                       game_label_container_height)
    picture_container_width = game_label_container_width
    picture_container_height = screeny / 10 * 8
    picture_container = pygame.Rect(0, game_label_container_height,
                                    picture_container_width,
                                    picture_container_height)
    hint_container_width = (game_label_container_width / 2) - 10
    hint_container_height = (picture_container_height / 5) - 5
    hint1_container = pygame.Rect(5, game_label_container_height,
                                  hint_container_width, hint_container_height)
    hint2_container = pygame.Rect(hint_container_width + 10,
                                  game_label_container_height,
                                  hint_container_width, hint_container_height)
    hint3_container = pygame.Rect(
        5, game_label_container_height + hint_container_height + 5,
        hint_container_width, hint_container_height)
    hint4_container = pygame.Rect(
        hint_container_width + 10,
        game_label_container_height + hint_container_height + 5,
        hint_container_width, hint_container_height)
    hint5_container = pygame.Rect(
        5, game_label_container_height + 2 * hint_container_height + 10,
        hint_container_width, hint_container_height)
    hint6_container = pygame.Rect(
        hint_container_width + 10,
        game_label_container_height + 2 * hint_container_height + 10,
        hint_container_width, hint_container_height)
    hint7_container = pygame.Rect(
        5, game_label_container_height + 3 * hint_container_height + 15,
        hint_container_width, hint_container_height)
    hint8_container = pygame.Rect(
        hint_container_width + 10,
        game_label_container_height + 3 * hint_container_height + 15,
        hint_container_width, hint_container_height)
    hint9_container = pygame.Rect(
        5, game_label_container_height + 4 * hint_container_height + 20,
        hint_container_width, hint_container_height)
    hint10_container = pygame.Rect(
        hint_container_width + 10,
        game_label_container_height + 4 * hint_container_height + 20,
        hint_container_width, hint_container_height)
    solution_container_width = picture_container_width
    solution_container_height = screeny / 10
    solution_container = pygame.Rect(
        0, (game_label_container_height + picture_container_height),
        solution_container_width, solution_container_height)
    picture_counter_container_width = screenx / 10 * 2
    picture_counter_container_height = screeny / 10
    picture_counter_container = pygame.Rect(game_label_container_width, 0,
                                            picture_counter_container_width,
                                            picture_counter_container_height)
    countdown_container_width = picture_counter_container_width
    countdown_container_height = screeny / 10
    countdown_container = pygame.Rect(
        solution_container_width,
        (game_label_container_height + picture_container_height),
        countdown_container_width, countdown_container_height)
    player_container_width = picture_counter_container_width
    player_container_height = screeny / 10 * 2
    player_label_container_width = player_container_width
    player_label_container_height = player_container_height / 10 * 3
    player_buzzer_container_width = player_container_width / 2
    player_buzzer_container_height = player_container_height / 10 * 7
    player_score_container_width = player_container_width / 2
    player_score_container_height = player_container_height / 10 * 7

    # text displayed at the beginning
    head, tail = os.path.split(content_dir)
    game_name = tail[:-5].replace('_', ' ')
    welcome = u"Willkommen zu " + game_name

    logo = "BuzzingaLogo.bmp"
    picture = load_image(logo, 'images')

    content_dict = {}
    with open(content_dir) as json_file:
        data = json.load(json_file)
    for q in data:
        solution_link = "4/" + str(q["pk"])
        content_dict[q["fields"]["solution"]] = {
            'hint1': q["fields"]["hint1"],
            'hint2': q["fields"]["hint2"],
            'hint3': q["fields"]["hint3"],
            'hint4': q["fields"]["hint4"],
            'hint5': q["fields"]["hint5"],
            'hint6': q["fields"]["hint6"],
            'hint7': q["fields"]["hint7"],
            'hint8': q["fields"]["hint8"],
            'hint9': q["fields"]["hint9"],
            'hint10': q["fields"]["hint10"],
            'solution_link': solution_link,
        }

    # loading info
    loading = myfont.render("loading...", 1, Static.RED)
    screen.fill(Static.WHITE)
    screen.blit(loading, loading.get_rect(center=picture_container.center))
    pygame.display.flip()

    amount_of_content = len(content_dict)

    winner_found = False
    hint_n = 1

    # randomly chosing content from content dictionary and updating solution label
    def random_pick_content():
        global random_key
        global random_val
        global winner_found
        winner_found = False
        try:
            random_key = random.choice(list(content_dict.keys()))
            random_val = content_dict[random_key]
            del content_dict[random_key]
        except:
            winner_found = True
        if not winner_found:
            pygame.draw.rect(screen, Static.WHITE, picture_container)
            screen.blit(
                progress,
                progress.get_rect(center=picture_counter_container.center))
        else:
            show_winner()
        return random_key, random_val, winner_found

    def show_winner():
        sound_channel.stop()
        pygame.draw.rect(screen, Static.WHITE, picture_container)
        pygame.draw.rect(screen, Static.WHITE, picture_counter_container)
        pygame.draw.rect(screen, Static.WHITE, solution_container)
        winner_ix = [
            i for i, x in enumerate(playerScore) if x == max(playerScore)
        ]
        winners = [scorefont.render("Gewinner:", 1, Static.RED)]
        [
            winners.append(scorefont.render(playerNames[i], 1, Static.RED))
            for i in winner_ix
        ]
        scorefont_width, scorefont_height = scorefont.size("Test")
        for line in range(len(winners)):
            screen.blit(
                winners[line],
                (0 + picture_container_width / 3,
                 game_label_container_height + picture_container_height / 4 +
                 (line * scorefont_height) + (15 * line)))

    # print solution in solution label
    def show_solution():
        solution = myfont.render(random_key, 1, Static.RED)
        screen.blit(solution,
                    solution.get_rect(center=solution_container.center))

    # countdown printed in solution label
    def countdown(count_from):
        for i in range(1, count_from):
            time_left = count_from - i
            time_left = str(time_left)
            countdown = myfont.render(time_left, 1, Static.RED)
            screen.blit(countdown,
                        countdown.get_rect(center=countdown_container.center))
            pygame.display.flip()
            pygame.time.wait(1000)
            if time_left != 0:
                pygame.draw.rect(screen, Static.WHITE, countdown_container)
                pygame.display.flip()
        if game_sounds:
            countdown_sound = pygame.mixer.Sound(
                "/home/pi/Desktop/venv/mycode/sounds/wrong-answer.wav")
            game_sound_channel.play(countdown_sound)

    def points_reached():
        global winner_found
        if not game_modus:
            if points_to_win == max(playerScore):
                winner_found = True

    hint_match_dict = {
        1: [hint1_container, "hint1"],
        2: [hint2_container, "hint2"],
        3: [hint3_container, "hint3"],
        4: [hint4_container, "hint4"],
        5: [hint5_container, "hint5"],
        6: [hint6_container, "hint6"],
        7: [hint7_container, "hint7"],
        8: [hint8_container, "hint8"],
        9: [hint9_container, "hint9"],
        10: [hint10_container, "hint10"],
    }

    def print_hint(n):
        global random_val
        pygame.draw.rect(screen, Static.BLUE, hint_match_dict[n][0])
        hint1 = myfont.render(random_val[hint_match_dict[n][1]], 1,
                              Static.WHITE)
        screen.blit(hint1, hint1.get_rect(center=hint_match_dict[n][0].center))
        pygame.display.flip()

    screen.fill(Static.WHITE)
    pygame.display.set_caption(game_name)

    # Created Variable for the text on the screen
    game_label = myfont.render(game_name, 1, Static.RED)
    solution_label = myfont.render(welcome, 1, Static.RED)
    nr = 1
    progress = myfont.render(
        str(amount_of_content) + " Dateien", 1, Static.RED)
    screen.blit(game_label,
                game_label.get_rect(center=game_label_container.center))
    screen.blit(progress,
                progress.get_rect(center=picture_counter_container.center))
    screen.blit(picture, picture.get_rect(center=picture_container.center))
    screen.blit(solution_label,
                solution_label.get_rect(center=solution_container.center))

    # Draw name of players, 4 empty rectangles and players score
    for n in range(0, players):
        player_label = myfont.render(playerNames[n], 1, Static.BLACK)
        player_label_container = pygame.Rect(
            picture_container_width,
            (picture_counter_container_height + n * player_container_height),
            player_label_container_width, player_label_container_height)
        screen.blit(
            player_label,
            player_label.get_rect(center=player_label_container.center))
        player_buzzer_container = pygame.Rect(
            picture_container_width,
            (game_label_container_height + player_label_container_height +
             n * player_container_height), player_buzzer_container_width,
            player_buzzer_container_height)
        pygame.draw.rect(screen, Static.BLACK, player_buzzer_container)
        player_score = scorefont.render(str(playerScore[n]), 1, Static.BLACK)
        player_score_container = pygame.Rect(
            (picture_container_width + player_buzzer_container_width),
            (game_label_container_height + player_label_container_height +
             n * player_container_height), player_score_container_width,
            player_score_container_height)
        screen.blit(
            player_score,
            player_score.get_rect(center=player_score_container.center))

    pygame.display.flip()

    first = False  # used to signify the first key pressed and stops other being used
    no_points = False
    show_solution_var = 1
    initialize = True
    running = True
    break_flag = False
    while running:
        pressed_keys = pygame.key.get_pressed()
        for event in pygame.event.get():
            alt_f4 = (
                event.type == pygame.KEYDOWN and
                (event.key == pygame.K_F4 and
                 (pressed_keys[pygame.K_LALT] or pressed_keys[pygame.K_RALT])))
            if alt_f4:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    sound_channel.stop()
                    os.chdir("/home/pi/Desktop/venv/mycode/")
                    break_flag = True
                    break
                if event.key == pygame.K_RETURN and winner_found:
                    show_winner()
                    pygame.display.flip()

        while initialize:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        sound_channel.stop()
                        os.chdir("/home/pi/Desktop/venv/mycode/")
                        break_flag = True
                        break
                    if event.key == pygame.K_RETURN:
                        try:
                            random_pick_content()
                            pygame.display.flip()
                        except Exception as e:
                            sound_channel.stop()
                            os.chdir("/home/pi/Desktop/venv/mycode/")
                            break_flag = True
                            break
                        initialize = False

        while not first and not winner_found and not break_flag:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        sound_channel.stop()
                        os.chdir("/home/pi/Desktop/venv/mycode/")
                        break_flag = True
                        break
                    if event.key == pygame.K_RETURN and hint_n == 10:
                        first = True
                        no_points = True
                        try:
                            show_solution_var = 1
                            for n in range(0, players):
                                player_buzzer_container = pygame.Rect(
                                    picture_container_width,
                                    (game_label_container_height +
                                     player_label_container_height +
                                     n * player_container_height),
                                    player_buzzer_container_width,
                                    player_buzzer_container_height)
                                buzzer_blocked = scorefont.render(
                                    "X", 1, Static.RED)
                                screen.blit(
                                    buzzer_blocked,
                                    buzzer_blocked.get_rect(
                                        center=player_buzzer_container.center))
                            pygame.display.flip()
                            hint_n = 1
                        except:
                            show_solution_var = 2
                    if event.key == pygame.K_n:
                        print_hint(hint_n)
                        if hint_n != 10:
                            hint_n += 1

                if event.type == pygame.JOYBUTTONDOWN:
                    buttonpressed = event.button
                    for n in range(0, players):
                        if buttonpressed == playerKeys[n]:
                            sound_channel.pause()
                            first_buzz = playerKeys.index(buttonpressed)
                            player_buzzer_container = pygame.Rect(
                                picture_container_width,
                                (game_label_container_height +
                                 player_label_container_height +
                                 first_buzz * player_container_height),
                                player_buzzer_container_width,
                                player_buzzer_container_height)
                            pygame.draw.rect(screen, Static.RED,
                                             player_buzzer_container)
                            solution_link = myfont.render(
                                random_val["solution_link"], 1, Static.WHITE)
                            screen.blit(
                                solution_link,
                                solution_link.get_rect(
                                    center=player_buzzer_container.center))
                            # buzzer sound
                            if game_sounds:
                                buzzerHit = pygame.mixer.Sound(
                                    "/home/pi/Desktop/venv/mycode/sounds/buzzer_hit.wav"
                                )
                                game_sound_channel.play(buzzerHit)
                            first = True
                            countdown(5)
                    pygame.display.flip()
                # a 'buzzer' was pressed and shown on screen
            # now go to the reset code
        # loop waiting until the 'button' are reset

        while first and not winner_found and not break_flag:
            for event in pygame.event.get():
                # User pressed down on a key
                if event.type == pygame.KEYDOWN:
                    keypressed = event.key
                    if event.key == pygame.K_ESCAPE:
                        sound_channel.stop()
                        os.chdir("/home/pi/Desktop/venv/mycode/")
                        break_flag = True
                        break
                    # Check if Key Pressed to increase score
                    if not no_points and keypressed in answer:
                        player_score_container = pygame.Rect(
                            (picture_container_width +
                             player_buzzer_container_width),
                            (game_label_container_height +
                             player_label_container_height +
                             first_buzz * player_container_height),
                            player_score_container_width,
                            player_score_container_height)
                        pygame.draw.rect(screen, Static.WHITE,
                                         player_score_container)
                        if keypressed == answer[0]:
                            playerScore[
                                first_buzz] = playerScore[first_buzz] + 1
                        if keypressed == answer[1]:
                            playerScore[
                                first_buzz] = playerScore[first_buzz] - 1
                            first = False
                        player_score = scorefont.render(
                            str(playerScore[first_buzz]), 1, Static.BLACK)
                        screen.blit(
                            player_score,
                            player_score.get_rect(
                                center=player_score_container.center))
                        pygame.display.flip()
                        if not first:
                            for n in range(0, players):
                                player_buzzer_container = pygame.Rect(
                                    picture_container_width,
                                    (game_label_container_height +
                                     player_label_container_height +
                                     n * player_container_height),
                                    player_buzzer_container_width,
                                    player_buzzer_container_height)
                                pygame.draw.rect(screen, Static.BLACK,
                                                 player_buzzer_container)
                            pygame.display.flip()
                            break
                        points_reached()

                    if keypressed == pygame.K_n:
                        print_hint(hint_n)
                        if hint_n != 10:
                            hint_n += 1

                    if keypressed == pygame.K_RETURN and show_solution_var == 2:
                        sound_channel.stop()
                        pygame.draw.rect(screen, Static.WHITE,
                                         solution_container)
                        pygame.display.flip()
                        # reset the buzzers to black
                        for n in range(0, players):
                            player_buzzer_container = pygame.Rect(
                                picture_container_width,
                                (game_label_container_height +
                                 player_label_container_height +
                                 n * player_container_height),
                                player_buzzer_container_width,
                                player_buzzer_container_height)
                            pygame.draw.rect(screen, Static.BLACK,
                                             player_buzzer_container)
                        first = False
                        no_points = False
                        pygame.display.flip()
                        show_solution_var = 0

                    # solution is shown
                    if keypressed == pygame.K_RETURN and show_solution_var == 1:
                        sound_channel.unpause()
                        pygame.draw.rect(screen, Static.WHITE,
                                         solution_container)
                        show_solution()
                        pygame.display.flip()
                        show_solution_var = 2

                    if keypressed == pygame.K_RETURN and show_solution_var == 0:
                        pygame.draw.rect(screen, Static.WHITE,
                                         picture_counter_container)
                        nr += 1
                        progress = myfont.render(
                            str(nr) + "/" + str(amount_of_content), 1,
                            Static.RED)
                        pygame.display.flip()
                        hint_n = 1
                        try:
                            random_pick_content()
                            pygame.display.flip()
                        except:
                            sound_channel.stop()
                            os.chdir("/home/pi/Desktop/venv/mycode/")
                            break_flag = True
                            break
                        show_solution_var = 1
        if break_flag:
            break