Rotate a Tetromino

  1. Modify CTetromino::Move() to consider the case when it receives an argument "rotate". Add a case in the switch state to handle rotations.
  2. In each tetromino, one square is chosen as the "center", which is represented by (dy,dx) = (0,0). The location of this square will not be changed after the rotation.
  3. For other tetrominoes, if the relative location to the center is (dy,dx), then
    1. After rotating 180 degrees counterclockwise, the relative location becomes (-dy, -dx).
    2. After rotating 90 degrees counterclockwise, the relative location becomes (-dx, dy)
    3. After rotating 270 degrees counterclockwise, the relative location becomes ( dx, -dy)
  4. In general, after roating θ degrees counterclockwise, the relative location becomes
    [
    cosθ -sinθ
    sinθ cosθ
    ] ☓ [
    dy
    dx
    ].
  5. Add a private data member "rotation" to your CTetromino class. When rotation=i, it represents that the tetromino has rotated 90*i degrees counterclockwise.
    1. In the constructor, always set rotation = 0.
    2. In CTetromino::Move(), simply increment rotation by 1. This is pretty simple.
    3. In CTetromino::Draw() and CTetromino::Erase(), you need to consider the value of rotation to draw/erase the tetromino correctly.
    4. You also need to modify update_occupy() and detect_confliction().
  6. You may test your new class with the following main program, which simply adds these lines:
    case KEY_UP:
    case 'k':
        a.Move(ROTATE);
        break;