Python俄罗斯方块源码3

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Python俄罗斯方块源码诺基亚S60v3手机PY平台专用代码作者:千年臭虫fromgraphicsimport*importrandom,e32,appuifwcn=lambdax:x.decode('u8')#_______________________defjuxing(t1,t2,s,x=1,y=1):#参数:宽/高/切角大小/坐标X/坐标Ya1,d1=1+x,t1+xc1=t1-s+xb1=s+1+xa2,d2=1+y,t2+yc2=t2-s+yb2=s+1+ylist1=[[b1,a2],[c1,a2],[d1,b2],[d1,c2],[c1,d2],[b1,d2],[a1,c2],[a1,b2]]returnlist1#_____________________defMasks():#蒙罩生成函数img=Image.new((15,15),L)img2=Image.new((15,15),L)img3=Image.new((15,15),L)img2.clear(0)img3.clear(0)biao=juxing(14.5,14.5,0.9,0.3,0.3)img.polygon((biao),0xff5fff,0xff5fff)img2.polygon((biao),0xffffff,0xffffff)img3.polygon((biao),0xffffff,0xffffff)biao=juxing(12.8,12.8,2)img.polygon((biao),0xf9ff9f,0x9fff9f,width=1)img3.polygon((biao),0x0,0x0)foriinrange(7):RGB=(105+i*20,105+i*20,115+i*20)img.line((2,7.5-i,13,7.5-i),(RGB))img.line((2,7.5+i,13,7.5+i),(RGB))return(img,img2,img3)defImages(mask1,se2):#生成彩色画布函数img=Image.new((15,15))img2=Image.new((15,15))img2.clear(0xffffff)img.clear(se2)foriinrange(8):img.arc((3+i*0.7,5,3+i,10),0,2,(255-i*10,200-i*10,0+i*20))img.blit(img2,target=(0,0),source=(0,0,15,15),mask=mask1)returnimg#_______________________defFkCen(ll,S):#方块层函数foriinrange(2):forjinrange(len(ll)):ll[j][0+i]=1ll[j][12+i]=1ifj14:ll[22+i][j]=1if(S1orS15):returnf0=[1,1,1,1,1,1,1,1,1,0]f1=[1,1,1,1,1,1,1,1,0,0]f2=[1,1,1,1,1,1,1,0,0,0]Fk=[f0,f1,f2]foriinrange(21,0,-1):S-=1v=random.randint(0,2)ls=Fk[v]random.shuffle(ls)#乱序forjinrange(10):ll[i][j+2]=ls[j]ifS1:return####___________________classtu(object):def__init__(s,S1=0,x=5,y=0):s.x=x;s.y=yt0=[[0,1,0],[1,1,1],[0,0,0]]t1=[[1,1,0],[0,1,1],[0,0,0]]t2=[[0,1,1],[1,1,0],[0,0,0]]t3=[[1,0,0],[1,1,1],[0,0,0]]t4=[[0,0,1],[1,1,1],[0,0,0]]t5=[[1,1],[1,1]]t6=[[0,1],[0,1],[0,1],[0,1]]ts=[t0,t1,t2,t3,t4,t5,t6]Fks=[[0,0],[0,0],[0,0],[0,0],[0,0],[0,1],[0,2]]s.FK=ts[S1]s.Fs=Fks[S1]#随机旋转---------S2=random.randint(0,3)foriinrange(S2):s.Xuan_Z(1)#_____________________defgo_zuo(s):#向左if(s.duibi(s.FK,0,1)):s.x-=1;return1else:return0#_____________________defgo_you(s):#向右if(s.duibi(s.FK,0,-1)):s.x+=1;return1else:return0#_____________________defgo_next(s):#向下if(s.duibi(s.FK,1,0)):s.y+=1;return1else:return0#_____________________defXuan_Z(s,L=0):#旋转函数ifs.Fs[1]==0:n=[]foriinrange(3):n.append([s.FK[2][i],s.FK[1][i],s.FK[0][i]])id=0elifs.Fs[1]==1:return0elifs.Fs[1]==2:n=[[0,0,0,0],[1,1,1,1]];id=3elifs.Fs[1]==3:n=[[0,1],[0,1],[0,1],[0,1]];id=2if(L==1):s.FK=n;s.Fs[1]=idreturn1#数据对比foriinrange(3):if(s.duibi(n,0,i)):s.x-=is.FK=n;s.Fs[1]=id;return1if(s.duibi(n,0,-1)):s.x+=1s.FK=n;s.Fs[1]=id;return1return0#_____________________defduibi(s,ll,n,m):#数据对比函数foriinrange(len(ll)):forjinrange(len(ll[0])):if(FK_SUM[s.y+i+n][s.x+j-m]andll[i][j]):return0return1#_____________________defcha(s):#方块数据传递函数foriinrange(len(s.FK)):forjinrange(len(s.FK[0])):if(s.FK[i][j]):FK_SUM[s.y+i][s.x+j]=s.FK[i][j]#_____________________deft_ying(s,im,v=0):#投影判断函数if(touying==0):returnforiinrange(22):if(s.duibi(s.FK,i,0)):passelse:#画投影s.show(im,mask3,ImgLs,0,i*15-15);break#_____________________defshow(s,im,mask,img=None,x=0,y=0):#画方块函数foriinrange(len(s.FK)):forjinrange(len(s.FK[0])):if(s.FK[i][j]):img.blit(im,target=(x+s.x*15+15*j-28,y+s.y*15+15*i-30),mask=mask)####___________________classApp(object):isRunning=True#_____________________def__init__(s):s.k=0appuifw.app.screen=fulls.cs=appuifw.Canvas(s.redraw,s.Key_z)appuifw.app.body=s.css.run()#_____________________defdraw_pin(s):#更新信息栏函数B=(10,0,15)foriinrange(3):ImgBg.rectangle((165,37+i*60,230,63+i*60),(0),(98,105,99),width=3)#底纹ImgBg.text((167+B[i],61+i*60),cn(str(fen[i])),(255,205,20),(dense,18))#关卡/分数/行数ImgBg.text((195,61),cn(/+str(cen)),(255,205,20),(dense,18))#层数ImgBg.blit(img_lan,target=(165,218),source=(10,0,78,68))#NEXT方块框底纹#_____________________defdraw_w(s):s.a.t_ying(ImgJi[7])s.a.show(ImgJi[s.sui],mask2,ImgLs)s.cs.blit(ImgLs)#_____________________defredraw(s,r):s.cs.blit(ImgBg)#_____________________defGameBg(s):#游戏界面绘制函数ImgBg.rectangle((0,-2,154,302),0xff7777,width=2)ImgBg.rectangle((0,303,154,320),0x0000f7,0x0000f7,width=2)menu=(等级,分数,行数,NEXT)ImgBg.blit(img_lan,target=(155,0))#信息栏框img=Image.new((45,25))foriinrange(6):ImgBg.blit(img,target=(-4+i*25,301),source=(0,0,35,20),mask=mask1)foriinrange(len(menu)):ImgBg.text((175,30+i*60),cn(menu[i]),(0+i*50,0,255-i*50),(dense,18))#信息栏字幕#_____________________defdraw_tx(s):#画初始方块函数foriinrange(22):forjinrange(12):ifFK_SUM[i][j]:ImgBg.blit(ImgJi[8],target=(j*15-28,i*15-30),mask=mask2)#_____________________defOver(s):#游戏结束s.k=2s.isRunning=0while(s.isRunning!=1):ImgBg.text((6,80),cn(GAMEOVER!),(255,50,255),(dense,25))s.cs.blit(ImgBg)e32.ao_sleep(0.1)#_____________________defcheck(s):#消除/分值计算/方块切片函数n=[]foriinrange(22):ifFK_SUM[i].count(1)==14:n.append(i)foriinrange(len(n)):delFK_SUM[n[i]]FK_SUM.insert(0,[1,1,0,0,0,0,0,0,0,0,0,0,1,1])s.k=0#-----------------if(len(n)0):#计算分值v=len(n)-1num=[100,300,750,1500]fen[1]+=num[v]fen[2]+=len(n)#----------------n.sort()while(len(n)0):#游戏活动区域切片img=Image.new((150,300))img.clear(0)ce=0foriinrange(20,0,-1):ifi==n[0]-1:ce+=15img.blit(ImgBg,target

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功