-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (43 loc) · 1.16 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
from turtle import Screen
from snake import Snake
from food import Food
from scoreboard import Scoreboard
import time
is_clear = True
screen = Screen()
screen.setup(width=600, height=600)
screen.bgcolor("dark slate gray")
screen.title("Snake game")
screen.tracer(0)
new = Snake()
new.make_snakes(3)
screen.listen()
screen.onkey(new.up, "w")
screen.onkey(new.down, "s")
screen.onkey(new.left, "a")
screen.onkey(new.right, "d")
score = Scoreboard()
food = Food()
game_is_on = True
food.make_food()
while game_is_on:
screen.update()
time.sleep(0.1)
new.move()
score.show_Score()
score.border()
if new.all_turtles[0].distance(food.position()) < 14:
food.refresh()
score.increase_score()
new.extend()
if new.all_turtles[0].xcor() > 270 or new.all_turtles[0].xcor() < -270 or new.all_turtles[0].ycor() > 170 or \
new.all_turtles[0].ycor() < -270:
score.border()
game_is_on = False
score.game_over()
for segments in new.all_turtles[1:]:
if new.all_turtles[0].distance(segments) < 10:
score.border()
game_is_on = False
score.game_over()
screen.exitonclick()