-
Notifications
You must be signed in to change notification settings - Fork 0
/
wtf.py
87 lines (62 loc) · 2.18 KB
/
wtf.py
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
import pygame
from snake_game import SnakeGame
print("a")
pygame.init()
print("b")
white = (255, 255, 255)
yellow = (255, 255, 102)
black = (0, 0, 0)
red = (213, 50, 80)
green = (0, 255, 0)
blue = (50, 153, 213)
dis_width = 400
dis_height = 400
dis = pygame.display.set_mode((dis_width, dis_height))
pygame.display.set_caption('Snake Game by Edureka')
clock = pygame.time.Clock()
snake_block = 20
snake_speed = 10
font_style = pygame.font.SysFont("bahnschrift", 25)
score_font = pygame.font.SysFont("comicsansms", 35)
def draw_score(score):
value = score_font.render("Your Score: " + str(score), True, yellow)
dis.blit(value, [0, 0])
def draw_snake(snake_block, snake_list):
for pos in snake_list:
pygame.draw.rect(dis, black, [pos.x * snake_block, pos.y * snake_block, snake_block, snake_block])
def gameLoop():
print("c")
game = SnakeGame(20, 20)
print("d")
while not game.finished:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game.finished = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
game._snake.turn_right()
elif event.key == pygame.K_e:
game._snake.turn_left()
game.move_snake()
foodx, foody = game._fruit.pos.x * snake_block, game._fruit.pos.y * snake_block
dis.fill(blue)
pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block])
draw_snake(snake_block, game._snake.body)
draw_score(game._snake.length - 1)
pygame.display.update()
clock.tick(snake_speed)
print("You Lost! Press C-Play Again or Q-Quit")
while game.game_close:
dis.fill(blue)
draw_score(game._snake.length - 1)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
game.finished = True
game.game_close = False
if event.key == pygame.K_c:
gameLoop()
pygame.quit()
quit()
gameLoop()