资源描述:
《Python俄罗斯方块源码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、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],[a
2、1,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=juxi
3、ng(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.cle
4、ar(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]=1ifj<14:ll[22+i][j]=1if(S<1o
5、rS>15):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]ifS<1:return####___________________classtu(object):def__init__(s,S1=0,x=5,y=0):s.x=x;s.y=y
6、t0=[[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
7、=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#_________