用户:学学vQey查看:0 回复:0 评论:0 创建时间:2021-12-25T09:09:39
【作品展示】

【作品介绍】
可以通过记忆相同的发牌,然后翻相同的卡牌,看看你的几分(翻对一组得分+2,翻错-2)用时多少
【作品源代码】
import pgzrun
import random
import time
WIDTH = 400
HEIGHT = 600
imgList = ['1.png', '1.png', '2.png', '2.png',
'3.png', '3.png', '4.png', '4.png',
'5.png', '5.png', '6.png', '6.png']
pList = [[70, 80], [200, 80], [330, 80],
[70, 230], [200, 230], [330, 230],
[70, 380], [200, 380], [330, 380],
[70, 530], [200, 530], [330, 530]]
random.shuffle(imgList)
bg = Actor('背景.png')
ready = Actor('准备界面.png')
# 成功界面角色
success = Actor('成功界面.png', [600, 300])
num = 0
cList = []
for i in range(12):
a = Actor(imgList[i], pList[i])
cList.append(a)
memory = []
dt = 0
def draw():
bg.draw()
for c in cList:
c.draw()
ready.draw()
success.draw()
if success.x == 200:
screen.draw.text(str(dt), center=[
240, 420], fontsize=50, color='yellow')
screen.draw.text(str(num), center=[240, 467], fontsize=50, color='red')
begin = 0
def showBack():
global begin
global dt
for c in cList:
c.image = '背面.png'
begin = time.time()
def on_mouse_down(pos):
global num
if ready.collidepoint(pos):
ready.x = 600
clock.schedule(showBack, 3)
for c in cList:
if c.collidepoint(pos) and c.image == '背面.png':
if len(memory) < 2:
i = cList.index(c)
c.image = imgList[i]
memory.append(c)
if len(memory) == 2: # 两张卡牌进行比较
clock.schedule(compare, 0.4)
count = 12
def compare():
global count
global dt
global num
c1 = memory[0]
c2 = memory[1]
if c1.image == c2.image:
c1.pos = [600, 300]
c2.pos = [600, 300]
count -= 2
num += 2
if count == 0:
success.x = 200
end = time.time()
dt = int(end-begin)
else:
c1.image = '背面.png'
c2.image = '背面.png'
num -= 2
memory.clear()
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn