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/return self.board[(y * Board.BoardWidth) + x]def setShapeAt(self, x, y, shape):self.board[(y * Board.BoardWidth) + x] = shapedef squareWidth(self):return self.GetClientSize().GetWidth() / Board.BoardWidthdef squareHeight(self):return self.GetClientSize().GetHeight() / Board.BoardHeightdef start(self):if self.isPaused:returnself.isStarted = Trueself.isWaitingAfterLine = Falseself.numLinesRemoved = 0self.clearBoard()self.newPiece()self.timer.Start(Board.Speed)def pause(self):if not self.isStarted:returnself.isPaused = not self.isPausedstatusbar = self.GetParent().statusbarif self.isPaused:self.timer.Stop()statusbar.SetStatusText('paused')else:self.timer.Start(Board.Speed)statusbar.SetStatusText(str(self.numLinesRemoved))self.Refresh()def clearBoard(self):for i in range(Board.BoardHeight * Board.BoardWidth):self.board.append(Tetrominoes.NoShape)def OnPaint(self, event):dc = wx.PaintDC(self)size = self.GetClientSize()boardTop = size.GetHeight() - Board.BoardHeight * self.squareHeight()for i in range(Board.BoardHeight):for j in range(Board.BoardWidth):shape = self.shapeAt(j, Board.BoardHeight - i - 1)if shape != Tetrominoes.NoShape:self.drawSquare(dc,0 + j * self.squareWidth(),boardTop + i * self.squareHeight(), shape)if self.curPiece.shape() != Tetrominoes.NoShape:for i in range(4):x = self.curX + self.curPiece.x(i)y = self.curY - self.curPiece.y(i)3 de 12 27/04/2008 1:10

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

Saved successfully!

Ooh no, something went wrong!