![]() |
Block types in tetris |
To make the tetris game, we first make a two dimensional array. An element in this integer array is a single block (one of the four blocks in each block type) in the game. We set all the elements to zero initially to show that the matrix is empty. We may call each element a cell. So to represent a Z block, we need four cells. In the matrix, to represent a falling block (eg: a Z block) we set corresponding elements' values to 1. We move these 1's in the 2d integer array downwards to simulate falling. Then when it reaches bottom, these 1's are changed to 2's. This is to denote that these cell cannot be moved further. Again, we start another random block from the top (first row).