用python画猫和老鼠_一个Python游戏:猫和老鼠
写出一个猫和老鼠的游戏。游戏者使用方向键来控制老鼠,使其保持在猫的前方(由计算机控制猫)。保持时间越长,得分越高。
import turtle
import time
boxsize = 200
caught = False
score = 0
# functions that are called on keypresses
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()
# stop the mouse from leaving the square set by box size
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
写出一个猫和老鼠的游戏。游戏者使用方向键来控制老鼠,使其保持在猫的前方(由计算机控制猫)。保持时间越长,得分越高。 import turtle import time boxsize = 200 caught = False score = 0 # functions that are called on keypresses 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() # stop the mouse from leaving the square set by box size 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