- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 197字
- 2021-08-20 15:50:37
Classes used in Flood Control
While it would certainly be possible to simply pile all of the game code into the Game1
class, the result would be difficult to read and manage later on. Instead, we need to consider how to logically divide the game into classes that can manage themselves and help to organize our code.
A good rule of thumb is that a class should represent a single thing or type of thing. If you can say, This object is made up of these other objects, or, This object contains these objects, consider creating classes to represent those relationships.
The Flood Control game contains a game board made up of 80 pipe pieces. We can abstract these pipes as a class called GamePiece
and provide it with the code it needs to handle rotation, and provide the code that will display the piece with a rectangle that can be used to pull the sprite off the sprite sheet.
The game board itself can be represented by a GameBoard
class, which will handle managing individual GamePiece
objects and be responsible for determining which pieces should be filled with water and which ones should be left empty.