반응형

방향키 사용하여 랜덤으로 배치되는 동그라미까지 이동하기


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
import random
import turtle
 
#거북이로 동그라미까지 이동하기
 
player = turtle.Turtle()  #사용할 거북이
player.color("blue")
player.shape("turtle")
player.speed(0)
player.penup()
player.goto(random.randint(-300,300), random.randint(-300300))
screen = player.getscreen()
 
a1 = turtle.Turtle() #목표지점1
a1.color("red")
a1.shape("circle")
a1.speed(0)
a1.penup()
a1.goto(random.randint(-300,300), random.randint(-300300))
 
a2 = turtle.Turtle() #목표지점1
a2.color("red")
a2.shape("circle")
a2.speed(0)
a2.penup()
a2.goto(random.randint(-300,300), random.randint(-300300))
 
def left() :
        player.left(30)
def right():
        player.right(30)
def up() :
        player.forward(30)
def down() :
        player.backward(30)
 
screen.onkeypress(left, "Left")
screen.onkeypress(right, "Right")
screen.onkeypress(up, "Up")
screen.onkeypress(down, "Down")
screen.listen()
 
 
def play() :
        playser.forward(2)
        a1.forward(2)
        a2(forward2)
        screen.ontimer(play, 10)
 
screen.ontimer(play, 10)
 
cs


반응형

+ Recent posts