Advertisement
jaldpsd
Aug 15th, 2024
37
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. Grok 2 (sus-column-r)
  2.  
  3.  
  4. import pygame
  5. import random
  6. import time
  7.  
  8. # Initialize Pygame
  9. pygame.init()
  10.  
  11. # Screen setup
  12. WIDTH, HEIGHT = 800, 400
  13. screen = pygame.display.set_mode((WIDTH, HEIGHT))
  14. pygame.display.set_caption('Line of Letters')
  15.  
  16. # Colors
  17. WHITE = (255, 255, 255)
  18. BLACK = (0, 0, 0)
  19. RED = (255, 0, 0)
  20. BLUE = (0, 0, 255)
  21.  
  22. # Game variables
  23. line_position = WIDTH // 2
  24. player_a_score = player_l_score = 50
  25. move_delay = 2 # Seconds before the line can move again
  26. last_move_time = time.time()
  27. move_direction = 0 # -1 for left, 1 for right, 0 for stationary
  28.  
  29. # Function to reset the game state
  30. def reset_game():
  31. global line_position, player_a_score, player_l_score, last_move_time
  32. line_position = WIDTH // 2
  33. player_a_score = player_l_score = 50
  34. last_move_time = time.time()
  35.  
  36. # Game loop
  37. clock = pygame.time.Clock()
  38. running = True
  39.  
  40. while running:
  41. for event in pygame.event.get():
  42. if event.type == pygame.QUIT:
  43. running = False
  44.  
  45. # Random movement of the line
  46. current_time = time.time()
  47. if current_time - last_move_time > move_delay and random.random() < 0.01: # 1% chance each frame after the delay
  48. move_direction = random.choice([-1, 1])
  49. last_move_time = current_time
  50. elif current_time - last_move_time > move_delay:
  51. move_direction = 0 # Stop moving if delay has passed
  52.  
  53. keys = pygame.key.get_pressed()
  54.  
  55. # Player A (left side, pressing 'A')
  56. if keys[pygame.K_a]:
  57. line_position -= 1 if move_direction != 1 else 2 # Counteract the line's random move
  58.  
  59. # Player L (right side, pressing 'L')
  60. if keys[pygame.K_l]:
  61. line_position += 1 if move_direction != -1 else 2
  62.  
  63. # Keep line within bounds
  64. line_position = max(0, min(line_position, WIDTH))
  65.  
  66. # Update scores
  67. player_a_score = line_position * 100 // WIDTH
  68. player_l_score = 100 - player_a_score
  69.  
  70. # Drawing
  71. screen.fill(WHITE)
  72. pygame.draw.line(screen, BLACK, (line_position, 0), (line_position, HEIGHT), 2)
  73.  
  74. # Draw territories
  75. pygame.draw.rect(screen, RED, (0, 0, line_position, HEIGHT))
  76. pygame.draw.rect(screen, BLUE, (line_position, 0, WIDTH - line_position, HEIGHT))
  77.  
  78. # Display scores or player indicators
  79. font = pygame.font.Font(None, 36)
  80. text_a = font.render(f'A: {player_a_score}%', True, BLACK)
  81. text_l = font.render(f'L: {player_l_score}%', True, BLACK)
  82. screen.blit(text_a, (10, 10))
  83. screen.blit(text_l, (WIDTH - 100, 10))
  84.  
  85. # Check for win condition
  86. if player_a_score <= 0 or player_l_score <= 0:
  87. winner = 'L' if player_a_score <= 0 else 'A'
  88. win_text = font.render(f'Player {winner} wins!', True, BLACK)
  89. screen.blit(win_text, (WIDTH//2 - 100, HEIGHT//2))
  90. pygame.display.flip()
  91. pygame.time.wait(3000)
  92. reset_game()
  93.  
  94. pygame.display.flip()
  95. clock.tick(60) # 60 FPS
  96.  
  97. pygame.quit()
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement