< Previous | Contents | Next >

Planning the Game

The core of the game is the critter itself. Therefore, I first plan my Critter class. Because I want the critter to have independent hunger and boredom levels, I know that the class will have private data members for those.


n m_Hunger

n m_Boredom


The critter should also have a mood, directly based on its hunger and boredom levels. My first thought was to have a private data member, but a critters mood is really a calculated value based on its hunger and boredom. Instead, I decided to have a private member function that calculates a critters mood on the fly, based on its current hunger and boredom levels:


n GetMood()


Next, I think about public member functions. I want the critter to be able to tell the player how its feeling. I also want the player to be able to feed and play with the critter to reduce its hunger and boredom levels. I need three public member functions to accomplish each of these tasks.


n Talk() n Eat() n Play()

Finally, I want another member function that simulates the passage of time, to make the critter a little more hungry and bored:


n PassTime()


I see this member function as private because it will only be called by other member functions, such as Talk(), Eat(), or Play().

The class will also have a constructor to initialize data members. Take a look at Figure 8.6, which models the Critter class. I preface each data member and

276 Chapter 8 n Classes: Critter Caretaker


member function with a symbol to indicate its access level; I use + for public and

for private.


image

Figure 8.6

Model for the Critter class.