-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day53-TurtleRace.py
91 lines (75 loc) · 1.76 KB
/
Day53-TurtleRace.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
88
89
90
91
import turtle as t
from turtle import Turtle
import time
from random import randint
# set up window
window = t.Screen()
window.title('Turtle Race')
t.bgcolor('#7bc043') # green field
t.speed(0)
t.penup()
t.setpos(-140, 200)
t.color('white')
t.write("TURTLE RACE", font=("Arial", 30, "bold"))
t.penup()
# dirt
t.setpos(-400, -180)
t.color('#4f372d')
t.begin_fill()
t.pendown()
t.forward(800) # draw 800 pixels going forward
t.right(90) # same logic as this ^
t.forward(300)
t.right(90)
t.forward(800)
t.right(90)
t.forward(300)
t.end_fill()
# finish line
stamp_size = 20
square_size = 15
finish_line = 200
t.color('black')
t.shape('square')
t.shapesize(square_size / stamp_size)
t.penup()
for i in range(10):
t.setpos(finish_line, (150 - (i * square_size * 2)))
t.stamp()
for j in range(10):
t.setpos(finish_line + square_size, ((150 - square_size) - (j * square_size * 2)))
t.stamp()
t.hideturtle()
turtles = []
turt_colours = ["#edc951", "#eb6841", "#cc2a36", "#00a0b0"]
for i in range(4):
t = Turtle()
t.speed(0)
t.color(turt_colours[i])
t.shape("turtle")
t.penup()
t.goto(-250, 100 - i * 50)
t.pendown()
turtles.append(t)
def race():
# MOVE TURTLES
win = False
while not win:
for index, t in enumerate(turtles):
t.forward(randint(1, 5))
if t.xcor() >= 200:
print('The winner is turtle #', index + 1, "!")
win = True
t.speed(1)
t.right(270) # Victory spin
break
def main():
countdown = 3 # Countdown from this number to 1
for k in range(1, countdown + 1):
print(countdown + 1 - k)
time.sleep(1) # Pause for 1 second
print("Go!")
race()
print("End")
window.mainloop()
main()