Tetris (8)
- Modify your previous TETRIS program
so that you can move a tetromino to left or right while it is falling
down.
- After a tetromino is constructed, automatically invoke
Draw()
to
display it.
- In
Move()
, invoke Erase()
before the position of the tetromino is
modifed, and invoke Draw()
after the position is modified.
- 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++.
- In
Move()
, add statements to handle the cases when it is called
with argument "LEFT" or "RIGHT".
- LEFT - decrement pos_x by 1, if it does not exceed the left
border.
- RIGHT - increment pos_x by 1, if it does not exceed the right
border.
- 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.
- 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.