Game Development of .Nettrix: GDI+ and Collision Detection - Diagrams of Basic Game Objects
(Page 9 of 22 )
The Class Diagram: First Draft Start with a simple class diagram (shown in Figure 1-20) illustrating the basic structures of the objects for your game, and then you can add the details and go on refining until you have a complete version. Almost all of the object-oriented analysis methodologies suggest this cyclic approach, and it’s ideal to show how the game idea evolves from draft to a fully featured project.
From this game proposal you can see the first two classes: Block, which will represent each game piece, and Square, the basic component of the blocks.

Figure 1-20. The class diagram—first draft
Based on the game proposal, you can determine some methods (functions) and properties (variables) for the Block class, as described in Table 1-1.
Table 1-1. The Block Class Members
TYPE | NAME | DESCRIPTION |
|---|
Method | Down | Makes the block go down on the screen |
| Method | Right | Moves the block right |
| Method | Left | Moves the block left |
| Method | Rotate | Rotates the block clockwise |
| Property | Square 1 | Specifies one of the squares that compose the block |
| Property | Square 2 | Specifies one of the squares that compose the block |
| Property | Square 3 | Specifies one of the squares that compose the block |
| Property | Square 4 | Specifies one of the squares that compose the block |
Each block is composed of fours objects from the Square class, described in Table 1-2.
Table 1-2. The Square Class Members
| TYPE | NAME | DESCRIPTION |
|---|
| Method | Show | Draws the square on the screen at its coordinates (Location property) and with its size (Size property),colored with a specific color (ForeColor property) and filled with BackColor |
| | |
| | |
| | |
| Method | Hide | Erases the square from the screen |
| Property | ForeColor | Specifies the square’s foreground color |
| Property | BackColor | Specifies the square’s background color |
| Property | Location | Specifies the x,y position of the square on the screen |
| Property | Size | Specifies the height and width of the square |
Comparing the two tables, you can see that there are methods to show and hide the square. Because the squares will be drawn from the Block object, you must have corresponding methods in the Block class and the corresponding properties, too. You can adjust the first diagram accordingly to produce Figure 1-21.

Figure 1-21. The class diagram---second draft
You use SquareSize as the size property for the block, since it’s not important to know the block size, but the block must know the size of the squares so that it can create them.
You can return to this diagram later and adjust it if necessary. Now turn your attention to the game engine, described in the next section.
This chapter is from Beginning .NET Game Programming in C#, by David Weller, et al., (Apress, 2004, ISBN: 1590593197). Check it out at your favorite bookstore today.
Buy this book now. |
Next: The Game Engine >>
More .NET Articles
More By Apress Publishing