This is a classic game of Tetris. The game was build from scratch and represents the most basic variation of Tetris. Tetris consists of seven shapes, each formed out of four blocks.
The player can move the shapes left and right using the left and right arrows on keyboard, they can speed up falling by pressing or holding the down arrow button, and they can also rotate the shape by pressing the up arrow button. When the player fills one line, the line gets destroyed and all the blocks above the line move one row down.
How it works: each shape is represented with a set of 2D schemas (arrays), one for each rotation of the shape. The number of schemas per shape vary; the “O” shape, for example, only has one schema, while the “L” shape has four. There is only one shape moving at a time and each position is determined according to the coordinates of the top left corner of its schema.
I used multi-threading to enable the player to pause and resume the game.
After the core functionality was implemented, a friend of mine also added a nice welcome screen and some music to the game.
This project can be found here.