13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>The</strong> Tetris game in <strong>wxPython</strong>http://www.zetcode.com/wxpython/thetetrisgame/self.drawSquare(dc, 0 + x * self.squareWidth(),boardTop + (Board.BoardHeight - y - 1) * self.squareHeight(),self.curPiece.shape())def OnKeyDown(self, event):if not self.isStarted or self.curPiece.shape() == Tetrominoes.NoShape:event.Skip()returnkeycode = event.GetKeyCode()if keycode == ord('P') or keycode == ord('p'):self.pause()returnif self.isPaused:returnelif keycode == wx.WXK_LEFT:self.tryMove(self.curPiece, self.curX - 1, self.curY)elif keycode == wx.WXK_RIGHT:self.tryMove(self.curPiece, self.curX + 1, self.curY)elif keycode == wx.WXK_DOWN:self.tryMove(self.curPiece.rotatedRight(), self.curX, self.curY)elif keycode == wx.WXK_UP:self.tryMove(self.curPiece.rotatedLeft(), self.curX, self.curY)elif keycode == wx.WXK_SPACE:self.dropDown()elif keycode == ord('D') or keycode == ord('d'):self.oneLineDown()else:event.Skip()def OnTimer(self, event):if event.GetId() == Board.ID_TIMER:if self.isWaitingAfterLine:self.isWaitingAfterLine = Falseself.newPiece()else:self.oneLineDown()else:event.Skip()def dropDown(self):newY = self.curYwhile newY > 0:if not self.tryMove(self.curPiece, self.curX, newY - 1):breaknewY -= 1self.pieceDropped()def oneLineDown(self):if not self.tryMove(self.curPiece, self.curX, self.curY - 1):self.pieceDropped()def pieceDropped(self):for i in range(4):x = self.curX + self.curPiece.x(i)y = self.curY - self.curPiece.y(i)4 de 12 27/04/2008 1:10

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

Saved successfully!

Ooh no, something went wrong!