Managing the game field logic
Now we know how to store different shapes and render them. Let's implement some game logic to make these shapes interact with each other on a game field.
Getting ready
Refer to the Writing the match-3 game recipe to see how the game field is rendered.
How to do it…
The interface of
clBricksField
looks as follows:class clBricksField { public:
The size of our game field is
11×22
:static const int FWidth = 11; static const int FHeight = 22; public: void clearField()
The methods to check if the figure fits freely into a position are as follows:
bool figureFits( int x, int y, const clBricksShape& fig ) bool figureWillHitNextTurn( int x, int y, const clBricksShape& fig )
This method stamps the shape into the specified position of the game field:
void addFigure( int x, int y, const clBricksShape& fig )
The following code is the main game logic. Methods to calculate and delete same-colored cell regions:
int deleteLines(); int CalcNeighbours( int...