Tetris (7)
- Modify your previous TETRIS program
and define a class CTetromino.
-
A tetromino has the following data members:
- unsigned short type_id; // [0..6]
- unsigned short pos_x;
- unsigned short pos_y;
- A tetromino has the following member functions:
- The constructor CTetromino() will be invoked with three parameters to
initialize data members type_id, pos_x, and pos_y.
- The default values of these three parameters are all 0.
- Draw() - display the tetromino at position (pos_y, pos_x).
Test your class with this main program.
Save your class definition as "tetris.h". Save the main program as
"tetris-7a.cpp". Compile the program with
"g++ tetris-7a.cpp -lcurses".
The program should produce output as follows.
- Add a member function Move(). It has a parameter to indicate the
direction of movement.
- In this version, we shall only invoke with the
argument "down", while in the next version we'll add the handling of
"left" and "right".
- When the Move() function is called with argument "down", the
data member pos_y of tetromino will increment by 1, unless it
reaches the bottom border.
- If pos_y successfully increments, this function returns 1.
If it fails, the return value is 0.
Test your class with this main program.
The program should produce output as follows.