13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>The</strong> Tetris game in <strong>wxPython</strong>http://www.zetcode.com/wxpython/thetetrisgame/def OnTimer(self, event):if event.GetId() == Board.ID_TIMER:if self.isWaitingAfterLine:self.isWaitingAfterLine = Falseself.newPiece()else:self.oneLineDown()else:event.Skip()In the OnTimer() method we either create a new piece, after theprevious one was dropped to the bottom, or we move a falling pieceone line down.def removeFullLines(self):numFullLines = 0rowsToRemove = []for i in range(Board.BoardHeight):n = 0for j in range(Board.BoardWidth):if not self.shapeAt(j, i) == Tetrominoes.NoShape:n = n + 1if n == 10:rowsToRemove.append(i)rowsToRemove.reverse()for m in rowsToRemove:for k in range(m, Board.BoardHeight):for l in range(Board.BoardWidth):self.setShapeAt(l, k, self.shapeAt(l, k + 1))...If the piece hits the bottom, we call the removeFullLines() method.First we find out all full lines. And we remove them. We do it bymoving all lines above the current full line to be removed one linedown. Notice, that we reverse the order of the lines to be removed.Otherwise, it would not work correctly. In our case we use a naivegravity. This means, that the pieces may be floating above emptygaps.10 de 12 27/04/2008 1:10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!