Python俄罗斯方块源码

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

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

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

资源描述

Python俄罗斯方块源码诺基亚S60v2手机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]]returnlist1defMasks():#蒙罩生成函数img=Image.new((10,10),L)img2=Image.new((10,10),L)img3=Image.new((10,10),L)img2.clear(0)img3.clear(0)biao=juxing(9.5,9.7,0.7,0.2,0.3)img.polygon((biao),0xff5fff,0xff5fff)img2.polygon((biao),0xffffff,0xffffff)img3.polygon((biao),0xffffff,0xffffff)biao=juxing(7.8,7.8,1)img.polygon((biao),0xf9ff9f,0x9fff9f,width=1)img3.polygon((biao),0x0,0x0)foriinrange(5):RGB=(105+i*20,105+i*20,115+i*20)img.line((2,5-i,8,5-i),(RGB))img.line((2,5+i,8,5+i),(RGB))return(img,img2,img3)defImages(mask1,se2):#生成彩色画布函数img=Image.new((10,10))img2=Image.new((10,10))img2.clear(0xffffff)img.clear(se2)foriinrange(8):img.arc((2+i*0.7,3,2+i,8),0,2,(255-i*10,200-i*10,0+i*20))img.blit(img2,target=(0,0),source=(0,0,10,10),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*10-10);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*10+10*j-18,y+s.y*10+10*i-20),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=(6,0,12)foriinrange(3):ImgBg.rectangle((112,30+i*45,171,48+i*45),(0),(98,105,99),width=2)#底纹ImgBg.text((116+B[i],48+i*45),cn(str(fen[i])),(255,20,30),(dense,16))#关卡/分数/行数ImgBg.text((140,48),cn(/+str(cen)),(0,255,255),(dense,16))#层数ImgBg.blit(img_lan,target=(120,160),source=(14,0,68,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,104,200),0xff7777,width=2)ImgBg.rectangle((0,200,104,208),0xff7777,0xff7777,width=2)menu=(等级,分数,行数,NEXT)ImgBg.blit(img_lan,target=(106,0))#信息栏框foriinrange(10):ImgBg.line((3+i*10,203,8+i*10,203),(0+i*20,200-i*15,0+i*20),width=7)#装饰彩色线条img=Image.new((25,15))foriinrange(7):ImgBg.blit(img,target=(0+i*15,200),source=(0,0,15,20),mask=mask1)foriinrange(len(menu)):ImgBg.text((120,25+i*45),cn(menu[i]),(0+i*50,0,255-i*50),(dense,15))#信息栏字幕#_____________________defdraw_tx(s):#画初始方块foriinrange(22):forjinrange(12):ifFK_SUM[i][j]:ImgBg.blit(ImgJi[8],target=(j*10-18,i*10-20),mask=mask2)#_____________________defOver(s):#结束s.k=2s.isRunning=0while(s.isRunning!=1):ImgBg.text((6,60),cn(GAMEOVER!),(255,50,255),(dense,16))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#-----------------iflen(n)0andlen(n)5:#计算分值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((100,200))img.clear(0)ce=0foriinrange(20,0,-1):ifi==n[0]-1:ce+=10img.

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

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

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

×
保存成功