用户:
一言为定sceE查看:0 回复:5 评论:0 创建时间:2021-08-12T16:48:05


找宝藏是我自己做的游戏,20宝藏 5喵,点到喵会结束游戏。下面是源码(素材在上面):
# 导入库
import turtle,random
# 创建画布
ms = turtle.Screen()
# 画布大小
ms.setup(1200,800)
# 画布背景图片
ms.bgpic('bg.gif')
#关闭动画
ms.tracer(0)
#导入
ms.addshape('box.gif')
ms.addshape('喵.gif')
box_list=[]
喵_list=[]
# 创建
def create(shape):
p = turtle.Pen()
p.hideturlte()
p.shape(shape)
x=random.randint(-500,500)
y = random.randint(-300, 300)
p.penup()
p.goto(x,y)
if shape=='box.gif':
box_list.append(p)
if shape=='喵.gif':
喵_list.append(p)
ms.update()
for i in range(20):
create('box.gif')
for i in range(5):
create('喵.gif')
d=turtle.Pen()
d.color('gold')
d.shape('circle')
def move(x,y):
d.color('gold')
d.penup()
d.goto(x,y)
for box in box_list:
if d.distance(box.xcor(),box.ycor())<30:
d.color('green')
print('find it')
box.showturtle()
for 喵 in 喵_list:
if d.distance(喵.xcor(), 喵.ycor()) < 30:
d.color('red')
print('oh on')
喵.showturtle()
ms.onclick(None, btn=1)
print('GAME OVER!!!!!!!!!!!!!!!!!')
ms.update()
ms.onclick(move,btn=1)
# 固定
turtle.done()