赞
踩
开心消消乐是消除类的游戏,适合休闲娱乐打法时间。只要点击俩个相同颜色的方块,方块就会消失,直到所有颜色的方块消失,我们就闯关成功进入下一关。
# 导入我们需要用到的库
import turtle as tt
import random as ra
import time as ti
# 设置关卡n从第一关开始
n=1
isck=0
tt.tracer(1,0)
tpencolor='deeppink,darkorange,brown,fuchsia,olive,aqua,red,green,yellow,blue,purple,salmon,sandybrown,skyblue,plum,coral,blueviolet,darkgoldenrod'
colors=tpencolor.split(',')
isonclick=True
scr=tt.Screen()
# 创建分数
fenshu=[tt.Turtle(),-1,1]
fenshu[0].ht()
fenshu[0].up()
fenshu[0].sety(-380)
fenshu[0].down()
onclicknum=1
onclickTurtle=tt.Turtle()
onclickTurtle.ht()
turtles=[]
def fenshus():
global fenshu
fenshu[1]=fenshu[1]+fenshu[2]
fenshu[0].undo()
fenshu[0].write('你的分数为:'+str(fenshu[1])+'分',align='center',font=('宋体',20))
fenshus()
def creategame(lve):
global turtles
global colors
if len(turtles)!=0:
for i in turtles:
i['tpen'].clear()
del turtles[0:len(turtles)]
x=-25-55*lve
y=25+55*lve
tpenid=0
colorsid=0
for i in range(lve*2+1):
for j in range(lve*2+1):
tpen=tt.Turtle()
tpen.ht()
tpen.speed(0)
tpencolor='silver'
if tpenid%2==0 and tpenid!=0:
colorsid=colorsid+1
tpenfillcolor=colors[colorsid%len(colors)]
tpenxy=(x+i*55,y-j*55)
tpenisshow=True
tpenid=tpenid+1
# 画笔,画笔颜色,填充颜色,画笔初始坐标,画笔是否显示,画笔编号
tpenType={'tpen':tpen,'tpencolor':tpencolor,'tpenfillcolor':tpenfillcolor,'tpenxy':tpenxy,'tpenisshow':tpenisshow,'tpenid':tpenid}
turtles.append(tpenType)
def suiji(turtles):
for i in turtles:
# 让每一个颜色---begin---随机去一个地方
colors=i['tpenfillcolor']
suiji=ra.randint(0,len(turtles)-1)
i['tpenfillcolor']=turtles[suiji]['tpenfillcolor']
turtles[suiji]['tpenfillcolor']=colors
# ---end---
def maingame(turtles):
for i in range(len(turtles)):
if turtles[i]['tpenisshow']==False:
continue
maingameid(i)
def maingameid(turtleid):
turtles[turtleid]['tpen'].color(turtles[turtleid]['tpencolor'])
turtles[turtleid]['tpen'].fillcolor(turtles[turtleid]['tpencolor'])
turtles[turtleid]['tpen'].up()
turtles[turtleid]['tpen'].goto(turtles[turtleid]['tpenxy'])
turtles[turtleid]['tpen'].down()
turtles[turtleid]['tpen'].begin_fill()
for j in range(4):
turtles[turtleid]['tpen'].fd(50)
turtles[turtleid]['tpen'].right(90)
turtles[turtleid]['tpen'].end_fill()
def maingameids(turtleid):
turtles[turtleid]['tpen'].color(turtles[turtleid]['tpenfillcolor'])
turtles[turtleid]['tpen'].fillcolor(turtles[turtleid]['tpenfillcolor'])
turtles[turtleid]['tpen'].up()
turtles[turtleid]['tpen'].goto(turtles[turtleid]['tpenxy'])
turtles[turtleid]['tpen'].down()
turtles[turtleid]['tpen'].begin_fill()
for j in range(4):
turtles[turtleid]['tpen'].fd(50)
turtles[turtleid]['tpen'].right(90)
turtles[turtleid]['tpen'].end_fill()
def showcolor(turtles):
for i in range(len(turtles)):
if turtles[i]['tpenisshow']==False:
continue
maingameids(i)
def maingameidss(turtleid):
turtles[turtleid]['tpen'].color(turtles[turtleid]['tpenfillcolor'])
turtles[turtleid]['tpen'].up()
turtles[turtleid]['tpen'].goto(turtles[turtleid]['tpenxy'])
turtles[turtleid]['tpen'].down()
for j in range(4):
turtles[turtleid]['tpen'].fd(50)
turtles[turtleid]['tpen'].right(90)
def showpencolor(turtles):
for i in range(len(turtles)):
if turtles[i]['tpenisshow']==False:
continue
maingameidss(i)
def isY():
global turtles
global n
count=0
for i in turtles:
if i['tpenisshow']==True:
count+=1
if count>=2:
break
if count<=1:
n=n+1
global fenshu
fenshu[2]=fenshu[2]+1
creategame(n)
suiji(turtles)
showcolor(turtles)
ti.sleep(3)
maingame(turtles)
tt.ontimer(isY,1000)
def onclickTurtle(x,y):
global isonclick
global isck
if isonclick==False:
return
isonclick=False
global onclicknum
global onclickTurtle
global turtles
global n
for i in range(len(turtles)):
if turtles[i]['tpenisshow']==True and turtles[i]['tpen'].pos()[0]<=x and x<=turtles[i]['tpen'].pos()[0]+50 and turtles[i]['tpen'].pos()[1]>=y and y>=turtles[i]['tpen'].pos()[1]-50:
turtles[i]['tpen'].color(turtles[i]['tpencolor'])
turtles[i]['tpen'].fillcolor(turtles[i]['tpenfillcolor'])
turtles[i]['tpen'].begin_fill()
for z in range(4):
turtles[i]['tpen'].fd(50)
turtles[i]['tpen'].right(90)
turtles[i]['tpen'].end_fill()
if onclicknum%2==0 and onclicknum != 0:
if turtles[i]['tpen'].fillcolor()==turtles[onclickTurtle]['tpen'].fillcolor() and turtles[i]['tpenid']!=turtles[onclickTurtle]['tpenid']:
ti.sleep(0.4)
turtles[i]['tpenisshow']=False
turtles[i]['tpen'].clear()
turtles[onclickTurtle]['tpenisshow']=False
turtles[onclickTurtle]['tpen'].clear()
fenshus()
if isck==0:
maingame(turtles)
isck=1
else:
ti.sleep(0.4)
maingameid(i)
maingameid(onclickTurtle)
if isck>=10:
showpencolor(turtles)
isck=0
elif isck==0:
maingame(turtles)
isck=1
else:
isck+=1
else:
onclickTurtle=i
onclicknum=onclicknum+1
break
isonclick=True
creategame(n)
suiji(turtles)
showcolor(turtles)
ti.sleep(3)
maingame(turtles)
scr.onclick(onclickTurtle)
isY()
# 设置当用户按下退出才能退出
tt.mainloop()
如果你安装了pip,那么只需在cmd输入: pip install pyinstaller,稍等片刻即可安装完成。
1、首先我们进入到我们要打包的python文件所在的目录,将路径复制下来。
2、接着打开cmd, 进入到python文件所在的目录。
cd 路径
输入命令:pyinstaller -F 文件名.py
运行,如果打包的是一个项目的话,那么这个文件名一定得是项目的入口文件,否则打包完成后有可能出错。
如果报错The 'enum34' package is an obsolete backport of a standard library package and is incompatible with PyInstaller. Please conda remove enum34 then try again.
解决方法:打开一个新的cmd,输入pip uninstall enum34
卸载enum34这个包。
重新打包,成功了。
程序目录多出了build、dist两个文件夹和消消乐.spec
文件,我们要运行的exe
程序在dist文件夹里面。
双击这个程序,出现下面情图现象,
稍等片刻之后,彩色方块变成灰色,点击相同颜色的方块,方块消失,全部完成后,升级进入下一关。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。