HTML and CSS Reference
In-Depth Information
Figure 6.10. Game Over screen with a second chance at life. Letting users easily try again allows them to continue
playing without a page refresh.
Step 4: Create a Game Over screen
With a Welcome screen in place, users can seamlessly play until their ball disappears.
When the ball is gone, you'll throw up a Game Over screen by adding a
Screen . gameover() method with the following snippet. You don't need to call
Screen.gameover() in your code, because it was placed in Ball.draw() .
var Screen = {
gameover : function () {
this . text = 'Game Over' ;
this . textSub = 'Click To Retry' ;
this . textColor = 'red' ;
this . create ();
You also need to add code for another listener placed earlier called
Game.restartGame() . On a click event, that listener fires to the following snippet to
reset the game to its initial setup state. You'll need to add Game.restartGame() as a
new method to Game for it to work:
var Game = {
restartGame : function () {
Search WWH ::

Custom Search