Game Development Reference
In-Depth Information
ejep$%7
lh]u=c]ej>qppkj*naikraArajpHeopajan$IkqoaArajp*?HE?G( ±
kjLh]u=c]ej>qppkj?he_g%7
y
The first directive is a call to the ejep method, which initializes all the elements of the game to their
starting values and assigns the random mystery number. Calling it again from the end of the game
completely resets the game. A new mystery number is also randomly chosen. Hey, it's a new game;
you can play again!
You can see in this example why it made sense to move all the initialization directives into the ejep
method. Whenever you want to reset the game, all you have to do is call it from anywhere in the
program.
The final directive removes the event listener from the lh]u=c]ej>qppkj:
lh]u=c]ej>qppkj*naikraArajpHeopajan$IkqoaArajp*?HE?G( ±
kjLh]u=c]ej>qppkj?he_g%7
It's a good idea to remove event listeners from objects whenever you aren't using them. If you don't,
the Flash Player still runs them in the background. The Play Again button's one and only function is to
reset the game, and once that job is over, it's no longer needed. So as odd as it may seem, its next duty
is this somewhat paradoxical and semisuicidal directive: to remove its own event listener. You don't
need it until the button makes its next appearance at the end of the game, so you might as well get
rid of it. Its listener will be reassigned to it the next time the game ends.
Seeing the final code
Hey, that's amazing, the game is done! Just in case you need to double-check something, here's what
the final code of the game looks like:
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
r]n_qnnajpCqaoo6qejp7
r]ncqaooaoNai]ejejc6qejp7
r]ncqaooaoI]`a6qejp7
r]nc]iaOp]pqo6Opnejc7
r]nc]iaSkj6>kkha]j7
lq^he_bqj_pekjI]ej$%
w
ejep$%7
y
 
Search Nedrilad ::




Custom Search