Advertisement
jaldpsd
Aug 15th, 2024
38
0
Never
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!
  1. Claude 3.5 Sonnet
  2.  
  3. import pygame
  4. import random
  5. import time
  6.  
  7. # Initialize Pygame
  8. pygame.init()
  9.  
  10. # Set up the display
  11. WIDTH, HEIGHT = 800, 600
  12. screen = pygame.display.set_mode((WIDTH, HEIGHT))
  13. pygame.display.set_caption("Two-Player Line Game")
  14.  
  15. # Colors
  16. BLACK = (0, 0, 0)
  17. WHITE = (255, 255, 255)
  18. RED = (255, 0, 0)
  19. BLUE = (0, 0, 255)
  20.  
  21. # Game variables
  22. line_pos = WIDTH // 2
  23. move_direction = 0
  24. move_speed = 100 # pixels per second
  25. last_move_time = 0
  26. wait_time = random.uniform(1, 5) # Random wait time between 1 and 5 seconds
  27.  
  28. # Font
  29. font = pygame.font.Font(None, 36)
  30.  
  31. def draw_game():
  32. screen.fill(BLACK)
  33. pygame.draw.rect(screen, BLUE, (0, 0, line_pos, HEIGHT))
  34. pygame.draw.rect(screen, RED, (line_pos, 0, WIDTH - line_pos, HEIGHT))
  35. pygame.draw.line(screen, WHITE, (line_pos, 0), (line_pos, HEIGHT), 2)
  36.  
  37. # Draw player labels
  38. a_text = font.render("A", True, WHITE)
  39. l_text = font.render("L", True, WHITE)
  40. screen.blit(a_text, (20, HEIGHT // 2))
  41. screen.blit(l_text, (WIDTH - 40, HEIGHT // 2))
  42.  
  43. # Draw percentage
  44. a_percent = font.render(f"{int(line_pos / WIDTH * 100)}%", True, WHITE)
  45. l_percent = font.render(f"{int((WIDTH - line_pos) / WIDTH * 100)}%", True, WHITE)
  46. screen.blit(a_percent, (line_pos // 2 - 20, 20))
  47. screen.blit(l_percent, (line_pos + (WIDTH - line_pos) // 2 - 20, 20))
  48.  
  49. pygame.display.flip()
  50.  
  51. def game_over(winner):
  52. screen.fill(BLACK)
  53. text = font.render(f"Player {winner} wins!", True, WHITE)
  54. screen.blit(text, (WIDTH // 2 - 100, HEIGHT // 2))
  55. pygame.display.flip()
  56. pygame.time.wait(3000)
  57.  
  58. running = True
  59. clock = pygame.time.Clock()
  60.  
  61. while running:
  62. for event in pygame.event.get():
  63. if event.type == pygame.QUIT:
  64. running = False
  65. if event.type == pygame.KEYDOWN:
  66. if event.key == pygame.K_a and move_direction < 0:
  67. move_direction = 0
  68. if event.key == pygame.K_l and move_direction > 0:
  69. move_direction = 0
  70.  
  71. current_time = time.time()
  72.  
  73. if move_direction == 0 and current_time - last_move_time > wait_time:
  74. move_direction = random.choice([-1, 1])
  75. last_move_time = current_time
  76. wait_time = random.uniform(1, 5)
  77.  
  78. if move_direction != 0:
  79. line_pos += move_direction * move_speed * clock.get_time() / 1000
  80.  
  81. if line_pos <= 0:
  82. game_over("L")
  83. running = False
  84. elif line_pos >= WIDTH:
  85. game_over("A")
  86. running = False
  87.  
  88. line_pos = max(0, min(WIDTH, line_pos))
  89.  
  90. draw_game()
  91. clock.tick(60)
  92.  
  93. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement