First, let's review the Tetris rules (just in case):
- There is a grid with a height of 16 blocks and a width of 10 blocks.
- You have seven different
tetrimino
(a tetris piece) that are all composed of four blocks. - A new
tetrimino
appears at the top of the game's grid every time the previous one cannot descend any more (because the block below is already occupied or because you've reached the game's floor). - The game is over when a new
tetrimino
cannot appear anymore (because there is already a tetrimino at the top of the grid). - Every time a line is full (all blocks are occupied by a
tetrimino
part), it disappears and all lines above descend by one line.
Now that we all agree on the game rules, let's see how to actually write those mechanisms.
First, we need to actually create those tetrimino
s.