基本信息
源码名称:【升级版】记忆力大挑战
源码大小:4.56M
文件格式:.zip
开发语言:Python
更新时间:2021-08-01
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
根据上一次上传的“记忆力大挑战”做出了改进:
1.添加了音效
2.对代码整体进行的改进
重要!!:
pgzero下载教程:https://blog.csdn.net/fengbohello/article/details/114993234
import pgzrun import random import time music.play('卡牌bgm.mp3') WIDTH = 400 HEIGHT = 600 imgList = ['2.png','1.png','2.png','3.png','3.png','4.png','4.png','5.png','5.png','6.png','6.png','1.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') over = Actor('结束界面.png', [600, 300]) begin = 0 during = 0 card = [] for i in range(0, 12): a = Actor(imgList[i], pList[i]) card.append(a) def draw(): bg.draw() for c in card: c.draw() ready.draw() over.draw() if over.x == 200: music.play_once('通关.wav') screen.draw.text(str(during), center = [225, 458], fontsize = 50) def showBack(): for c in card: c.image = '背面.png' memory = [] def on_mouse_down(pos): global begin if ready.collidepoint(pos): ready.x = 600 begin = time.time() clock.schedule(showBack, 3) else: for i in range(0, 12): if card[i].collidepoint(pos) and card[i].image == '背面.png': card[i].image = imgList[i] if len(memory) < 2: memory.append(card[i]) if len(memory) == 2: clock.schedule(wait, 0.2) def wait(): global during if memory[0].image == memory[1].image: memory[0].pos = [600, 300] memory[1].pos = [600, 300] music.play_once('正确.wav') else: memory[0].image = '背面.png' memory[1].image = '背面.png' music.play_once('错误.mp3') memory.clear() count = 0 for c in card: if c.x == 600: count = count 1 if count == 12: over.pos = [200, 300] end = time.time() during = int(end - begin) pgzrun.go()