1 import sys
2 import random
3 from PyQt4 import QtCore, QtGui
4 class Tetris(QtGui.QMainWindow):
5 def __init__(self):
6 QtGui.QMainWindow.__init__(self)
7 self.setGeometry(300, 300, 180, 380)
8 self.setWindowTitle('Tetris')
9 self.tetrisboard = Board(self)
10 self.setCentralWidget(self.tetrisboard)
11 self.statusbar = self.statusBar()
12 self.connect(self.tetrisboard, QtCore.SIGNAL("messageToStatusbar(QString)"),
13 self.statusbar, QtCore.SLOT("showMessage(QString)"))
14 self.tetrisboard.start()
15 self.center()
16 def center(self):
17 screen = QtGui.QDesktopWidget().screenGeometry()
18 size = self.geometry()
19 self.move((screen.width()-size.width())/2,
20 (screen.height()-size.height())/2)
21 class Board(QtGui.QFrame):
22 BoardWidth = 10
23 BoardHeight = 22
24 Speed = 300
25 def __init__(self, parent):
26 QtGui.QFrame.__init__(self, parent)
27 self.timer = QtCore.QBasicTimer()
28 self.isWaitingAfterLine = False
29 self.curPiece = Shape()
30 self.nextPiece = Shape()
31 self.curX = 0
32 self.curY = 0
33 self.numLinesRemoved = 0
34 self.board = []
35 self.setFocusPolicy(QtCore.Qt.StrongFocus)
36 self.isStarted = False
37 self.isPaused = False
38 self.clearBoard()
39 self.nextPiece.setRandomShape()