Game Development Reference
In-Depth Information
7. Cells of the game ield are stored here. The values correspond to colors of the cells:
public:
int FField[ FWidth ][ FHeight ];
};
How it works…
Shape itting uses simple mask checking and is trivial. We will give more attention to
the neighbor cells calculation. It is based on the recursive lood-ill algorithm ( http://
en.wikipedia.org/wiki/Flood_fill ):
int clBricksField::deleteRegions( int NumRegionsToDelete )
{
int NumRegions = 0;
for ( int j = 0; j != FHeight; j++ )
{
for ( int i = 0 ; i != FWidth ; i++ )
{
if ( FField[i][j] != -1 )
{
Recursively, calculate the number of neighbors to each cell:
int Neighbors = CalcNeighbours( i, j,
FField[i][j] );
Mark the cells if the number of neighbors is high enough:
if ( Neighbors >= NumRegionsToDelete )
{
FillNeighbours( i, j, FField[i][j] );
NumRegions += Neighbours;
}
}
}
}
Remove the marked cells from the ield:
CollapseField();
Return the number of deleted regions. This is used to evaluate the current score:
return NumRegions;
}
 
Search WWH ::




Custom Search