Advertisement
This is comment for paste
GPT-4 vs Llama-3 vs Claude
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Claude 3.5 Sonnet
- import pygame
- import random
- import time
- # Initialize Pygame
- pygame.init()
- # Set up the display
- WIDTH, HEIGHT = 800, 600
- screen = pygame.display.set_mode((WIDTH, HEIGHT))
- pygame.display.set_caption("Two-Player Line Game")
- # Colors
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- RED = (255, 0, 0)
- BLUE = (0, 0, 255)
- # Game variables
- line_pos = WIDTH // 2
- move_direction = 0
- move_speed = 100 # pixels per second
- last_move_time = 0
- wait_time = random.uniform(1, 5) # Random wait time between 1 and 5 seconds
- # Font
- font = pygame.font.Font(None, 36)
- def draw_game():
- screen.fill(BLACK)
- pygame.draw.rect(screen, BLUE, (0, 0, line_pos, HEIGHT))
- pygame.draw.rect(screen, RED, (line_pos, 0, WIDTH - line_pos, HEIGHT))
- pygame.draw.line(screen, WHITE, (line_pos, 0), (line_pos, HEIGHT), 2)
- # Draw player labels
- a_text = font.render("A", True, WHITE)
- l_text = font.render("L", True, WHITE)
- screen.blit(a_text, (20, HEIGHT // 2))
- screen.blit(l_text, (WIDTH - 40, HEIGHT // 2))
- # Draw percentage
- a_percent = font.render(f"{int(line_pos / WIDTH * 100)}%", True, WHITE)
- l_percent = font.render(f"{int((WIDTH - line_pos) / WIDTH * 100)}%", True, WHITE)
- screen.blit(a_percent, (line_pos // 2 - 20, 20))
- screen.blit(l_percent, (line_pos + (WIDTH - line_pos) // 2 - 20, 20))
- pygame.display.flip()
- def game_over(winner):
- screen.fill(BLACK)
- text = font.render(f"Player {winner} wins!", True, WHITE)
- screen.blit(text, (WIDTH // 2 - 100, HEIGHT // 2))
- pygame.display.flip()
- pygame.time.wait(3000)
- running = True
- clock = pygame.time.Clock()
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_a and move_direction < 0:
- move_direction = 0
- if event.key == pygame.K_l and move_direction > 0:
- move_direction = 0
- current_time = time.time()
- if move_direction == 0 and current_time - last_move_time > wait_time:
- move_direction = random.choice([-1, 1])
- last_move_time = current_time
- wait_time = random.uniform(1, 5)
- if move_direction != 0:
- line_pos += move_direction * move_speed * clock.get_time() / 1000
- if line_pos <= 0:
- game_over("L")
- running = False
- elif line_pos >= WIDTH:
- game_over("A")
- running = False
- line_pos = max(0, min(WIDTH, line_pos))
- draw_game()
- clock.tick(60)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement