Stacking Up Tetrominoes

  1. 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.
  2. 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.
  3. 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).
  4. When a tetromino stops, call a function update_occupy() to set the cells corresponding to the final location of this tetromino.
  5. 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! Tetrominoes Stack Up