Game Development Reference
In-Depth Information
6.
The state of the game is presented by an array of tiles, which is stored in the
clPuzzle class:
class clPuzzle
{
public:
mutable std::vector<clTile> FTiles;
int FColumns, FRows;
bool FMovingImage;
int FClickedI, FClickedJ;
float FOfsX, FOfsY;
clPuzzle()
: FMovingImage( false )
, FClickedI( -1 ), FClickedJ( -1 )
, FOfsX( 0.0f ), FOfsY( 0.0f )
{
Retoss( 4, 4 );
}
...
7.
Swap the two tiles speciied by their (i,j) 2D coordinates:
void SwapTiles( int i1, int j1, int i2, int j2 )
{
std::swap( FTiles[j1 * FColumns + i1],
FTiles[j2 * FColumns + i2] );
}
};
8.
The game is complete if all the tiles are in their places. To check if the tile is in place,
we need to compare its FOriginX and FOriginY coordinates to its current i and j
coordinates:
bool clPuzzle::IsComplete() const
{
for ( int i = 0; i != FColumns; i++ )
{
for ( int j = 0; j != FRows; j++ )
{
clTile* T = GetTile( i, j );
if ( T->FOriginX != i || T->FOriginY != j)
return false;
}
}
return true;
}
 
Search WWH ::




Custom Search