-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (63 loc) · 1.22 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
65
66
67
68
69
70
71
72
73
import turtle as t
import random
def turn_left():
t.left(10)
def turn_right():
t.right(10)
def fire():
global target
an = t.heading()
while t.ycor() > 0:
t.forward(20)
t.right(6)
d = t.distance(target, 0)
t.sety(random.randint(10, 100))
if d < 25:
t.color("blue")
t.write("Good!", False, "center", ("", 15))
else:
t.color("red")
t.write("Bad!", False, "center", ("", 15))
t.color("black")
t.goto(-200, 10)
t.setheading(an)
def left():
global target
t.clear()
t.goto(-300, 0)
t.down()
t.goto(300, 0)
target = random.randint(50, 150)
t.color("green")
t.up()
t.goto(target - 25, 2)
t.down()
t.goto(target +25, 2)
t.color("black")
t.up()
t.goto(-200, 10)
t.setheading(20)
t.color("black")
t.up()
t.goto(-200, 10)
t.setheading(20)
t.goto(-300, 0)
t.down()
t.goto(300, 0)
target = random.randint(50, 150)
t.pensize(1)
t.color("green")
t.up()
t.goto(target - 25, 2)
t.down()
t.goto(target +25, 2)
t.color("black")
t.up()
t.goto(-200, 10)
t.setheading(20)
t.onkeypress(left, "Left")
t.onkeypress(turn_left, "Up")
t.onkeypress(turn_right, "Down")
t.onkeypress(fire, "space")
t.listen()
t.mainloop()