-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (34 loc) · 1023 Bytes
/
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
from turtle import Screen, onkey
from snake_mech import Snake
from Snake_food import Food
import time
from snake_scorecard import Scorecard
scorecard=Scorecard()
screen = Screen()
screen.setup(width=600, height=600)
screen.bgcolor('black')
screen.title('Feast of the Serpent')
screen.tracer(0)
food=Food()
snake = Snake()
game_is_on = True
screen.listen()
onkey(snake.up, "Up")
onkey(snake.down, "Down")
onkey(snake.left, "Left")
onkey(snake.right, "Right")
while game_is_on:
screen.update()
snake.move()
time.sleep(0.1)
if snake.head.distance(food)<15:
food.refresh()
scorecard.increase_score()
for segs in snake.segments[1:]:
if snake.head.distance(segs)<10:
game_is_on=False
scorecard.gameover()
if snake.head.xcor()>300 or snake.head.xcor()<- 300 or snake.head.ycor()>300 or snake.head.ycor()<-300:
game_is_on = False
scorecard.gameover()
screen.exitonclick()