【Python】用Python实现一个俄罗斯方块游戏
俄罗斯方块游戏,使用Python实现,总共有350+行代码,实现了俄罗斯方块游戏的基本功能,同时会记录所花费时间,消去的总行数,所得的总分,还包括一个排行榜,可以查看最高记录。
排行榜中包含一系列的统计功能,如单位时间消去的行数,单位时间得分等。
附源码:
from Tkinter import *
from tkMessageBox import *
import random
import time
#俄罗斯方块界面的高度
HEIGHT = 18
#俄罗斯方块界面的宽度
WIDTH = 10
ACTIVE = 1
PASSIVE = 0
TRUE = 1
FALSE = 0
root=Tk();root.title('Russia')
class App(Frame):
def __init__(self,master):
Frame.__init__(self)
master.bind('<Up>',self.Up)
master.bind('<Left>',self.Left)
master.bind('<Right>',self.Right)
master.bind('<Down>',self.Down)
#master.bind('<Down>',self.Space)
master.bind('<space>',self.Space)
master.bind('<Control-Shift-Key-F12>',self.Play)
master.bind('<Key-F6>',self.Pause)
self.backg="#%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='Score: ',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=WIDTH+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)
相关文档:
Python中字符串被定义为引号之间的字符集合。Python支持使用成对的单引号或双引号,三引号包含的字符串。
使用索引操作符([])和切片操作符([:])可以得到子字符串。字符串有其特有的索引规则:第一个字符的索引是0
,最后一个字符的索引是-1。
加号(+)用于字符串连接运算,星号(*)则用于字符串重复。如下例:
pystr = " ......
http://blog.csdn.net/myan/archive/2008/01/07/2028545.aspx
http://blog.csdn.net/gashero/archive/2007/06/03/1636030.aspx
我感觉还是python应用更广一些,Ruby的RoR做Web框架好一些吧,至于perl,现在感觉实在有几分苦涩…… ......
int main()
{
int a[] = {1,2,3,4,5};
int i;
int * p = a;
for (p = a + 4, i = 0; i < 5; i++) {
printf("%d ",p[-i]);
}
return 0;
}
......
import sys, pygame, time
size = width, height = 700,700
fontColor = (0,0,255)
class walk:
'''This is a game about war.
Just like war 3.'''
def __init__(self):
'''Init the screen.
Get param and init the screen'''
#print ('this is init funnction') ......
#!/usr/bin/python
#coding=utf-8
import Image,ImageDraw,ImageFont,os,string,random,ImageFilter
def initChars():
"""
允许的字符集合,初始集合为数字、大小写字母
usage: initChars()
param: None
return: list
返回允许的字符集和
for: picChecker类初始字符集合
todo: ......