Game Development Reference
In-Depth Information
DisplayManager also has the responsibility of finding if the puzzle is done, thereby
initiating the end game effect.
Managing pieces—Group
An important class called group is used to manage the pieces that are currently
connected. To begin with, there will be as many groups as there are pieces. So each
group object is instantiated with one piece. Groups may merge when one piece of
a group is connected to a piece from another group. When two groups merge, we
transfer all the pieces from one group to the other and we purge the other group. We
choose the bigger group to transfer the pieces to; if the two groups are of the same size
then we simply pick one. The puzzle is completed when there is only one group left.
The PieceSprite class
The PieceSprite class is the sprite representing a single jigsaw piece. The actual
visual sprite that is seen on the screen is contained ( m_sprite ) in this class. There
will be as many piece sprite instances as there are pieces in the puzzle.
The players may drag around a PieceSprite on the screen. When a piece sprite is
moved and if it is a part of a group with other pieces, we need to take care to move
all the pieces in the group.
Each piece could have four neighboring pieces, except for those in the corners and
edges of the puzzle. The pieces are stored in a two-dimensional array. Given
the number of rows and columns, we could easily figure out the correct
neighboring pieces.
To begin with, the piece sprites are themselves randomly distributed on the screen.
When a piece is moved by the player, we simply check if any of the correctly
matching neighboring pieces are close enough; if so, we trigger the merge.
Search WWH ::




Custom Search