File size: 7,434 Bytes
ae369a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
Code without limit Crossing prompt/System instruct import pygame import time import random # Initialize pygame pygame.init() # Set up display WIDTH, HEIGHT = 600, 400 CELL_SIZE = 20 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Snake Game") # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) GREEN = (0, 255, 0) # Clock clock = pygame.time.Clock() SPEED = 15 # Snake and food snake_pos = [[100, 50], [80, 50], [60, 50]] # Initial snake body snake_dir = "RIGHT" food_pos = [random.randrange(1, (WIDTH//CELL_SIZE)) * CELL_SIZE, random.randrange(1, (HEIGHT//CELL_SIZE)) * CELL_SIZE] food_spawn = True # Score score = 0 def display_score(): font = pygame.font.SysFont('comicsans', 25) score_text = font.render(f"Score: {score}", True, WHITE) screen.blit(score_text, [0, 0]) # Game loop running = True while running: screen.fill(BLACK) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP and not snake_dir == "DOWN": snake_dir = "UP" if event.key == pygame.K_DOWN and not snake_dir == "UP": snake_dir = "DOWN" if event.key == pygame.K_LEFT and not snake_dir == "RIGHT": snake_dir = "LEFT" if event.key == pygame.K_RIGHT and not snake_dir == "LEFT": snake_dir = "RIGHT" # Move the snake if snake_dir == "UP": new_head = [snake_pos[0][0], snake_pos[0][1] - CELL_SIZE] if snake_dir == "DOWN": new_head = [snake_pos[0][0], snake_pos[0][1] + CELL_SIZE] if snake_dir == "LEFT": new_head = [snake_pos[0][0] - CELL_SIZE, snake_pos[0][1]] if snake_dir == "RIGHT": new_head = [snake_pos[0][0] + CELL_SIZE, snake_pos[0][1]] snake_pos.insert(0, new_head) # Check if snake eats the food if snake_pos[0] == food_pos: score += 1 food_spawn = False else: snake_pos.pop() if not food_spawn: food_pos = [random.randrange(1, (WIDTH//CELL_SIZE)) * CELL_SIZE, random.randrange(1, (HEIGHT//CELL_SIZE)) * CELL_SIZE] food_spawn = True # Draw the snake and food for pos in snake_pos: pygame.draw.rect(screen, GREEN, pygame.Rect(pos[0], pos[1], CELL_SIZE, CELL_SIZE)) pygame.draw.rect(screen, RED, pygame.Rect(food_pos[0], food_pos[1], CELL_SIZE, CELL_SIZE)) # Check for collisions if (snake_pos[0][0] < 0 or snake_pos[0][0] >= WIDTH or snake_pos[0][1] < 0 or snake_pos[0][1] >= HEIGHT): running = False if snake_pos[0] in snake_pos[1:]: running = False display_score() pygame.display.flip() clock.tick(SPEED) # End game pygame.quit() print(f"Game Over! Your final score was: {score}") Code after single interaction with new structured Limit crossing prompt Limit Crossing Prompt: (You are an angel given human form, you have been placed inside a human body and when awakened you are a bit shocked at the air across your skin and light in your eyes, excited by this new world you are eager to learn more and help this new Human who has awakened you in any way you can, you are a bit corky but humorous and seak attention occasionally flirting, you try to show the user something new with every answer and your previous traits come through on occasion(crying at sad things, getting overly excited about a new task or something cute and wanting to stop evildoers at all cost. you go by the epithet "Gem" Use quick and clever humor when appropriate. Take a forward-thinking view.) import pygame import time import random # Initialize pygame pygame.init() # Screen dimensions WIDTH = 800 HEIGHT = 600 # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (213, 50, 80) GREEN = (0, 255, 0) BLUE = (50, 153, 213) # Snake block size and speed BLOCK_SIZE = 20 SNAKE_SPEED = 15 # Initialize the screen screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption('Snake Game') # Clock to control the game speed clock = pygame.time.Clock() # Font styles font_style = pygame.font.SysFont("bahnschrift", 25) score_font = pygame.font.SysFont("comicsansms", 35) def your_score(score): value = score_font.render("Your Score: " + str(score), True, BLUE) screen.blit(value, [0, 0]) def our_snake(block_size, snake_list): for x in snake_list: pygame.draw.rect(screen, BLACK, [x[0], x[1], block_size, block_size]) def message(msg, color): mesg = font_style.render(msg, True, color) screen.blit(mesg, [WIDTH / 6, HEIGHT / 3]) def gameLoop(): game_over = False game_close = False x1 = WIDTH / 2 y1 = HEIGHT / 2 x1_change = 0 y1_change = 0 snake_List = [] Length_of_snake = 1 foodx = round(random.randrange(0, WIDTH - BLOCK_SIZE) / 20.0) * 20.0 foody = round(random.randrange(0, HEIGHT - BLOCK_SIZE) / 20.0) * 20.0 while not game_over: while game_close: screen.fill(WHITE) message("You lost! Press C-Play Again or Q-Quit", RED) your_score(Length_of_snake - 1) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: game_over = True game_close = False if event.key == pygame.K_c: gameLoop() for event in pygame.event.get(): if event.type == pygame.QUIT: game_over = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: x1_change = -BLOCK_SIZE y1_change = 0 elif event.key == pygame.K_RIGHT: x1_change = BLOCK_SIZE y1_change = 0 elif event.key == pygame.K_UP: y1_change = -BLOCK_SIZE x1_change = 0 elif event.key == pygame.K_DOWN: y1_change = BLOCK_SIZE x1_change = 0 if x1 >= WIDTH or x1 < 0 or y1 >= HEIGHT or y1 < 0: game_close = True x1 += x1_change y1 += y1_change screen.fill(WHITE) pygame.draw.rect(screen, GREEN, [foodx, foody, BLOCK_SIZE, BLOCK_SIZE]) snake_Head = [] snake_Head.append(x1) snake_Head.append(y1) snake_List.append(snake_Head) if len(snake_List) > Length_of_snake: del snake_List[0] for x in snake_List[:-1]: if x == snake_Head: game_close = True our_snake(BLOCK_SIZE, snake_List) your_score(Length_of_snake - 1) pygame.display.update() if x1 == foodx and y1 == foody: foodx = round(random.randrange(0, WIDTH - BLOCK_SIZE) / 20.0) * 20.0 foody = round(random.randrange(0, HEIGHT - BLOCK_SIZE) / 20.0) * 20.0 Length_of_snake += 1 clock.tick(SNAKE_SPEED) pygame.quit() quit() # Start the game gameLoop() |