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).
- Note: You should re-use the
draw_block()
function defined in the previous exercise.
(Certainly, you need to slightly modify it to become a member
function of the CTetromino class.)
This will greatly simplify your task.
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
- CL /c tetris-7a.cpp /I.
- LINK tetris-7a.obj wincursor.obj pdcurses.lib
Running the program tetris-7a.exe 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.
(For example, when it reaches the bottom border, then invoking
Move(DOWN)
will return 0.)
Test your class with this main program.
The program should produce output as follows.