Game Development Reference
In-Depth Information
Managing the game ield 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 ield.
Getting ready
Refer to the Writing the match-3 game recipe to see how the game ield is rendered.
How to do it…
1.
The interface of clBricksField looks as follows:
class clBricksField
{
public:
2. The size of our game ield is 11×22 :
static const int FWidth = 11;
static const int FHeight = 22;
public:
void clearField()
3. The methods to check if the igure its 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 )
4. This method stamps the shape into the speciied position of the game ield:
void addFigure( int x, int y, const clBricksShape& fig )
5.
The following code is the main game logic. Methods to calculate and delete
same-colored cell regions:
int deleteLines();
int CalcNeighbours( int i, int j, int Col );
void FillNeighbours( int i, int j, int Col );
6.
Since we are making a match-3 game, we pass the value of 3 to this method.
However, the logic is general; you can play with your own values to tweak
the gameplay:
int deleteRegions( int NumRegionsToDelete );
void collapseField();
 
Search WWH ::




Custom Search