用键盘方向键来控制老鼠,使其在猫的正前方
import turtle
import time
boxsize=200
caught=False
score=0
#定义响应键盘消息的函数
def up():
mouse.forward(10)
checkbound()
def left():
mouse.left(45)
def right():
mouse.right(45)
def back():
mouse.backward(10)
checkbound()
def quitTurtles():
window.bye()
#检测边界
def checkbound():
global boxsize #使用外部变量
if mouse.xcor() > boxsize:
mouse.goto(boxsize,mouse.ycor())
if mouse.xcor() < -boxsize:
mouse.goto(-boxsize,mouse.ycor())
if mouse.ycor() > boxsize:
mouse.goto(mouse.xcor(),boxsize)
if mouse.ycor() > -boxsize:
mouse.goto(mouse.xcor(),-boxsize)
#设置屏幕
window=turtle.Screen()
mouse=turtle.Turtle()
cat=turtle.Turtle