猫史档案馆


低配版的游戏!电脑差的可以试试

用户:呵呵123456789呵呵123456789查看:0 回复:0 评论:0 创建时间:2024-04-03T19:32:43


这个追逐游戏有点难

代码:

import turtle
import time
import random

scr = turtle.Screen()
scr.setup(1000,500)

pl = turtle.Turtle()
pl.penup()
pl.speed(0)
pl.shape('turtle')
pl.shapesize(2)
def u():
    pl.setheading(90)
    pl.fd(15)
def d():
    pl.setheading(-90)
    pl.fd(15)
def l():
    pl.setheading(180)
    pl.fd(15)
def r():
    pl.setheading(0)
    pl.fd(15)

ent = turtle.Turtle()
ent.speed(0)
ent.penup()
ent.shapesize(3)

ent.goto(random.randint(-200,300),random.randint(-150,150))
pl.goto(random.randint(-200,300),random.randint(-150,150))
scr.onkey(u,'Up')
scr.onkey(d,'Down')
scr.onkey(l,'Left')
scr.onkey(r,'Right')
scr.listen()
game = True
start = time.localtime().tm_sec
while game:
    ent.setheading(ent.towards(pl))
    ent.fd(2.8)
    if ent.distance(pl) <= 10:
        game = False
end = time.localtime().tm_sec
tame = end-start
ent.hideturtle(),pl.hideturtle()
writer = turtle.Pen()
writer.hideturtle()
writer.penup()
writer.write(f'你坚持了{tame}秒',align='center',font=('宋体',75,'bold'))
time.sleep(3)


回复

上一页1 页 / 共 0下一页