Disclaimer: Tetris (R) is property of The Tetris Company, LLC. The proposed implementation is only for teaching purposes.

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.

To get a feeling for the task, it's useful to immerse yourself in it. You should consult harddrop.com, probably watch the Tetris World Championship, and some incredible feats.

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.

The pieces

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 :

The playfield

Also called well, the playfield is usually 10 width by 20 height.




Game start / over