我正在创建一个游戏,用户使用键盘移动乌龟以避免另一只乌龟。这是我的代码:
import turtle
playGround = turtle.Screen()
playGround.screensize(500, 500)
playGround.title("Turtle Keys")
run = turtle.Turtle()
follow = turtle.Turtle()
run.shape("turtle")
follow.shape("turtle")
run.color("blue")
follow.color("red")
run.penup()
follow.penup()
run.st()
def k1():
run.forward(45)
def k2():
run.left(45)
def k3():
run.right(45)
def k4():
run.back(45)
def quitThis():
playGround.bye()
playGround.onkey(k1, "Up") # the up arrow key
playGround.onkey(k2, "Left") # the left arrow key
playGround.onkey(k3, "Right") # you get it!
playGround.onkey(k4, "Down")
playGround.onkey(quitThis,'q')
playGround.listen()
我想让红海龟追逐蓝海龟,但它不起作用。