- GUI
- Windows API tutorial
- Introduction to Windows API
- Windows API main functions
- System functions in Windows API
- Strings in Windows API
- Date & time in Windows API
- A window in Windows API
- First steps in UI
- Windows API menus
- Windows API dialogs
- Windows API controls I
- Windows API controls II
- Windows API controls III
- Advanced controls in Windows API
- Custom controls in Windows API
- The GDI in Windows API
- PyQt4 tutorial
- PyQt5 tutorial
- Qt4 tutorial
- Introduction to Qt4 toolkit
- Qt4 utility classes
- Strings in Qt4
- Date and time in Qt4
- Working with files and directories in Qt4
- First programs in Qt4
- Menus and toolbars in Qt4
- Layout management in Qt4
- Events and signals in Qt4
- Qt4 Widgets
- Qt4 Widgets II
- Painting in Qt4
- Custom widget in Qt4
- The Breakout game in Qt4
- Qt5 tutorial
- Introduction to Qt5 toolkit
- Strings in Qt5
- Date and time in Qt5
- Containers in Qt5
- Working with files and directories in Qt5
- First programs in Qt5
- Menus and toolbars in Qt5
- Layout management in Qt5
- Events and signals in Qt5
- Qt5 Widgets
- Qt5 Widgets II
- Painting in Qt5
- Custom widget in Qt5
- Snake in Qt5
- The Breakout game in Qt5
- PySide tutorial
- Tkinter tutorial
- Tcl/Tk tutorial
- Qt Quick tutorial
- Java Swing tutorial
- JavaFX tutorial
- Java SWT tutorial
- wxWidgets tutorial
- Introduction to wxWidgets
- wxWidgets helper classes
- First programs in wxWidgets
- Menus and toolbars in wxWidgets
- Layout management in wxWidgets
- Events in wxWidgets
- Dialogs in wxWidgets
- wxWidgets widgets
- wxWidgets widgets II
- Drag and Drop in wxWidgets
- Device Contexts in wxWidgets
- Custom widgets in wxWidgets
- The Tetris game in wxWidgets
- wxPython tutorial
- Introduction to wxPython
- First Steps
- Menus and toolbars
- Layout management in wxPython
- Events in wxPython
- wxPython dialogs
- Widgets
- Advanced widgets in wxPython
- Drag and drop in wxPython
- Internationalisation
- Application skeletons in wxPython
- The GDI
- Mapping modes
- Creating custom widgets
- Tips and Tricks
- wxPython Gripts
- The Tetris game in wxPython
- C# Winforms Mono tutorial
- Java Gnome tutorial
- Introduction to Java Gnome
- First steps in Java Gnome
- Layout management in Java Gnome
- Layout management II in Java Gnome
- Menus in Java Gnome
- Toolbars in Java Gnome
- Events in Java Gnome
- Widgets in Java Gnome
- Widgets II in Java Gnome
- Advanced widgets in Java Gnome
- Dialogs in Java Gnome
- Pango in Java Gnome
- Drawing with Cairo in Java Gnome
- Drawing with Cairo II
- Nibbles in Java Gnome
- QtJambi tutorial
- GTK+ tutorial
- Ruby GTK tutorial
- GTK# tutorial
- Visual Basic GTK# tutorial
- PyGTK tutorial
- Introduction to PyGTK
- First steps in PyGTK
- Layout management in PyGTK
- Menus in PyGTK
- Toolbars in PyGTK
- Signals & events in PyGTK
- Widgets in PyGTK
- Widgets II in PyGTK
- Advanced widgets in PyGTK
- Dialogs in PyGTK
- Pango
- Pango II
- Drawing with Cairo in PyGTK
- Drawing with Cairo II
- Snake game in PyGTK
- Custom widget in PyGTK
- PHP GTK tutorial
- C# Qyoto tutorial
- Ruby Qt tutorial
- Visual Basic Qyoto tutorial
- Mono IronPython Winforms tutorial
- Introduction
- First steps in IronPython Mono Winforms
- Layout management
- Menus and toolbars
- Basic Controls in Mono Winforms
- Basic Controls II in Mono Winforms
- Advanced Controls in Mono Winforms
- Dialogs
- Drag & drop in Mono Winforms
- Painting
- Painting II in IronPython Mono Winforms
- Snake in IronPython Mono Winforms
- The Tetris game in IronPython Mono Winforms
- FreeBASIC GTK tutorial
- Jython Swing tutorial
- JRuby Swing tutorial
- Visual Basic Winforms tutorial
- JavaScript GTK tutorial
- Ruby HTTPClient tutorial
- Ruby Faraday tutorial
- Ruby Net::HTTP tutorial
- Java 2D games tutorial
- Java 2D tutorial
- Cairo graphics tutorial
- PyCairo tutorial
- HTML5 canvas tutorial
- Python tutorial
- Python language
- Interactive Python
- Python lexical structure
- Python data types
- Strings in Python
- Python lists
- Python dictionaries
- Python operators
- Keywords in Python
- Functions in Python
- Files in Python
- Object-oriented programming in Python
- Modules
- Packages in Python
- Exceptions in Python
- Iterators and Generators
- Introspection in Python
- Ruby tutorial
- PHP tutorial
- Visual Basic tutorial
- Visual Basic
- Visual Basic lexical structure
- Basics
- Visual Basic data types
- Strings in Visual Basic
- Operators
- Flow control
- Visual Basic arrays
- Procedures & functions in Visual Basic
- Organizing code in Visual Basic
- Object-oriented programming
- Object-oriented programming II in Visual Basic
- Collections in Visual Basic
- Input & output
- Tcl tutorial
- C# tutorial
- Java tutorial
- AWK tutorial
- Jetty tutorial
- Tomcat Derby tutorial
- Jtwig tutorial
- Android tutorial
- Introduction to Android development
- First Android application
- Android Button widgets
- Android Intents
- Layout management in Android
- Android Spinner widget
- SeekBar widget
- Android ProgressBar widget
- Android ListView widget
- Android Pickers
- Android menus
- Dialogs
- Drawing in Android
- Java EE 5 tutorials
- Introduction
- Installing Java
- Installing NetBeans 6
- Java Application Servers
- Resin CGIServlet
- JavaServer Pages, (JSPs)
- Implicit objects in JSPs
- Shopping cart
- JSP & MySQL Database
- Java Servlets
- Sending email in a Servlet
- Creating a captcha in a Servlet
- DataSource & DriverManager
- Java Beans
- Custom JSP tags
- Object relational mapping with iBATIS
- Jsoup tutorial
- MySQL tutorial
- MySQL quick tutorial
- MySQL storage engines
- MySQL data types
- Creating, altering and dropping tables in MySQL
- MySQL expressions
- Inserting, updating, and deleting data in MySQL
- The SELECT statement in MySQL
- MySQL subqueries
- MySQL constraints
- Exporting and importing data in MySQL
- Joining tables in MySQL
- MySQL functions
- Views in MySQL
- Transactions in MySQL
- MySQL stored routines
- MySQL Python tutorial
- MySQL Perl tutorial
- MySQL C API programming tutorial
- MySQL Visual Basic tutorial
- MySQL PHP tutorial
- MySQL Java tutorial
- MySQL Ruby tutorial
- MySQL C# tutorial
- SQLite tutorial
- SQLite C tutorial
- SQLite PHP tutorial
- SQLite Python tutorial
- SQLite Perl tutorial
- SQLite Ruby tutorial
- SQLite C# tutorial
- SQLite Visual Basic tutorial
- PostgreSQL C tutorial
- PostgreSQL Python tutorial
- PostgreSQL Ruby tutorial
- PostgreSQL PHP tutorial
- PostgreSQL Java tutorial
- Apache Derby tutorial
- SQLAlchemy tutorial
- MongoDB PHP tutorial
- MongoDB Java tutorial
- MongoDB JavaScript tutorial
- MongoDB Ruby tutorial
- Spring JdbcTemplate tutorial
- JDBI tutorial
The Tetris game in IronPython Mono Winforms
The tetris game is one of the most popular computer games ever created. The original game was designed and programmed by a Russian programmer Alexey Pajitnov in 1985. Since then, Tetris is available on almost every computer platform in lots of variations. Even my mobile phone has a modified version of the tetris game.
Tetris is called a falling block puzzle game. In this game, we have seven different shapes called tetrominoes. S-shape, Z-shape, T-shape, L-shape, Line-shape, MirroredL-shape and a Square-shape. Each of these shapes is formed with four squares. The shapes are falling down the board. The object of the tetris game is to move and rotate the shapes, so that they fit as much as possible. If we manage to form a row, the row is destroyed and we score. We play the tetris game until we top out.

The development
We do not have images for our tetris game, we draw the tetrominoes using the drawing API available in the Winforms library. Behind every computer game, there is a mathematical model. So it is in tetris.
Some ideas behind the game.
- We use
Timer
to create a game cycle - The tetrominoes are drawn
- The shapes move on a square by square basis (not pixel by pixel)
- Mathematically a board is a simple list of numbers
The following example is a modified version of the Tetris game, available with PyQt4 installation files.
tetris.py
#!/usr/bin/ipy import clr clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") clr.AddReference("System") from System.Windows.Forms import Application, Form, FormBorderStyle from System.Windows.Forms import UserControl, Keys, Timer, StatusBar from System.Drawing import Size, Color, SolidBrush, Pen from System.Drawing.Drawing2D import LineCap from System.ComponentModel import Container from System import Random class Tetrominoes(object): NoShape = 0 ZShape = 1 SShape = 2 LineShape = 3 TShape = 4 SquareShape = 5 LShape = 6 MirroredLShape = 7 class Board(UserControl): BoardWidth = 10 BoardHeight = 22 Speed = 200 ID_TIMER = 1 def __init__(self): self.Text = 'Snake' self.components = Container() self.isWaitingAfterLine = False self.curPiece = Shape() self.nextPiece = Shape() self.curX = 0 self.curY = 0 self.numLinesRemoved = 0 self.board = [] self.DoubleBuffered = True self.isStarted = False self.isPaused = False self.timer = Timer(self.components) self.timer.Enabled = True self.timer.Interval = Board.Speed self.timer.Tick += self.OnTick self.Paint += self.OnPaint self.KeyUp += self.OnKeyUp self.ClearBoard() def ShapeAt(self, x, y): return self.board[(y * Board.BoardWidth) + x] def SetShapeAt(self, x, y, shape): self.board[(y * Board.BoardWidth) + x] = shape def SquareWidth(self): return self.ClientSize.Width / Board.BoardWidth def SquareHeight(self): return self.ClientSize.Height / Board.BoardHeight def Start(self): if self.isPaused: return self.isStarted = True self.isWaitingAfterLine = False self.numLinesRemoved = 0 self.ClearBoard() self.NewPiece() def Pause(self): if not self.isStarted: return self.isPaused = not self.isPaused statusbar = self.Parent.statusbar if self.isPaused: self.timer.Stop() statusbar.Text = 'paused' else: self.timer.Start() statusbar.Text = 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): g = event.Graphics size = self.ClientSize boardTop = size.Height - 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(g, 0 + j * self.SquareWidth(), boardTop + i * self.SquareHeight(), shape) if self.curPiece.GetShape() != Tetrominoes.NoShape: for i in range(4): x = self.curX + self.curPiece.x(i) y = self.curY - self.curPiece.y(i) self.DrawSquare(g, 0 + x * self.SquareWidth(), boardTop + (Board.BoardHeight - y - 1) * self.SquareHeight(), self.curPiece.GetShape()) g.Dispose() def OnKeyUp(self, event): if not self.isStarted or self.curPiece.GetShape() == Tetrominoes.NoShape: return key = event.KeyCode if key == Keys.P: self.Pause() return if self.isPaused: return elif key == Keys.Left: self.TryMove(self.curPiece, self.curX - 1, self.curY) elif key == Keys.Right: self.TryMove(self.curPiece, self.curX + 1, self.curY) elif key == Keys.Down: self.TryMove(self.curPiece.RotatedRight(), self.curX, self.curY) elif key == Keys.Up: self.TryMove(self.curPiece.RotatedLeft(), self.curX, self.curY) elif key == Keys.Space: self.DropDown() elif key == Keys.D: self.OneLineDown() def OnTick(self, sender, event): if self.isWaitingAfterLine: self.isWaitingAfterLine = False self.NewPiece() else: self.OneLineDown() def DropDown(self): newY = self.curY while newY > 0: if not self.TryMove(self.curPiece, self.curX, newY - 1): break newY -= 1 self.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) self.SetShapeAt(x, y, self.curPiece.GetShape()) self.RemoveFullLines() if not self.isWaitingAfterLine: self.NewPiece() def RemoveFullLines(self): numFullLines = 0 statusbar = self.Parent.statusbar rowsToRemove = [] for i in range(Board.BoardHeight): n = 0 for j in range(Board.BoardWidth): if not self.ShapeAt(j, i) == Tetrominoes.NoShape: n = n + 1 if 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)) numFullLines = numFullLines + len(rowsToRemove) if numFullLines > 0: self.numLinesRemoved = self.numLinesRemoved + numFullLines statusbar.Text = str(self.numLinesRemoved) self.isWaitingAfterLine = True self.curPiece.SetShape(Tetrominoes.NoShape) self.Refresh() def NewPiece(self): self.curPiece = self.nextPiece statusbar = self.Parent.statusbar self.nextPiece.SetRandomShape() self.curX = Board.BoardWidth / 2 + 1 self.curY = Board.BoardHeight - 1 + self.curPiece.MinY() if not self.TryMove(self.curPiece, self.curX, self.curY): self.curPiece.SetShape(Tetrominoes.NoShape) self.timer.Stop() self.isStarted = False statusbar.Text = 'Game over' def TryMove(self, newPiece, newX, newY): for i in range(4): x = newX + newPiece.x(i) y = newY - newPiece.y(i) if x < 0 or x >= Board.BoardWidth or y < 0 or y >= Board.BoardHeight: return False if self.ShapeAt(x, y) != Tetrominoes.NoShape: return False self.curPiece = newPiece self.curX = newX self.curY = newY self.Refresh() return True def DrawSquare(self, g, x, y, shape): colors = [ (0, 0, 0), (204, 102, 102), (102, 204, 102), (102, 102, 204), (204, 204, 102), (204, 102, 204), (102, 204, 204), (218, 170, 0) ] light = [ (0, 0, 0), (248, 159, 171), (121, 252, 121), (121, 121, 252), (252, 252, 121), (252, 121, 252), (121, 252, 252), (252, 198, 0) ] dark = [ (0, 0, 0), (128, 59, 59), (59, 128, 59), (59, 59, 128), (128, 128, 59), (128, 59, 128), (59, 128, 128), (128, 98, 0) ] pen = Pen(Color.FromArgb(light[shape][0], light[shape][1], light[shape][2]), 1) pen.StartCap = LineCap.Flat pen.EndCap = LineCap.Flat g.DrawLine(pen, x, y + self.SquareHeight() - 1, x, y) g.DrawLine(pen, x, y, x + self.SquareWidth() - 1, y) darkpen = Pen(Color.FromArgb(dark[shape][0], dark[shape][1], dark[shape][2]), 1) darkpen.StartCap = LineCap.Flat darkpen.EndCap = LineCap.Flat g.DrawLine(darkpen, x + 1, y + self.SquareHeight() - 1, x + self.SquareWidth() - 1, y + self.SquareHeight() - 1) g.DrawLine(darkpen, x + self.SquareWidth() - 1, y + self.SquareHeight() - 1, x + self.SquareWidth() - 1, y + 1) g.FillRectangle(SolidBrush(Color.FromArgb(colors[shape][0], colors[shape][1], colors[shape][2])), x + 1, y + 1, self.SquareWidth() - 1, self.SquareHeight() - 2) pen.Dispose() darkpen.Dispose() class 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)) ) def __init__(self): self.coords = [[0,0] for i in range(4)] self.pieceShape = Tetrominoes.NoShape self.SetShape(Tetrominoes.NoShape) def GetShape(self): return self.pieceShape def SetShape(self, shape): table = Shape.coordsTable[shape] for i in range(4): for j in range(2): self.coords[i][j] = table[i][j] self.pieceShape = shape def SetRandomShape(self): rand = Random() self.SetShape(rand.Next(1, 7)) def x(self, index): return self.coords[index][0] def y(self, index): return self.coords[index][1] def SetX(self, index, x): self.coords[index][0] = x def SetY(self, index, y): self.coords[index][1] = y def MaxX(self): m = self.coords[0][0] for i in range(4): m = max(m, self.coords[i][0]) return m def MinY(self): m = self.coords[0][1] for i in range(4): m = min(m, self.coords[i][1]) return m def RotatedLeft(self): if self.pieceShape == Tetrominoes.SquareShape: return self result = Shape() result.pieceShape = self.pieceShape for i in range(4): result.SetX(i, self.y(i)) result.SetY(i, -self.x(i)) return result def RotatedRight(self): if self.pieceShape == Tetrominoes.SquareShape: return self result = Shape() result.pieceShape = self.pieceShape for i in range(4): result.SetX(i, -self.y(i)) result.SetY(i, self.x(i)) return result class IForm(Form): def __init__(self): self.Text = 'Tetris' self.Width = 200 self.Height = 430 self.FormBorderStyle = FormBorderStyle.FixedSingle board = Board() board.Width = 195 board.Height = 380 self.Controls.Add(board) self.statusbar = StatusBar() self.statusbar.Parent = self self.statusbar.Text = 'Ready' board.Start() self.CenterToScreen() Application.Run(IForm())
I have simplified the game a bit, so that it is easier to understand. The game starts immediately, after it is launched. We can pause the game by pressing the p key. The space key will drop the tetris piece immediately to the bottom. The d key will drop the piece one line down. (It can be used to speed up the falling a bit.) The game goes at constant speed, no acceleration is implemented. The score is the number of lines that we have removed.
class Tetrominoes(object): NoShape = 0 ZShape = 1 SShape = 2 LineShape = 3 TShape = 4 SquareShape = 5 LShape = 6 MirroredLShape = 7
There are seven different types of tetrominoes.
... self.curX = 0 self.curY = 0 self.numLinesRemoved = 0 self.board = [] ...
Before we start the game cycle, we initialize some important variables. The self.board
variable is a list of Tetrominoes
. It represents the position of various shapes and remains of the shapes on the board.
def ClearBoard(self): for i in range(Board.BoardHeight * Board.BoardWidth): self.board.append(Tetrominoes.NoShape)
The ClearBoard()
method clears the board. It fills the self.board
variable with Tetrominoes.NoShape
values.
Painting in the tetris game is done in the OnPaint()
method.
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(g, 0 + j * self.squareWidth(), boardTop + i * self.squareHeight(), shape)
The painting of the game is divided into two steps. In the first step, we draw all the shapes, or remains of the shapes that have been dropped to the bottom of the board. All the squares are rememberd in the self.board
list. We access it using the ShapeAt()
method.
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) self.drawSquare(g, 0 + x * self.squareWidth(), boardTop + (Board.BoardHeight - y - 1) * self.squareHeight(), self.curPiece.shape())
The next step is drawing of the actual piece that is falling down.
In the OnKeyUp()
method we check for pressed keys.
elif key == Keys.Left: self.tryMove(self.curPiece, self.curX - 1, self.curY)
If we press the left arrow key, we try to move the piece to the left. We say try, because the piece might not be able to move.
In the TryMove()
method we try to move our shapes. If we cannot move the piece, we return False.
for i in range(4): x = newX + newPiece.x(i) y = newY - newPiece.y(i) if x < 0 or x >= Board.BoardWidth or y < 0 or y >= Board.BoardHeight: return False if self.ShapeAt(x, y) != Tetrominoes.NoShape: return False
If the shape is at the edge of the board or is adjacent to some other piece, we return False.
self.curPiece = newPiece self.curX = newX self.curY = newY self.Refresh() return True
Otherwise we place the current falling piece to a new position and return True.
def OnTick(self, sender, event): if self.isWaitingAfterLine: self.isWaitingAfterLine = False self.NewPiece() else: self.OneLineDown()
In the OnTick()
method we either create a new piece, after the previous one hit the bottom, or we move a falling piece one line down.
If the piece hits the bottom, we call the RemoveFullLines()
method. First we find out all full lines.
rowsToRemove = [] for i in range(Board.BoardHeight): n = 0 for j in range(Board.BoardWidth): if not self.ShapeAt(j, i) == Tetrominoes.NoShape: n = n + 1 if n == 10: rowsToRemove.append(i)
We cycle throught the board. A row can have ten pieces of shapes. If the row is full, e.g. n is equal to 10, we store the line number for later removal.
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))
These code lines remove the full lines. We reverse the order of the rowsToRemove
list so that we begin with the bottom most full line. What we do is remove a full line by placing all lines about it one line down. This happens for all full lines In our case we use a naive gravity. This means that the pieces may be lef floating above empty gaps.
def NewPiece(self): self.curPiece = self.nextPiece statusbar = self.Parent.statusbar self.nextPiece.SetRandomShape() self.curX = Board.BoardWidth / 2 + 1 self.curY = Board.BoardHeight - 1 + self.curPiece.MinY() if not self.TryMove(self.curPiece, self.curX, self.curY): self.curPiece.SetShape(Tetrominoes.NoShape) self.timer.Stop() self.isStarted = False statusbar.Text = 'Game over'
The NewPiece()
method creates randomly a new tetris piece. If the piece cannot go into its initial position, e.g. the TryMove()
method returns False, the game is over.
colors = [ (0, 0, 0), (204, 102, 102), ... ] light = [ (0, 0, 0), (248, 159, 171), ... ] dark = [ (0, 0, 0), (128, 59, 59), ... ]
There are three lists of colours. The colours
list stores color values for the fills of the squares. Each of seven pieces has its own color. The light
and the dark
store colours for lines that will make the square look 3D. These colours are the same, just are lighter and darker. We will draw two lines with light colour to the top and left sides of the squares and two lines with darker colour to the right and bottom sides.
g.DrawLine(pen, x, y + self.SquareHeight() - 1, x, y) g.DrawLine(pen, x, y, x + self.SquareWidth() - 1, y)
These two lines draw the light lines for a square.
The Shape
class saves information about the tetris piece.
self.coords = [[0,0] for i in range(4)]
Upon creation we create an empty coordinates list. The list will save the coordinates of the tetris piece. For example, these tuples (0, -1), (0, 0), (1, 0), (1, 1) represent a rotated S-shape. The following diagram illustrates the shape.

When we draw the current falling piece, we draw it at self.curX
, self.curY
position. Then we look at the coordinates table and draw all the four squares.
The RotateLeft()
method rotates a piece to the left.
if self.pieceShape == Tetrominoes.SquareShape: return self
If we have the Tetrominoes.SquareShape
piece, we do nothing. This shape is always the same.
result = Shape() result.pieceShape = self.pieceShape for i in range(4): result.SetX(i, self.y(i)) result.SetY(i, -self.x(i)) return result
In other cases, we change coordinates of the piece. To understand this code, look at the above figure.

This was Tetris game in IronPython Winforms.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论