Introducing the Critter Program

Like most of the examples in this book, the main program for this chapter has little practical merit but is entertaining. You’ll build a virtual pet named a critter. The critter is very simple, but as you see in Figures 4.1 through 4.5, it’s fun to interact with.

Figure 4.1. Introducing your critter. Go ahead and talk to it!


Figure 4.2. The critter tells you about itself.


Figure 4.3. After talking for a while, the critter becomes melancholy.


Figure 4.4. Without appropriate attention, the critter becomes angry.


Figure 4.5. The cost of neglect can be a sad and lifeless critter. Fortunately, with enough food and love, it can be revived.


I used simple rules to drive the critter’s behavior. During each turn, the critter ages and becomes hungrier and a little more unhappy. Whenever you talk to the critter, it gives you a message based on its current happiness level. If the critter is hungry, it becomes unhappy even more quickly. Playing with and feeding the critter make it happier. That’s all there is to the design of the critter, but to create the program, I relied on OOP techniques. The critter is actually an object, and it can talk, eat, play, and age.

Another interesting feature of the Critter program is the use of a simple menu. Many console-based programs use a menu, so now you’ll learn how to build one.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.245.140