Tetris (8)

  1. Modify your previous TETRIS program so that you can move a tetromino to left or right while it is falling down.
  2. After a tetromino is constructed, automatically invoke Draw() to display it.
  3. In Move(), invoke Erase() before the position of the tetromino is modifed, and invoke Draw() after the position is modified.
  4. From now on, you don't need to worry about how to draw/erase your tetrominoes on the screen. You simply call its member function Move(), and it knows how to handle the details to draw/erase by itself. This is the beauty of Encapsulation in C++.
  5. In Move(), add statements to handle the cases when it is called with argument "LEFT" or "RIGHT".
    1. LEFT - decrement pos_x by 1, if it does not exceed the left border.
    2. RIGHT - increment pos_x by 1, if it does not exceed the right border.
  6. You may test your class with this main program. In addition to KEY_LEFT and KEY_RIGHT, the program also recognizes the key 'q' to quit the program. The program should produce output as follows.
    tetris-8.png
  7. Note that your program still has no idea about the previous tetrominoes, so it will always fall down to the bottom border, instead of stacking upon existing tetrominoes. We shall enhance this in the next exercise.
    tetris-8b.png