// Piece class // JMC Oct 2000 // this file should not need to be modified #ifndef PIECE_H #define PIECE_H // Piece -- Main Object that moves on screen #include "grid.h" #include "square.h" // how much of a complete rotation is the piece // from its starting position enum Position {FULL, QUARTER, HALF, THREE_QUARTER}; // Piece -- dropping Tetris object // this class cannot be instatiated, as it contains // a pure virtual function. Derived classes are // created that correspond to the different // Tetris shapes class Piece { public: // constructor Piece(); // display piece on screen virtual void Draw(); // move piece in direction d if possible // freeze the piece if it can't move down anymore virtual void Move(Direction d); // true if the piece could move in direction d virtual bool canMove(Direction d) const; // returns squares[i] virtual Square getSquare(int i) const; // returns color of the piece virtual GP142Color getColor() const; // rotate the piece a quarter turn counter clockwise from its current position // must be implemented by a derived class // A piece will rotate only if the squares it // would move into are empty and it wouldn't // move outside the boundaries of the grid virtual void Rotate() = 0; private: bool ableToMove; // = true if the piece has not landed on // another part of the grid, so it can still move protected: Square squares[TETRIS]; // every Tetris piece is made up of squares GP142Color color; // color displayed for the piece Position currentPosition; // how much of a complete rotation has occurred GP142Display *display; // screen to draw piece on Grid *grid; // grid which contains occupied squares }; #endif