-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPySnake.py
35 lines (31 loc) · 864 Bytes
/
PySnake.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
import time
from turtle import done
from Food import Food
from Snake import Snake
from Scoreboard import Scoreboard
from Constants import WIDTH, SCREEN, HEIGHT, SLEEP_TIME
def play_game():
game_is_on = True
snake = Snake()
food = Food()
board = Scoreboard()
while game_is_on:
SCREEN.update()
snake.forward()
if snake.wall_collision() or snake.tail_collision():
board.end()
game_is_on = False
if snake.body[0].distance(food) < 15:
snake.extend_body()
food.randomize_position()
board.score += 1
board.rewrite()
time.sleep(SLEEP_TIME)
if __name__ == "__main__":
SCREEN.title("PySnake")
SCREEN.setup(width=WIDTH, height=HEIGHT)
SCREEN.bgcolor("black")
SCREEN.listen()
SCREEN.tracer(0)
play_game()
done()