-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (46 loc) · 1.14 KB
/
main.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
from turtle import Screen
from snake import Snake
from food import Food
from scoreboard import Score
import time
N = 600
D = 10
speed = 3
sleep_time = 0.000001
up = "Up"
down = "Down"
left = "Left"
right = "Right"
black = "black"
sqr = "square"
screen = Screen()
screen.setup(width = N+100, height = N+100)
screen.bgcolor(black)
screen.title("Snake Game")
screen.tracer(0)
snake = Snake()
food = Food()
score = Score()
screen.listen()
screen.onkey(snake.up ,up)
screen.onkey(snake.down ,down)
screen.onkey(snake.left ,left)
screen.onkey(snake.right ,right)
runn = True
while runn:
screen.update()
time.sleep(sleep_time)
snake.move()
if snake.head.distance(food) < 16:
food.refresh()
score.increase()
snake.extend()
snake.incr_speed()
if snake.head.xcor() > 295 or snake.head.xcor() < -295 or snake.head.ycor() > 295 or snake.head.ycor() < -295:
runn = False
score.gameover()
for i in snake.segment[1:]:
if snake.head.distance(i) < 3:
runn = False
score.gameover()
screen.exitonclick()