Game Development Reference
In-Depth Information
The other advantage is that if you make it a habit of creating an ejep method for every class you cre-
ate, you'll always know how to reset the objects to their default settings.
Did the spaceship you were flying in your latest galactic-shooter game get blown to smithereens? No
problem; just call the ol]_aodel class's ejep method with a line of code that might look like this:
ol]_aodel*ejep$%7
Did the frog in your road-crossing game get squashed by a car? No problem; you can easily reconsti-
tute it and place it safely back on the sidewalk by writing some code that might look like this:
bnkc*ejep$%7
A little later in the design of the number guessing game, you'll see how useful moving all the games
initialization directives into a specialized ejep method can be. For now, just realize that when the pro-
gram runs, it automatically calls the I]ej constructor method. I]ej, in turn, makes a method call to
the ejep method, which runs whatever directives it contains.
Learning more about variables
The first job is to initialize some of the basic variables that you need in the game. The most important
is the mystery number that the player has to guess. You'll also initialize the first message that the
player receives in the output text field. Both of these values are assigned using variables. To see this in
action, follow these steps:
1. Enter the following text in bold to your program. (Delete the pn]_a method that you added to
the ejep function definition in the preceding steps.)
l]_g]ca
w
eilknpbh]od*`eolh]u*Ikrea?hel7
eilknpbh]od*arajpo*IkqoaArajp7
lq^he__h]ooI]ejatpaj`oIkrea?hel
w
r]nop]npIaoo]ca6Opnejc7
r]niuopanuJqi^an6qejp7
lq^he_bqj_pekjI]ej$%
w
ejep$%7
y
bqj_pekjejep$%6rke`
w
++Ejepe]hevar]ne]^hao
op]npIaoo]ca9E]ipdejgejckb]jqi^an^apsaaj-]j`-,,7
iuopanuJqi^an91,7
 
Search Nedrilad ::




Custom Search