Create the code file ‘enumerations’ in ‘Tetris parts/definitions’. Add two enumerations that will be useful in your project. Firstly, there is the block type. Tetris has square blocks, T-blocks and so on. A list might look like this:
enum BLOCK_TYPE
{
BT_SQUARE ,
BT_T ,
5 BT_L ,
BT_BACKWARDS_L,
BT_STRAIGHT ,
BT_S ,
BT_BACKWARDS_S,
10 BT_NUM , // number of block types used in the game
BT_BACKGROUND , // special case, only for background
BT_WALL ,
}
The last three values deserve extra attention. The value ‘BT_NUM’ is useful because the number which represents that value is equal to the highest value + 1. This makes it easy to use a random function. Since the result of a random function does not include the maximum value, we will be able to use this kind of code later on in our application:
blockType type = Random(BT_NUM);
So why is BT_NUM not the last value in the list? Well, the last two values are special cases. There will be special squares to draw the background and the borders of the game. And the color of such a square is determined by the block type. Because we do not want to use those types in the actual game, BT _NUM is but before these values.
A second enumeration is used to determine the possible directions in which a block can move. A block can not upwards, only to the left, the right, or down. Blocks which are already down, do not have a direction anymore.
enum DIRECTION
{
D_LEFT ,
D_RIGHT,
5 D_DOWN ,
D_NONE ,
}