Advertisement
Guest User

GPT-4 vs Llama-3 vs Claude

a guest
Apr 19th, 2024
1,040
0
Never
7
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.99 KB | Source Code | 0 0
  1. =================================
  2.  
  3. Code Generated by GPT-4:
  4.  
  5. =================================
  6.  
  7. import pygame
  8. import random
  9. import time
  10.  
  11. pygame.init()
  12. width, height = 800, 600
  13. screen = pygame.display.set_mode((width, height))
  14. clock = pygame.time.Clock()
  15.  
  16. # Initial position of the line
  17. line_x = width // 2
  18.  
  19. def move_line():
  20. global line_x
  21. move_rate = random.choice([-5, 5]) # Line moves left or right randomly
  22. while 0 < line_x < width:
  23. line_x += move_rate
  24. yield
  25. if line_x <= 0 or line_x >= width:
  26. break
  27.  
  28. # Main game loop
  29. running = True
  30. line_movement = move_line()
  31. while running:
  32. for event in pygame.event.get():
  33. if event.type == pygame.QUIT:
  34. running = False
  35. elif event.type == pygame.KEYDOWN:
  36. if event.key == pygame.K_a and move_rate > 0: # Player A stops the line moving left
  37. line_movement = move_line()
  38. elif event.key == pygame.K_l and move_rate < 0: # Player L stops the line moving right
  39. line_movement = move_line()
  40.  
  41. next(line_movement, None) # Move the line
  42. screen.fill((0, 0, 0))
  43. pygame.draw.line(screen, (255, 255, 255), (line_x, 0), (line_x, height))
  44. pygame.display.flip()
  45. clock.tick(60)
  46.  
  47. pygame.quit()
  48.  
  49.  
  50. =================================
  51.  
  52. Code Generated by LlaMA-3:
  53.  
  54. =================================
  55.  
  56. import pygame
  57. import random
  58. import time
  59.  
  60. # Initialize Pygame
  61. pygame.init()
  62.  
  63. # Set up the game window dimensions
  64. WINDOW_WIDTH = 800
  65. WINDOW_HEIGHT = 600
  66. screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
  67.  
  68. # Set up the title of the window
  69. pygame.display.set_caption("Territory Tussle")
  70.  
  71. # Define some colors
  72. WHITE = (255, 255, 255)
  73. BLACK = (0, 0, 0)
  74. RED = (255, 0, 0)
  75. GREEN = (0, 255, 0)
  76.  
  77. # Set up the game variables
  78. player_A_territory = 50
  79. player_L_territory = 50
  80. line_x = WINDOW_WIDTH / 2
  81. line_speed = 2
  82. player_A_score = 0
  83. player_L_score = 0
  84. moving_right = True
  85. game_over = False
  86.  
  87. # Set up the game clock
  88. clock = pygame.time.Clock()
  89.  
  90. # Game loop
  91. while True:
  92. # Event handling
  93. for event in pygame.event.get():
  94. if event.type == pygame.QUIT:
  95. pygame.quit()
  96. sys.exit()
  97. elif event.type == pygame.KEYDOWN:
  98. if event.key == pygame.K_a:
  99. if not moving_right:
  100. moving_right = True
  101. line_speed = 2
  102. elif event.key == pygame.K_l:
  103. if moving_right:
  104. moving_right = False
  105. line_speed = 2
  106. elif event.type == pygame.KEYUP:
  107. line_speed = 2
  108.  
  109. # Move the line
  110. if moving_right:
  111. line_x += line_speed
  112. else:
  113. line_x -= line_speed
  114.  
  115. # Check for boundary collisions
  116. if line_x <= 0:
  117. line_x = 0
  118. elif line_x >= WINDOW_WIDTH:
  119. line_x = WINDOW_WIDTH
  120.  
  121. # Update the game state
  122. if player_A_territory <= 0 or player_L_territory <= 0:
  123. game_over = True
  124. elif player_A_territory >= 100 or player_L_territory >= 100:
  125. game_over = True
  126.  
  127. # Draw everything
  128. screen.fill(WHITE)
  129. pygame.draw.line(screen, BLACK, (line_x, 0), (line_x, WINDOW_HEIGHT), 2)
  130. pygame.draw.rect(screen, RED, (0, 0, line_x, WINDOW_HEIGHT))
  131. pygame.draw.rect(screen, GREEN, (line_x, 0, WINDOW_WIDTH - line_x, WINDOW_HEIGHT))
  132.  
  133. # Game over banner
  134. if game_over:
  135. banner_font = pygame.font.SysFont("Arial", 50)
  136. banner_text = banner_font.render("Game Over! Press R to restart.", True, BLACK)
  137. screen.blit(banner_text, (100, 100))
  138.  
  139. # Restart button
  140. restart_font = pygame.font.SysFont("Arial", 30)
  141. restart_text = restart_font.render("R", True, BLACK)
  142. screen.blit(restart_text, (100, 200))
  143.  
  144. # Dominance percentage
  145. if player_A_score + player_L_score > 0:
  146. dominance_font = pygame.font.SysFont("Arial", 20)
  147. if player_A_territory >= 100:
  148. dominance_text = dominance_font.render(f"Player A dominance: 100%", True, BLACK)
  149. else:
  150. dominance_text = dominance_font.render(f"Player A dominance: {player_A_score / (player_A_score + player_L_score) * 100:.2f}%", True, BLACK)
  151. screen.blit(dominance_text, (100, 300))
  152. if player_L_territory >= 100:
  153. dominance_text = dominance_font.render(f"Player L dominance: 100%", True, BLACK)
  154. else:
  155. dominance_text = dominance_font.render(f"Player L dominance: {player_L_score / (player_A_score + player_L_score) * 100:.2f}%", True, BLACK)
  156. screen.blit(dominance_text, (100, 350))
  157.  
  158. # Update the display
  159. pygame.display.flip()
  160.  
  161. # Cap the frame rate
  162. clock.tick(60)
  163.  
  164. # Check for restart
  165. keys = pygame.key.get_pressed()
  166. if keys[pygame.K_r] and game_over:
  167. player_A_territory = 50
  168. player_L_territory = 50
  169. line_x = WINDOW_WIDTH / 2
  170. game_over = False
  171.  
  172.  
  173.  
  174. =================================
  175.  
  176. Code generated by Claude 3 Sonnet:
  177.  
  178. =================================
  179.  
  180.  
  181.  
  182. import pygame
  183. import random
  184. import time
  185.  
  186. # Initialize Pygame
  187. pygame.init()
  188.  
  189. # Set up the game window
  190. WINDOW_WIDTH = 800
  191. WINDOW_HEIGHT = 600
  192. window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
  193. pygame.display.set_caption("Line Game")
  194.  
  195. # Define colors
  196. BLACK = (0, 0, 0)
  197. WHITE = (255, 255, 255)
  198. RED = (255, 0, 0)
  199. BLUE = (0, 0, 255)
  200.  
  201. # Game variables
  202. player1_territory = WINDOW_WIDTH // 2
  203. player2_territory = WINDOW_WIDTH // 2
  204. line_position = WINDOW_WIDTH // 2
  205. line_moving = False
  206. line_speed = 5
  207. line_direction = 0 # 0 = left, 1 = right
  208. move_interval = 3 # seconds
  209.  
  210. # Game loop
  211. running = True
  212. clock = pygame.time.Clock()
  213. last_move_time = time.time()
  214.  
  215. while running:
  216. clock.tick(60) # Limit frame rate
  217.  
  218. # Handle events
  219. for event in pygame.event.get():
  220. if event.type == pygame.QUIT:
  221. running = False
  222.  
  223. # Player input
  224. keys = pygame.key.get_pressed()
  225. if keys[pygame.K_a] and line_moving and line_direction == 1:
  226. line_moving = False
  227. if keys[pygame.K_l] and line_moving and line_direction == 0:
  228. line_moving = False
  229.  
  230. # Move the line
  231. if not line_moving:
  232. current_time = time.time()
  233. if current_time - last_move_time > move_interval:
  234. line_moving = True
  235. line_direction = random.randint(0, 1)
  236. last_move_time = current_time
  237.  
  238. if line_moving:
  239. if line_direction == 0: # Move left
  240. line_position -= line_speed
  241. else: # Move right
  242. line_position += line_speed
  243.  
  244. # Update player territories
  245. player1_territory = line_position
  246. player2_territory = WINDOW_WIDTH - line_position
  247.  
  248. # Check for game over
  249. if player1_territory <= 0:
  250. print("Player 2 wins!")
  251. running = False
  252. elif player2_territory <= 0:
  253. print("Player 1 wins!")
  254. running = False
  255.  
  256. # Clear the window
  257. window.fill(BLACK)
  258.  
  259. # Draw the line
  260. pygame.draw.line(window, WHITE, (line_position, 0), (line_position, WINDOW_HEIGHT), 2)
  261.  
  262. # Draw player territories
  263. pygame.draw.rect(window, RED, (0, 0, player1_territory, WINDOW_HEIGHT))
  264. pygame.draw.rect(window, BLUE, (player1_territory, 0, player2_territory, WINDOW_HEIGHT))
  265.  
  266. # Update the display
  267. pygame.display.flip()
  268.  
  269. # Quit Pygame
  270. pygame.quit()
Tags: decrypt
Advertisement
Comments
  • jaldpsd
    336 days (edited)
    # text 0.75 KB | 0 0
    1. Prompt:
    2.  
    3. I want to create a game.
    4. To players play against each other in the same computer. One is in control of the letter L and the other controls the letter A.
    5. We have a field divided by two with a line. Each player controls 50% of the field. The player who controls A controls the left half and the one who controls L controls the right half
    6. At a random momemnt, the line will move towards either the left or the right.
    7. The player who is losing ground must pres the button as fast as possible to prevent the line from moving anymore.
    8. When that's done, the line will stay in place and players will have to wait until the line starts to move at a random moment to a random location.
    9. The player who ends up controling 0% of the screen loses and the game ends
  • jaldpsd
    329 days
    # text 2.76 KB | 0 0
    1. Code created by Reka Core:
    2.  
    3.  
    4. import pygame
    5. import random
    6. import time
    7.  
    8. # Initialize Pygame
    9. pygame.init()
    10.  
    11. # Game window dimensions
    12. WINDOW_WIDTH = 800
    13. WINDOW_HEIGHT = 400
    14.  
    15. # Create the game window
    16. screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
    17.  
    18. # Set the window title
    19. pygame.display.set_caption("Letter Game")
    20.  
    21. # Line movement speed
    22. LINE_SPEED = 5
    23.  
    24. # Player colors
    25. PLAYER_A_COLOR = (255, 0, 0)
    26. PLAYER_L_COLOR = (0, 0, 255)
    27.  
    28. # Game field dimensions
    29. FIELD_WIDTH = WINDOW_WIDTH
    30. FIELD_HEIGHT = WINDOW_HEIGHT // 2
    31.  
    32. # Player-controlled areas
    33. player_a_area = FIELD_WIDTH // 2
    34. player_l_area = FIELD_WIDTH // 2
    35.  
    36. # Line position
    37. line_x = WINDOW_WIDTH // 2
    38. line_y = FIELD_HEIGHT
    39.  
    40. # Line direction
    41. line_direction = random.choice([-1, 1])
    42.  
    43. # Game loop
    44. running = True
    45. while running:
    46. # Handle events
    47. for event in pygame.event.get():
    48. if event.type == pygame.QUIT:
    49. running = False
    50. elif event.type == pygame.KEYDOWN:
    51. if event.key == pygame.K_a and line_x <= FIELD_WIDTH * 3 // 4:
    52. line_x = FIELD_WIDTH * 3 // 4
    53. line_direction = 1
    54. time.sleep(random.uniform(0, 5))
    55. elif event.key == pygame.K_l and line_x >= FIELD_WIDTH // 4:
    56. line_x = FIELD_WIDTH // 4
    57. line_direction = -1
    58. time.sleep(random.uniform(0, 5))
    59.  
    60. # Move the line in a specific direction
    61. line_x += line_direction * LINE_SPEED
    62.  
    63. # Check if a player is losing ground
    64. if line_x <= FIELD_WIDTH // 4:
    65. player_l_area -= LINE_SPEED
    66. line_x = FIELD_WIDTH // 2 - player_a_area
    67. elif line_x >= FIELD_WIDTH * 3 // 4:
    68. player_a_area -= LINE_SPEED
    69. line_x = FIELD_WIDTH // 2 + player_l_area
    70.  
    71. # Update player-controlled areas
    72. player_a_area = FIELD_WIDTH // 2 - line_x
    73. player_l_area = line_x - FIELD_WIDTH // 2
    74.  
    75. # Draw the game field
    76. screen.fill((255, 255, 255))
    77. pygame.draw.line(screen, (0, 0, 0), (line_x, line_y), (line_x, WINDOW_HEIGHT), 2)
    78. pygame.draw.rect(screen, PLAYER_A_COLOR, (0, 0, player_a_area, FIELD_HEIGHT))
    79. pygame.draw.rect(screen, PLAYER_L_COLOR, (player_a_area, 0, player_l_area, FIELD_HEIGHT))
    80.  
    81. # Update the display
    82. pygame.display.flip()
    83.  
    84. # Wait for the next line movement
    85. time.sleep(0.1)
    86.  
    87. # Game over screen
    88. pygame.display.set_caption("Game Over")
    89. screen.fill((255, 255, 255))
    90. if player_a_area == 0:
    91. winner = "Player L"
    92. elif player_l_area == 0:
    93. winner = "Player A"
    94. text = pygame.font.Font(None, 36).render(f"Winner: {winner}", True, (0, 0, 0))
    95. text_rect = text.get_rect(center=(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2))
    96. screen.blit(text, text_rect)
    97. pygame.display.flip()
    98. time.sleep(3)
    99.  
    100. # Quit Pygame
    101. pygame.quit()
  • jaldpsd
    273 days
    # text 3.73 KB | 0 0
    1. Code created by Claude Sonnet 3.5:
    2.  
    3. <!DOCTYPE html>
    4. <html lang="en">
    5. <head>
    6. <meta charset="UTF-8">
    7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    8. <title>Two-Player Line Game</title>
    9. <style>
    10. body {
    11. display: flex;
    12. justify-content: center;
    13. align-items: center;
    14. height: 100vh;
    15. margin: 0;
    16. font-family: Arial, sans-serif;
    17. }
    18. #gameContainer {
    19. width: 600px;
    20. height: 300px;
    21. position: relative;
    22. overflow: hidden;
    23. }
    24. #player1, #player2 {
    25. position: absolute;
    26. top: 0;
    27. height: 100%;
    28. display: flex;
    29. align-items: center;
    30. justify-content: center;
    31. font-size: 48px;
    32. color: white;
    33. }
    34. #player1 {
    35. left: 0;
    36. background-color: red;
    37. }
    38. #player2 {
    39. right: 0;
    40. background-color: blue;
    41. }
    42. #divider {
    43. position: absolute;
    44. top: 0;
    45. width: 4px;
    46. height: 100%;
    47. background-color: black;
    48. }
    49. #instructions {
    50. position: absolute;
    51. bottom: 10px;
    52. text-align: center;
    53. width: 100%;
    54. }
    55. </style>
    56. </head>
    57. <body>
    58. <div id="gameContainer">
    59. <div id="player1"></div>
    60. <div id="player2"></div>
    61. <div id="divider"></div>
    62. <div id="instructions">Player 1: Press 'A' | Player 2: Press 'L'</div>
    63. </div>
    64.  
    65. <script>
    66. const gameContainer = document.getElementById('gameContainer');
    67. const player1 = document.getElementById('player1');
    68. const player2 = document.getElementById('player2');
    69. const divider = document.getElementById('divider');
    70.  
    71. let gameWidth = gameContainer.offsetWidth;
    72. let dividerPosition = gameWidth / 2;
    73. let isMoving = false;
    74. let moveDirection = 0;
    75. let moveSpeed = 1;
    76.  
    77. function updateGame() {
    78. player1.style.width = `${dividerPosition}px`;
    79. player2.style.width = `${gameWidth - dividerPosition}px`;
    80. divider.style.left = `${dividerPosition}px`;
    81.  
    82. player1.textContent = dividerPosition > 0 ? 'A' : '';
    83. player2.textContent = dividerPosition < gameWidth ? 'L' : '';
    84.  
    85. if (dividerPosition <= 0 || dividerPosition >= gameWidth) {
    86. endGame();
    87. }
    88. }
    89.  
    90. function startMoving() {
    91. if (!isMoving) {
    92. isMoving = true;
    93. moveDirection = Math.random() > 0.5 ? 1 : -1;
    94. moveDivider();
    95. }
    96. }
    97.  
    98. function moveDivider() {
    99. if (isMoving) {
    100. dividerPosition += moveDirection * moveSpeed;
    101. updateGame();
    102. requestAnimationFrame(moveDivider);
    103. }
    104. }
    105.  
    106. function stopMoving() {
    107. if (isMoving) {
    108. isMoving = false;
    109. setTimeout(startMoving, 1000);
    110. }
    111. }
    112.  
    113. function endGame() {
    114. isMoving = false;
    115. alert(dividerPosition <= 0 ? "Player 2 (L) wins!" : "Player 1 (A) wins!");
    116. }
    117.  
    118. document.addEventListener('keydown', (event) => {
    119. if (event.key.toLowerCase() === 'a' && moveDirection > 0) {
    120. stopMoving();
    121. } else if (event.key.toLowerCase() === 'l' && moveDirection < 0) {
    122. stopMoving();
    123. }
    124. });
    125.  
    126. updateGame();
    127. setTimeout(startMoving, 1000);
    128. </script>
    129. </body>
    130. </html>
  • jaldpsd
    218 days
    # text 2.60 KB | 0 0
    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()
  • jaldpsd
    218 days
    # text 2.92 KB | 0 0
    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.  
  • jaldpsd
    218 days
    # text 2.34 KB | 0 0
    1. Grok 2 Mini:
    2. import pygame
    3. import random
    4.  
    5. # Initialize Pygame
    6. pygame.init()
    7.  
    8. # Constants
    9. SCREEN_WIDTH = 800
    10. SCREEN_HEIGHT = 600
    11. LINE_WIDTH = 10
    12. FPS = 60
    13.  
    14. # Colors
    15. WHITE = (255, 255, 255)
    16. BLACK = (0, 0, 0)
    17. RED = (255, 0, 0)
    18. GREEN = (0, 255, 0)
    19.  
    20. # Setup
    21. screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
    22. pygame.display.set_caption("L vs A Game")
    23. clock = pygame.time.Clock()
    24.  
    25. # Game variables
    26. line_position = SCREEN_WIDTH // 2
    27. line_speed = 10
    28. line_direction = 1 # 1 for right, -1 for left
    29. game_over = False
    30. button_pressed = False
    31.  
    32. # Player controls
    33. A_KEY = pygame.K_a
    34. L_KEY = pygame.K_l
    35.  
    36. def move_line():
    37. global line_position, line_direction
    38. if not button_pressed:
    39. line_position += line_speed * line_direction
    40. if line_position <= 0 or line_position >= SCREEN_WIDTH:
    41. line_direction *= -1
    42. line_position += line_speed * line_direction
    43.  
    44. def check_game_over():
    45. global game_over
    46. if line_position <= 0 or line_position >= SCREEN_WIDTH:
    47. game_over = True
    48.  
    49. def draw_game():
    50. screen.fill(BLACK)
    51. pygame.draw.line(screen, WHITE, (line_position, 0), (line_position, SCREEN_HEIGHT), LINE_WIDTH)
    52. pygame.draw.rect(screen, RED if line_direction == 1 else GREEN, (0, 0, line_position, SCREEN_HEIGHT), 0)
    53. pygame.draw.rect(screen, GREEN if line_direction == 1 else RED, (line_position, 0, SCREEN_WIDTH - line_position, SCREEN_HEIGHT), 0)
    54.  
    55. if game_over:
    56. font = pygame.font.Font(None, 74)
    57. text = font.render("Game Over!", True, WHITE)
    58. text_rect = text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
    59. screen.blit(text, text_rect)
    60.  
    61. pygame.display.flip()
    62.  
    63. # Main game loop
    64. running = True
    65. while running:
    66. for event in pygame.event.get():
    67. if event.type == pygame.QUIT:
    68. running = False
    69. elif event.type == pygame.KEYDOWN:
    70. if event.key == A_KEY and line_direction == -1:
    71. button_pressed = True
    72. elif event.key == L_KEY and line_direction == 1:
    73. button_pressed = True
    74. elif event.type == pygame.KEYUP:
    75. if event.key in [A_KEY, L_KEY]:
    76. button_pressed = False
    77.  
    78. if not game_over:
    79. move_line()
    80. check_game_over()
    81.  
    82. draw_game()
    83. clock.tick(FPS)
    84.  
    85. pygame.quit()
    86.  
  • jaldpsd
    176 days
    # text 2.58 KB | 0 0
    1. Llama 3.2 90B (on Groq)
    2.  
    3. import pygame
    4. import random
    5. import sys
    6.  
    7. # Initialize Pygame
    8. pygame.init()
    9.  
    10. # Set up some constants
    11. WIDTH, HEIGHT = 800, 600
    12. LINE_COLOR = (255, 255, 255)
    13. PLAYER_A_COLOR = (0, 0, 255)
    14. PLAYER_L_COLOR = (255, 0, 0)
    15.  
    16. # Set up the display
    17. screen = pygame.display.set_mode((WIDTH, HEIGHT))
    18.  
    19. # Set up the font
    20. font = pygame.font.Font(None, 36)
    21.  
    22. # Set up the clock
    23. clock = pygame.time.Clock()
    24.  
    25. # Set up the game variables
    26. line_x = WIDTH // 2
    27. player_a_score = WIDTH // 2
    28. player_l_score = WIDTH // 2
    29. moving = False
    30. direction = 0
    31.  
    32. # Game loop
    33. while True:
    34. for event in pygame.event.get():
    35. if event.type == pygame.QUIT:
    36. pygame.quit()
    37. sys.exit()
    38. elif event.type == pygame.KEYDOWN:
    39. if event.key == pygame.K_a and moving and direction == -1:
    40. moving = False
    41. elif event.key == pygame.K_l and moving and direction == 1:
    42. moving = False
    43.  
    44. # Move the line
    45. if not moving and random.random() < 0.05:
    46. moving = True
    47. direction = random.choice([-1, 1])
    48. if moving:
    49. line_x += direction * 5
    50. if line_x < 0:
    51. line_x = 0
    52. player_a_score = 0
    53. player_l_score = WIDTH
    54. moving = False
    55. elif line_x > WIDTH:
    56. line_x = WIDTH
    57. player_a_score = WIDTH
    58. player_l_score = 0
    59. moving = False
    60.  
    61. # Draw everything
    62. screen.fill((0, 0, 0))
    63. pygame.draw.line(screen, LINE_COLOR, (line_x, 0), (line_x, HEIGHT), 5)
    64. pygame.draw.rect(screen, PLAYER_A_COLOR, (0, 0, line_x, HEIGHT))
    65. pygame.draw.rect(screen, PLAYER_L_COLOR, (line_x, 0, WIDTH - line_x, HEIGHT))
    66. a_text = font.render(f"A: {player_a_score}", True, (255, 255, 255))
    67. l_text = font.render(f"L: {player_l_score}", True, (255, 255, 255))
    68. screen.blit(a_text, (10, 10))
    69. screen.blit(l_text, (WIDTH - 100, 10))
    70.  
    71. # Check for game over
    72. if player_a_score == 0 or player_l_score == 0:
    73. if player_a_score == 0:
    74. screen.fill((0, 0, 0))
    75. text = font.render("L wins!", True, (255, 255, 255))
    76. screen.blit(text, (WIDTH // 2 - 50, HEIGHT // 2))
    77. else:
    78. screen.fill((0, 0, 0))
    79. text = font.render("A wins!", True, (255, 255, 255))
    80. screen.blit(text, (WIDTH // 2 - 50, HEIGHT // 2))
    81. pygame.display.flip()
    82. pygame.time.wait(2000)
    83. break
    84.  
    85. # Update the display
    86. pygame.display.flip()
    87.  
    88. # Cap the frame rate
    89. clock.tick(60)
    90.  
    91. # Quit Pygame
    92. pygame.quit()
Add Comment
Please, Sign In to add comment
Advertisement