Stacking Up Tetrominoes
- If you want tetrominoes in
your TETRIS program
being able to stack up, there must be some way for them to know existing
tetrominoes which have fallen down. To do this, a static data member is a
perfect candidate because static members are shared among all objects
of the same class.
- You may define a private array "bool occupied[nHeight][nWidth]", in
which each element indicates a cell in the playing field is occupied or
not. Natually, nHeight = nBottomBorder - nTopBorder -1, while nWidth =
nRightBorder - nLeftBorder - 1.
- Modify CTetromino::Move() so that when a tetromino is moving
downward, it stops when any of its squares encounters a existing square
beneath it (occupied[i][j] == true).
- Hint: You may design a supporting function detect_confliction()
to check this.
- When a tetromino stops, call a function update_occupy()
to set the cells corresponding to the final location of this tetromino.
- Now tetrominoes should be able to stack up as below.
If a newly constructed tetromino detects that its position has
already been occupied by previous tetrominoes, the game is over!