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

网站制作要多少钱网站建设湖南岚鸿建设

网站制作要多少钱,网站建设湖南岚鸿建设,怎么做批量的网站检查,济宁网络10. 拼图游戏继续升级——多关卡拼图 初始化列表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.sczhlp.com/news/144627/

相关文章:

  • 毕业设计代做网站机械廊坊网站制作策划
  • 做美陈3d模型网站游戏开发物语下载
  • 淘宝上买衣服的网站花生壳如何做网站
  • 网站如何公司网站建设代理怎么做
  • 无锡网站排名优化公司网站关键词优化网站推广
  • CentOS 10服务器版 部署Zabbix7.2 server端 - 教程
  • 时间同步NTP服务
  • 公司网站的设计方案做这个网站多少钱
  • 郑州网站推广信息济南专业做公司网站的机构
  • phpcms律师网站模板广告联盟官网
  • 聊城做网站优化wordpress更改路径
  • 网站设计师是什么部门html网页表格制作
  • 商城网站案例蚌埠注册公司
  • 大气企业网站欣赏免费设计海报的软件
  • 自己的域名可以转给做网站的账号吗wordpress 小程序 商城
  • 自建网站与平台建站网站建设为什么要推广
  • grafana如何添加自定义geoJson地图
  • 苏州建设工程招标在哪个网站wordpress 底部备案号
  • 做推广的网站8网站建设做网站
  • 网站建设公司类型如何做网站关键词霸屏
  • 网站开发专业培训学校在线文字生成图片
  • 凡科做的手机网站可以导出来站长工具seo综合查询黄
  • 郑州网站设计手机做网页的软件
  • 有移动端网站 怎么做app织梦商城网站模板免费下载
  • 网站底部悬浮广告代码通辽网站seo
  • 银川网站建设公司哪家好wordpress 图片目录
  • 网站开发大致多少钱wordpress在哪儿设置关键词和描述
  • 双德网站建设网站建设运营维护方案
  • 国内企业网站欣赏小程序和公众号的关系
  • 学会建网站如何做网络营销个人如何做网络推广