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/self.curPiece = newPieceself.curX = newXself.curY = newYself.Refresh()return Truedef drawSquare(self, dc, x, y, shape):colors = ['#000000', '#CC6666', '#66CC66', '#6666CC','#CCCC66', '#CC66CC', '#66CCCC', '#DAAA00']light = ['#000000', '#F89FAB', '#79FC79', '#7979FC','#FCFC79', '#FC79FC', '#79FCFC', '#FCC600']dark = ['#000000', '#803C3B', '#3B803B', '#3B3B80','#80803B', '#803B80', '#3B8080', '#806200']pen = wx.Pen(light[shape])pen.SetCap(wx.CAP_PROJECTING)dc.SetPen(pen)dc.DrawLine(x, y + self.squareHeight() - 1, x, y)dc.DrawLine(x, y, x + self.squareWidth() - 1, y)darkpen = wx.Pen(dark[shape])darkpen.SetCap(wx.CAP_PROJECTING)dc.SetPen(darkpen)dc.DrawLine(x + 1, y + self.squareHeight() - 1,x + self.squareWidth() - 1, y + self.squareHeight() - 1)dc.DrawLine(x + self.squareWidth() - 1,y + self.squareHeight() - 1, x + self.squareWidth() - 1, y + 1)dc.SetPen(wx.TRANSPARENT_PEN)dc.SetBrush(wx.Brush(colors[shape]))dc.DrawRectangle(x + 1, y + 1, self.squareWidth() - 2,self.squareHeight() - 2)class Tetrominoes(object):NoShape = 0ZShape = 1SShape = 2LineShape = 3TShape = 4SquareShape = 5LShape = 6MirroredLShape = 7class Shape(object):coordsTable = (((0, 0), (0, 0), (0, 0), (0, 0)),((0, -1), (0, 0), (-1, 0), (-1, 1)),((0, -1), (0, 0), (1, 0), (1, 1)),((0, -1), (0, 0), (0, 1), (0, 2)),((-1, 0), (0, 0), (1, 0), (0, 1)),((0, 0), (1, 0), (0, 1), (1, 1)),((-1, -1), (0, -1), (0, 0), (0, 1)),((1, -1), (0, -1), (0, 0), (0, 1)))6 de 12 27/04/2008 1:10

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

Saved successfully!

Ooh no, something went wrong!