Managing shapes
In the previous recipe, we learned how to render the game screen. Some classes remained unimplemented. In this recipe, we will implement the clBricksShape
class responsible for the storage and manipulation of each of the shapes that appear in the game.
Getting ready
Take a look at how many different pentomino shapes can exist. Wikipedia provides a comprehensive overview: http://en.wikipedia.org/wiki/Pentomino.
How to do it…
The interface of our
clBricksShape
class looks as follows:class clBricksShape { public:
The size of shapes used in our game. We use
5x5
shapes.static const int FWidth = SHAPES_X; static const int FHeight = SHAPES_Y;
Store the colors of the cells this shape consists of. The colors are stored as indices:
private: int FColor[NUM_COLORS];
The figure index defines the shape type:
int FFigureIndex;
The rotation index corresponds to the rotation angle of the figure:
0
,1
,2
, and3
stand for0
,90
,180
, and270
degrees:int FRotationIndex;
The methods are very...