Game Development Reference
Keep this in mind whenever you decide what type to declare your variables.
Figure 5-17. Declare variables as int if you need to
use negative values.
Winning and losing
The game now has enough information about what the player is doing to figure out whether the game
has been won or lost. All you need to do now is to find a way to say, “Hey, the game is over!” and tell
players how well they did.
To do this, add the following to the program:
A >kkha]j (true/false) variable called c]iaSkj that is set to pnqa if the game has been won and
b]hoa if it hasn't.
A method called _da_gC]iaKran that checks to see whether the player has enough guesses
remaining to continue playing.
A method called aj`C]ia that tells players whether they've won or lost.
An important aspect of this next bit of code is that it shows you an example of how you can use meth-
ods to help you modularize your code. In general terms, modular programming is way of breaking
down complex bits of code into smaller manageable pieces, or modules . Modules can really be any
pieces of code, such as classes or methods, which perform one specific helpful function. Have a look
at the two new methods added in the following code and see if you can figure out how they're used
to modularize the program.
1. Add the following code in bold text to your program: