猫史档案馆


【Python作品分享】向雯晴---猫和老鼠【作品秀】

用户:坚强的超能鸭nGCy坚强的超能鸭nGCy查看:0 回复:0 评论:0 创建时间:2021-01-30T21:47:10


【作品展示】

center_image

 

【作品介绍】

人物请你们自己找一下吧,我真的发不了。你们也可以把猫和老鼠换成其他人物,这是一款猫捉老鼠的游戏。我小学四年级,这是我创作的第一个用键盘控制的游戏,希望大家多多支持,多多点赞。真的谢谢大家。有问题尽管提,我会尽量改进的。评论区等着你们哟。

 

【作品源代码】

import turtle 
import time

screen = turtle.Screen()
screen.setup(800,850)
screen.bgpic("背景.gif")

screen.addshape("cat.gif")
cat = turtle.Pen()
cat.shape("cat.gif")

screen.addshape("mouse.gif")
screen.tracer(0)
mouse = turtle.Pen()
mouse.shape("mouse.gif")
mouse.penup()
mouse.goto(200,-200)


def up():
    mouse.setheading(90)
    mouse.forward(3)


def down():
    mouse.setheading(270)
    mouse.forward(3)

def left():
    mouse.setheading(180)
    mouse.forward(3)

def right():
    mouse.setheading(0)
    mouse.forward(3)

screen.listen()
screen.onkeypress(up, "Up")
screen.onkeypress(down, "Down")
screen.onkeypress(left, "Left")
screen.onkeypress(right, "Right")

cat.penup()

scor=turtle.Pen()
scor.hideturtle()

game = 0
playing = True
while playing:
    angle = cat.towards(mouse)
    cat.setheading(angle)
    cat.forward(1)
    if cat.distance(cat.xcor(), mouse.ycor())<1:
        playing = False
    game += 1
    scor.write(f'分数:{game}', font=("思源宋体", 40, "normal"), align="center")
    screen.update()
    time.sleep(0.07)
    scor.clear()

scor.write(f'游戏结束结束,分数是:{game}', font=("思源宋体", 40, "normal"), align="center")

turtle.done()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页