// Grid Class #ifndef GRID_H #define GRID_H // Tetris Grid Class // This class displays the grid that the blocks move in. // It removes completely full rows. #include "gp142display.h" class Piece; // for circular dependencies const int TETRIS = 4; // 4 squares per piece const int FILL = 0; // used to fill in something drawn on the screen const int GRID_WIDTH = 10; // number of squares wide const int GRID_HEIGHT = 20; // number of squares tall const int SQUARE_WIDTH = 20; // width of a grid square in pixels const int SQUARE_HEIGHT = 20; // heigth of a grid square in pixels const int GRID_LEFT = -100; // pixel position of left edge of grid const int GRID_BOTTOM = -175; // pixel position of bottom edge of grid const GP142Color EMPTY_SQUARE = White; // grid square is considered empty if it has color white // Grid -- maintains which squares are occupied // by pieces which have already dropped class Grid { public: // constructor Grid(GP142Display *display); // draw the grid to the screen including // boundary box and occupied squares void Draw(); // true if grid[x][y] is not empty bool IsSet(int x, int y) const; // set the grid (x,y) to color void Set(int x, int y, GP142Color color); // check for and remove all solid rows of squares // if a solid row is found, all rows above it // are moved down and the top row set to empty void CheckRows(); private: // colors of squares occupied by frozen pieces // (unoccupied squares are EMPTY_SQUARE color) // grid[x][y] is displayed as solid square of colored pixels // // lower-left is (0,0) and upper-right is (GRID_WIDTH-1, GRID_HEIGHT-1) // given point (x,y) left of it is (x-1,y), below it is (x,y-1) GP142Color grid[GRID_WIDTH][GRID_HEIGHT]; GP142Display *display; // screen to draw things onto }; #endif