Ramikan-BR commited on
Commit
b9a9cbf
1 Parent(s): fab0916

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +78 -0
README.md CHANGED
@@ -12,6 +12,84 @@ tags:
12
  - sft
13
  ---
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  # Uploaded model
16
 
17
  - **Developed by:** Ramikan-BR
 
12
  - sft
13
  ---
14
 
15
+ Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
16
+
17
+ ### Input:
18
+ Write a code to create the snake game
19
+
20
+ ### Output:
21
+
22
+ Here is a simple implementation of the classic Snake game in Python using the Pygame library. This code will create a window with a snake that moves in a grid, eating apples and growing in length.
23
+
24
+ ```python
25
+ import pygame
26
+ import random
27
+ import time
28
+
29
+ # Initialize Pygame
30
+ pygame.init()
31
+
32
+ # Set the dimensions of the window
33
+ width, height = 640, 480
34
+ screen = pygame.display.set_mode((width, height))
35
+ pygame.display.set_caption('Snake Game')
36
+
37
+ # Define colors
38
+ white = (255, 255, 255)
39
+ black = (0, 0, 0)
40
+ red = (255, 0, 0)
41
+ green = (0, 255, 0)
42
+
43
+ # Define the snake
44
+ snake_pos = [20, 20]
45
+ snake_dir = [1, 0]
46
+ snake_size = 16
47
+ snake_length = 1
48
+
49
+ # Define the apple
50
+ apple_pos = [random.randint(20, 300), randomative(20, 300)
51
+ apple_size = 16
52
+
53
+ # Define the clock
54
+ clock = pygame.time.Clock()
55
+
56
+ # Game loop
57
+ running = True
58
+ while running:
59
+ # Handle events
60
+ for event in pygame.event.get():
61
+ if event.type == pygame.QUIT:
62
+ running = False
63
+
64
+ # Move the snake
65
+ new_pos = [snake_pos[0] + snake_dir[0], snake_pos[1] + snake_dir[1]]
66
+ if new_pos[0] < 0 or new_pos[0] > width - snake_size:
67
+ snake_dir[0] *= -1
68
+ if new_pos[1] < 0 or new_pos[1] > height - snake_size:
69
+ snake_dir[1] *= -1
70
+ snake_pos[0] = new_pos[0]
71
+ snake_pos[1] = new_pos[1]
72
+
73
+ # Check for apple collision
74
+ if snake_pos[0] == apple_pos[0] and snake_pos[1] == apple_pos[1]:
75
+ apple_pos = [random.randint(20, 300), random.randint(20, 300)]
76
+ snake_length += 1
77
+
78
+ # Draw the screen
79
+ screen.fill(white)
80
+ pygame.draw.rect(screen, red, [apple_pos[0], apple_pos[1], apple_size, apple_size])
81
+ for i in range(snake_length):
82
+ pygame.draw.rect(screen, green, [snake_pos[0] - i * snake_size, snake_pos[1], snake_size, snake_size])
83
+ pygame.display.flip()
84
+
85
+ # Control the frame rate
86
+ clock.tick(10)
87
+
88
+ pygame.quit()
89
+ ```
90
+
91
+ This code will create a window with a snake that moves in a grid, eating apples and growing in length. The snake will bounce off the walls of the window. To play the game, simply run the code and use the arrow keys to control the snake.<|endoftext|>
92
+
93
  # Uploaded model
94
 
95
  - **Developed by:** Ramikan-BR