Game Development Reference
In-Depth Information
The recursive lood-ill is straightforward. The following code calculates the number of
adjacent cells:
intclBricksField::CalcNeighbours( int i, int j, int Col )
{
if ( i < 0 || j < 0 || i >= FWidth ||
j >= FHeight || FField[i][j] != Col ) return 0;
FField[i][j] = -1;
int Result = 1 + CalcNeighbours( i + 1, j + 0, Col ) +
CalcNeighbours( i - 1, j + 0, Col ) +
CalcNeighbours( i + 0, j + 1, Col ) +
CalcNeighbours( i + 0, j - 1, Col );
FField[i][j] = Col;
return Result;
}
The following code marks the adjacent cells:
void clBricksField::FillNeighbours( int i, int j, int Col )
{
if ( i < 0 || j < 0 || i >= FWidth ||
j >= FHeight || FField[i][j] != Col ) { return; }
FField[i][j] = -1;
FillNeighbours( i + 1, j + 0, Col );
FillNeighbours( i - 1, j + 0, Col );
FillNeighbours( i + 0, j + 1, Col );
FillNeighbours( i + 0, j - 1, Col );
}
There's moreā€¦
There is also another variant of game logic implemented in this project. Check out the method
deleteLines() in the ile game/Field.h to learn how to implement it.
Implementing user interaction within a
game loop
In the previous recipes we learned how to render the game environment and implement
the game logic. One more important aspect of the development needs our attention:
the user interaction.
Getting ready
Check out the ile main.cpp in the project 1_Game for the full implementation.
 
Search WWH ::




Custom Search