本文整理汇总了Python中shape.Shape.setShape方法的典型用法代码示例。如果您正苦于以下问题:Python Shape.setShape方法的具体用法?Python Shape.setShape怎么用?Python Shape.setShape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shape.Shape
的用法示例。
在下文中一共展示了Shape.setShape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Board
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import setShape [as 别名]
class Board(QtGui.QFrame):
BoardWidth = 10
BoardHeight = 22
Speed = 300
def __init__(self, parent):
QtGui.QFrame.__init__(self, parent)
self.timer = QtCore.QBasicTimer()
self.isWaitingAfterLine = False
self.curPiece = Shape()
self.nextPiece = Shape()
self.curX = 0
self.curY = 0
self.numLinesRemoved = 0
self.board = []
self.setFocusPolicy(QtCore.Qt.StrongFocus)
self.isStarted = False
self.isPaused = False
self.clearBoard()
self.nextPiece.setRandomShape()
def getShapeAt(self, x, y):
return self.board[int((y * Board.BoardWidth) + x)]
def setShapeAt(self, x, y, shape):
self.board[int((y * Board.BoardWidth) + x)] = shape
def getSelWidth(self):
return self.contentsRect().width() / Board.BoardWidth
def getSelHeight(self):
return self.contentsRect().height() / Board.BoardHeight
def start(self):
if self.isPaused:
return
self.isStarted = True
self.isWaitingAfterLine = False
self.numLinesRemoved = 0
self.clearBoard()
self.emit(QtCore.SIGNAL("messageToStatusbar(QString)"), str(self.numLinesRemoved))
self.newPiece()
self.timer.start(Board.Speed, self)
def pause(self):
if not self.isStarted:
return
self.isPaused = not self.isPaused
if self.isPaused:
self.timer.stop()
self.emit(QtCore.SIGNAL("messageToStatusbar(QString)"), "paused")
else:
self.timer.start(Board.Speed, self)
self.emit(QtCore.SIGNAL("messageToStatusbar(QString)"), str(self.numLinesRemoved))
self.update()
def paintEvent(self, event):
painter = QtGui.QPainter(self)
rect = self.contentsRect()
boardTop = rect.bottom() - Board.BoardHeight * self.getSelHeight()
for i in range(Board.BoardHeight):
for j in range(Board.BoardWidth):
shape = self.getShapeAt(j, Board.BoardHeight - i - 1)
if shape != Tetrominoes.NoShape:
self.drawSquare(painter, rect.left() + j * self.getSelWidth(), boardTop + i * self.getSelHeight(), shape)
if self.curPiece.getShape() != Tetrominoes.NoShape:
for i in range(4):
x = self.curX + self.curPiece.getX(i)
y = self.curY - self.curPiece.getY(i)
self.drawSquare(painter, rect.left() + x * self.getSelWidth(), boardTop + (Board.BoardHeight - y - 1) * self.getSelHeight(), self.curPiece.getShape())
def keyPressEvent(self, event):
if not self.isStarted or self.curPiece.getShape() == Tetrominoes.NoShape:
QtGui.QWidget.keyPressEvent(self, event)
return
key = event.key()
if key == QtCore.Qt.Key_P:
self.pause()
return
if self.isPaused:
return
elif key == QtCore.Qt.Key_Left:
self.tryMove(self.curPiece, self.curX - 1, self.curY)
elif key == QtCore.Qt.Key_Right:
self.tryMove(self.curPiece, self.curX + 1, self.curY)
elif key == QtCore.Qt.Key_Down:
self.tryMove(self.curPiece.rotatedRight(), self.curX, self.curY)
elif key == QtCore.Qt.Key_Up:
#.........这里部分代码省略.........