Introducing the Snowball Fight

With surprisingly little work, you can use objects to model complex behavior. In this chapter you will make a model of a snowball fight. Each player is an object, and the menu system is a third object. Figures 5.1, 5.2, and 5.3 illustrate the snowball fight in progress.

Figure 5.1. Begin by entering the player names, which are important for the play-by-play description of the game.


Figure 5.2. Players have a limited number of snowballs and are more likely to hit their target when they are close to it.


Figure 5.3. With a good strategy, you can beat the computer much of the time, but not always.


The design of the snowball fight is simple. Both the player and the opponent are custom classes that have a lot in common. They have three properties: name, snowballs, and strength. Each player starts with three snowballs and, to win, has to make more during the fight. Each player also begins with three lives. When a player has been hit three times, that player loses the fight. The computer opponent is like the human player but has features that enable it to automatically play against the user.

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

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