Python-俄罗斯方块游戏.doc

上传人:bao****ty 文档编号:144596941 上传时间:2020-09-11 格式:DOC 页数:8 大小:53.50KB
返回 下载 相关 举报
Python-俄罗斯方块游戏.doc_第1页
第1页 / 共8页
Python-俄罗斯方块游戏.doc_第2页
第2页 / 共8页
Python-俄罗斯方块游戏.doc_第3页
第3页 / 共8页
Python-俄罗斯方块游戏.doc_第4页
第4页 / 共8页
Python-俄罗斯方块游戏.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《Python-俄罗斯方块游戏.doc》由会员分享,可在线阅读,更多相关《Python-俄罗斯方块游戏.doc(8页珍藏版)》请在金锄头文库上搜索。

1、【Python】用Python实现一个俄罗斯方块游戏俄罗斯方块游戏,使用Python实现,总共有350+行代码,实现了俄罗斯方块游戏的基本功能,同时会记录所花费时间,消去的总行数,所得的总分,还包括一个排行榜,可以查看最高记录。排行榜中包含一系列的统计功能,如单位时间消去的行数,单位时间得分等。附源码:from Tkinter import *from tkMessageBox import *import randomimport time#俄罗斯方块界面的高度HEIGHT = 18#俄罗斯方块界面的宽度WIDTH = 10ACTIVE = 1PASSIVE = 0TRUE = 1FALSE

2、 = 0root=Tk();root.title(Russia)class App(Frame): def _init_(self,master): Frame._init_(self) master.bind(,self.Up) master.bind(,self.Left) master.bind(,self.Right) master.bind(,self.Down) #master.bind(,self.Space) master.bind(,self.Space) master.bind(,self.Play) master.bind(,self.Pause) self.backg=

3、#%02x%02x%02x % (120,150,30) self.frontg=#%02x%02x%02x % (40,120,150) self.nextg=#%02x%02x%02x % (150,100,100) self.flashg=#%02x%02x%02x % (210,130,100) self.LineDisplay=Label(master,text=Lines: ,bg=black,fg=red) self.Line=Label(master,text=0,bg=black,fg=red) self.ScoreDisplay=Label(master,text=Scor

4、e: ,bg=black,fg=red) self.Score=Label(master,text=0,bg=black,fg=red) #Display time self.SpendTimeDisplay=Label(master,text=Time: ,bg=black,fg=red) self.SpendTime=Label(master,text=0.0,bg=black,fg=red) self.LineDisplay.grid(row=HEIGHT-2,column=WIDTH,columnspan=2) self.Line.grid(row=HEIGHT-2,column=WI

5、DTH+2,columnspan=3) self.ScoreDisplay.grid(row=HEIGHT-1,column=WIDTH,columnspan=2) self.Score.grid(row=HEIGHT-1,column=WIDTH+2,columnspan=3) #Display time self.SpendTimeDisplay.grid(row=HEIGHT-4,column=WIDTH,columnspan=2) self.SpendTime.grid(row=HEIGHT-4,column=WIDTH+2,columnspan=3) self.TotalTime=0

6、.0 self.TotalLine=0;self.TotalScore=0 #Game over self.isgameover=FALSE #Pause self.isPause=FALSE #Start self.isStart=FALSE self.NextList=;self.NextRowList= r=0;c=0 for k in range(4*4): LN=Label(master,text= ,bg=str(self.nextg),fg=white,relief=FLAT,bd=4) LN.grid(row=r,column=WIDTH+c,sticky=N+E+S+W) s

7、elf.NextRowList.append(LN) c=c+1 if c=4: r=r+1;c=0 self.NextList.append(self.NextRowList) self.NextRowList= self.BlockList=;self.LabelList= self.BlockRowList=;self.LabelRowList= row=0;col=0 for i in range(HEIGHT*WIDTH): L=Label(master,text= ,bg=str(self.backg),fg=white,relief=FLAT,bd=4) L.grid(row=r

8、ow,column=col,sticky=N+E+S+W) L.row=row;L.col=col;L.isactive=PASSIVE self.BlockRowList.append(0);self.LabelRowList.append(L) col=col+1 if col=WIDTH: row=row+1;col=0 self.BlockList.append(self.BlockRowList) self.LabelList.append(self.LabelRowList) self.BlockRowList=;self.LabelRowList= #file fw=open(t

9、ext.txt,a) fw.close() hasHead=FALSE f=open(text.txt,r) if f.read(5)=score: hasHead=TRUE f.close() self.file=open(text.txt,r+a) if hasHead=FALSE: self.file.write(score line time scorePtime linePtime scorePline daten) self.file.flush() self.time=1000 self.OnTimer() def _del_(self): #self.file.close()

10、pass def Pause(self,event): self.isPause=1-self.isPause def Up(self,event): BL=self.BlockList;LL=self.LabelList Moveable=TRUE xtotal=0;ytotal=0;count=0 for i in range(HEIGHT): for j in range(WIDTH): if LLij.isactive=ACTIVE: xtotal=xtotal+i;ytotal=ytotal+j;count=count+1 SourceList=;DestList= for i in

11、 range(HEIGHT): for j in range(WIDTH): if LLij.isactive=ACTIVE: x0=(xtotal+ytotal)/count;y0=(ytotal-xtotal )/count xr=(xtotal+ytotal)%count;yr=(ytotal-xtotal)%count x=x0-j;y=y0+i if xr=count/2:x=x+1 if yr=count/2:y=y+1 SourceList.append(i,j);DestList.append(x,y) if x=HEIGHT or y=WIDTH:Moveable=FALSE if x=0 and x=0 and yWIDTH and BLxy=1 and LLxy.isactive=PASSIVE:Moveable=FALSE if Moveable=TRUE: for i in range(len(SourceList): self.Empty(SourceListi0,SourceListi1) for

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号