import pygame import sys import random # Initialize Pygame pygame.init() # Constants WIDTH, HEIGHT = 800, 600 HALO_CHARACTERS = ["Master Chief", "Cortana", "Arbiter", "Sgt. Johnson", "Catherine Halsey"] TIME_LIMIT_SECONDS = 60 FPS = 60 # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) # Create the screen screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Draw the Halo Character Example") # Clock to control the frame rate clock = pygame.time.Clock() # Font font = pygame.font.Font(None, 36) # Drawing variables drawing = False points = [] current_word = "" # Timer time_remaining = TIME_LIMIT_SECONDS * FPS # Button button_rect = pygame.Rect(WIDTH - 150, HEIGHT - 50, 120, 40) button_color = WHITE def choose_random_halo_character(): return random.choice(HALO_CHARACTERS) current_halo_character = choose_random_halo_character() result_message = "" while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: if button_rect.collidepoint(event.pos): # Check the drawn word when the button is pressed if current_word.lower() == current_halo_character.lower(): result_message = "Correct! You drew the character correctly." else: result_message = "Incorrect. Try again!" points = [] current_word = "" current_halo_character = choose_random_halo_character() time_remaining = TIME_LIMIT_SECONDS * FPS else: drawing = True points.append([event.pos]) elif event.type == pygame.MOUSEBUTTONUP: drawing = False current_word = ''.join([chr(int(x / WIDTH * 256)) for x, y in points[-1]]) elif event.type == pygame.MOUSEMOTION and drawing: # Record points when mouse is moved points[-1].append(event.pos) # Update timer time_remaining -= 1 if time_remaining <= 0: result_message = "Time's up! You didn't complete the drawing in time." points = [] current_word = "" current_halo_character = choose_random_halo_character() time_remaining = TIME_LIMIT_SECONDS * FPS # Draw everything screen.fill(WHITE) # Draw points only for line in points: if len(line) >= 2: pygame.draw.lines(screen, BLACK, False, line, 2) # Draw word to guess word_text = font.render("Draw the Halo character: " + current_halo_character, True, BLACK) screen.blit(word_text, (10, 10)) # Draw button pygame.draw.rect(screen, button_color, button_rect) button_text = font.render("Done", True, BLACK) screen.blit(button_text, (WIDTH - 130, HEIGHT - 40)) # Draw timer timer_text = font.render("Time remaining: {} seconds".format(time_remaining // FPS), True, BLACK) screen.blit(timer_text, (10, 40)) # Draw result message result_text = font.render(result_message, True, RED) screen.blit(result_text, (10, 70)) pygame.display.flip() clock.tick(FPS)