The GameGrid class

Finally, the GameGrid class is quite simple. It keeps track of the squares on the game board. The gridArea field is the portion of the total client area that is occupied by the grid:

GameGrid.h

const int Rows = 20, Cols = 10;  
 
class GameGrid { 
  public: 
    GameGrid(Rect gridArea); 
    void ClearGameGrid(); 
 
    Color* operator[](int row) {return gameGrid[row];} 
    void InvalidateSquare(Window* windowPtr, int row, 
                          int col, Size offsetSize); 
    void DrawGameGrid(Graphics& graphics, bool inverse) const; 



    void DrawSquare(Graphics& graphics, int row, int col, 
                    Color penColor, Color brushColor, 
                    Size offsetSize = ZeroSize) const; 
 
    Rect GridArea() const {return gridArea;} 
 
  private: 
    Rect gridArea; 
    Color gameGrid[Rows][Cols]; 
}; 

When called by the TetrisWindow ...

Get C++ Windows Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.