forked from meet-projects/meet2019y1lab6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fun2.py
58 lines (46 loc) · 1.13 KB
/
fun2.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
##import turtle
##turtle.goto (0,0)
##def up ():
## print ("you pressed the up key.")
##turtle.onkey (up,"Up")
##turtle.goto (0,0)
##turtle.lis
import turtle
turtle.goto (0,0)
turtle.direction = None
def on_move ():
pos =turtle.pos ()
x= pos [0]
y=pos[1]
if turtle.direction == "Up":
turtle.goto (x , y+100)
if turtle.direction == "Right":
turtle.goto (x+100 , y)
if turtle.direction == "Down":
turtle.goto (x , y-100)
if turtle.direction == "Left":
turtle.goto (x-100 , y)
def up ():
turtle.direction = "Up"
on_move ()
print ("you pressed the up key ")
turtle.onkey (up ,"Up")
turtle.listen()
def down ():
turtle.direction = "Down"
on_move ()
print ("you pressed the down key ")
turtle.onkey (down ,"Down")
turtle.listen()
def left ():
turtle.direction = "Left"
on_move ()
print ("you pressed the left key ")
turtle.onkey (left ,"Left")
turtle.listen()
def right ():
turtle.direction = "Right"
on_move ()
print ("you pressed the Right key ")
turtle.onkey (right ,"Right")
turtle.listen()