The classical game Tetris is one of the most basic game you can make. In its original version, the game was displayed on a terminal.
In this tutorial we will model the game's structure using the command line for debugging. Then we can simply add real time graphics on top.
Finally, you should definitely have a look at Tetris Effect. It's one of the most beautiful piece of software art ever made.
To learn the rules in detail, check the Tetris Guideline.
Pieces are generated randomly. It's possible to use a special rule to spawn certain pieces when they don't come out (especially the long bar, necessary for tetris).
There are special for rotation, allowing certain advanced tricks like wall kicks. Here we only implement the basics though.
The 7 pieces:
L - 3x3
J - 3x3
Z - 3x3
S - 3x3
O - 2x2
T - 3x3
I - 4x4
Pieces are choosen at random, with some special rules to avoid situations where some pieces (like the long bar) don't drop for a time. It's not a strict requirement.
The random number generator is xor shift defined as :
Also called well, the playfield is usually 10 width by 20 height.