当前位置: 首页 > news >正文

做教育培训网站公司西安专业网络推广平台

做教育培训网站公司,西安专业网络推广平台,电子科技网站,做好的网页上传到wordpress10. 拼图游戏继续升级——多关卡拼图 初始化列表Photos用来储存拼图文件名,Photo_ID用来统计当下是第几张拼图,Squares储存当下拼图的24张小拼图的文件名,Gird储存当下窗口上显示的24个小拼图及坐标。 Photos["girl_","boy_…

10. 拼图游戏继续升级——多关卡拼图

  • 初始化列表Photos用来储存拼图文件名,Photo_ID用来统计当下是第几张拼图,Squares储存当下拼图的24张小拼图的文件名,Gird储存当下窗口上显示的24个小拼图及坐标。
Photos=["girl_","boy_","cat_"]
Photo_ID=0
Squares=[]
Gird=[]
  • 建立change_Photo()函数通过Photo_ID来初始化新一轮的拼图
def change_Photo():global Photo_IDSquares.clear()Gird.clear()for i in range(1,25):# 初始化最新图片的文件名if i<10:s=Photos[Photo_ID]+'0'+str(i)else:s=Photos[Photo_ID]+str(i)Squares.append(Actor(s))# 略 Squares、Gird的初始化
  • 设定图片切换方法:上一张拼图胜利后按下空格键切换下一张拼图,再次将Is_Win设定为False
  • 修改游戏胜利条件:Photo_ID等于Photos的长度且Is_Win为True时才能迎来最终的胜利
def on_key_down(key):global Photo_ID,Is_Win,Win_musicif key == keys.SPACE:Photo_ID += 1if Photo_ID < len(Photos):Is_Win = FalseWin_music = 0change_Photo()
  • 修改时间的更新条件
def update():global newTime,startTime,Photo_IDif (not Is_Win) or (Photo_ID!=len(Photos)):endTime = datetime.datetime.now()newTime=(endTime-startTime).seconds
  • 再窗口上增加当下是第几张拼图的提示
def draw():# 略screen.draw.text("第" + str(Photo_ID+1)+"张图", (WIDTH-100, 10),\fontsize=20, fontname='s', color="blue")
  • 当最后一张拼图完成增加提示
def draw():# 略if Is_Win:# 略if Photo_ID == len(Photos) :screen.draw.text("已是最后一张图了!", (WIDTH / 2 - 170, HEIGHT / 2 + 50), \fontsize=50, fontname='s', color="blue")

执行效果如下图所示:

完整代码如下:

import pgzrun
import random
import time
import datetimetry:txtFile=open("rank.txt",'r')score=txtFile.readline()
except:txtFile=open("rank.txt",'w')score = "您是第一个玩家"txtFile.write(score)
txtFile.close()startTime=datetime.datetime.now()
oldTime=int(score) if score.isdigit() else 9999
newTime=0TITLE="pgzrun 拼图游戏"
Square_size=125
WIDTH=Square_size*4
HEIGHT=Square_size*6click_time=0
clickID_1=clickID_2=-1
Is_Win=False
Win_music=0sounds.bg_music.play(-1)Photos=["girl_","boy_","cat_"]
Photo_ID=0
Squares=[]
Gird=[]def swap_Square(i,j):  # 两个拼图的位置互换sounds.chick.play()temp_pos=Gird[i].posGird[i].pos=Gird[j].posGird[j].pos=temp_posdef change_Photo():global Photo_IDSquares.clear()Gird.clear()for i in range(1,25):if i<10:s=Photos[Photo_ID]+'0'+str(i)else:s=Photos[Photo_ID]+str(i)Squares.append(Actor(s))for i in range(6):for j in range(4):Square=Squares[i*4+j]Square.left=Square_size*jSquare.top=Square_size*iGird.append(Square)for k in range(10):  # 随机抽取10组拼图 进行位置互换i = random.randint(0, 23)j = random.randint(0, 23)swap_Square(i, j)change_Photo()def on_mouse_down(pos,button): # 当鼠标被点击时global click_time ,clickID_1 , clickID_2,Is_Win,Win_musicfor i in range(24):if Gird[i].collidepoint(pos): # 拼图对象被点击breakif click_time%2==0 :clickID_1=ielse:clickID_2=iswap_Square(clickID_1,clickID_2)click_time += 1# 成功判断is_win = Truefor i in range(6):for j in range(4):Square = Squares[i * 4 + j]if not (Square.left == Square_size * j and Square.top == Square_size * i) :is_win = Falsebreakif is_win:if Win_music==0:sounds.win_music.play()Win_music=1Is_Win=Trueif newTime<oldTime:txtFile=open("rank.txt",'w')txtFile.write(str(newTime))txtFile.close()def draw():screen.clear()for Square in Gird:Square.draw()screen.draw.text("游戏最佳记录: "+str(oldTime), (10, 10), fontsize=20, fontname='s', color="blue")screen.draw.text("第" + str(Photo_ID+1)+"张图", (WIDTH-100, 10), fontsize=20, fontname='s', color="blue")screen.draw.text("游戏运行时间: " + str(newTime), (10, 30), fontsize=20, fontname='s', color="blue")if Is_Win:screen.draw.text("游戏胜利!",(WIDTH/2-100,HEIGHT/2-50),fontsize=50,fontname='s',color="blue")if Photo_ID == len(Photos) :screen.draw.text("已是最后一张图了!", (WIDTH / 2 - 170, HEIGHT / 2 + 50), fontsize=50, fontname='s', color="blue")else :for i in range(5):screen.draw.line((i*Square_size,0),(i*Square_size,HEIGHT),"black")for i in range(7):screen.draw.line((0,i*Square_size),(WIDTH,i*Square_size),"black")if clickID_1!=-1:screen.draw.rect(Rect((Gird[clickID_1].left,Gird[clickID_1].top),(Square_size,Square_size)),"red")def update():global newTime,startTime,Photo_IDif (not Is_Win) or (Photo_ID!=len(Photos)):endTime = datetime.datetime.now()newTime=(endTime-startTime).secondsdef on_key_down(key):global Photo_ID,Is_Win,Win_musicif key == keys.SPACE:Photo_ID += 1if Photo_ID < len(Photos):Is_Win = FalseWin_music = 0change_Photo()pgzrun.go()

pgzrun拼图游戏素材包下载

http://www.hkea.cn/news/281920/

相关文章:

  • 江西网站建设成都百度
  • 糯米团网站怎么做微信软文范例100字
  • 如何在社交网站上做视频推广seo营销的概念
  • 大连做网站仟亿科技最新域名查询
  • 网站开发实施计划与安排宁波网络推广方式
  • 企业网站建设公司注意哪些问题软件开发外包公司
  • abc网站建设怎么样yandex引擎搜索入口
  • wordpress屏蔽f12广州seo网络优化公司
  • 南宁网站建设推广服务云服务器免费
  • 大数据营销是什么seo站长
  • 建设政府网站的公司乐山网站seo
  • 仿站容易还是建站容易专业做灰色关键词排名
  • 做网站背景音乐管理课程培训
  • 网站建设可以自学吗品牌软文范文
  • 网站风格对比哪里有学计算机培训班
  • 做mla的网站网站优化哪家好
  • 网站注册的账号怎么注销线上营销活动有哪些
  • 国内做进口的电商网站网站推广软件哪个好
  • 谁有做那事的网站百度投诉中心入口
  • 免费单页网站在线制作沈阳seo排名优化教程
  • 廊坊网站建大型网站建站公司
  • 远程桌面做网站sem和seo区别与联系
  • 做贷款网站优化大师有用吗
  • 有没有便宜的网站制作制作网页教程
  • 医院网站制作优化关键词的方法有哪些
  • wordpress安装到网站吗泰安seo
  • 长春网站开发培训价格google play三件套
  • 做生存分析的网站有哪些国外新闻最新消息
  • 济南网站优化收费百度互联网营销
  • bootstrap响应网站模板下载发帖推广百度首页