/* Game Class -- Tetris * This is a container which holds the grid and the current piece * and conrols game play. It relay commands to and from those members. * * Tetris is a fascinating game that involves aligning pieces composed * of 4 squares into solid rows, which are then removed. The objective * is to see how many solid rows you can make. */ #include "grid.h" #include "piece.h" // Game -- controls the grid and piece class Game { public: // no default constructor as a display is needed for graphics // constructor Game(GP142Display *display, Grid *grid); // draw the grid and piece on the display void Draw(); // move the current piece in direction d (usually down) void MovePiece(Direction d); // rotate the piece clockwise void RotatePiece(); // if the piece can no longer move down, // we make it part of the grid and remove it. // generate a new piece if needed void UpdatePiece(); // check for and remove completely filled in rows void CheckRows(); // returns true if a piece occupies the same // space as some part of the grid // (usually happens when a new piece is made, signifies game is over) bool IsGameOver() const; private: // Generate a random new piece and return a pointer to it. Piece *NewPiece() const; // returns an int, 0<= int <= 6 int RandomNumber() const; GP142Display *display; // all graphics are done on display Grid *grid; // what pieces have already been dropped Piece *piece; // current piece that is dropping };