Game Development Reference
In-Depth Information
Figure 3-9. Correct letters chosen and placed in empty boxes
After the loop, you remove the button's text object from the stage to indicate that this letter is no longer available
to choose from. If you made it through the loop with no matches, you subtract the player's lives and update the
livesTxt text object.
At this point, your checkGame function is called to check on the player's progress. If the player got all of the letters,
win is set to true and gameOver is called. Similarly, if the player is out of lives, win is set to false and gameOver is fired.
If the game is declared over after checking on the game's progress, you end the game by calling the gameOver
function to determine the game's outcome (see Listing 3-19).
Listing 3-19. wordGame.js - gameOver Function for Winning or Losing the Game
function gameOver() {
stage.removeAllChildren();
var msg = win ? "YOU WIN!" : "YOU LOSE";
gameOverTxt = new createjs.Text(msg, "36px Arial");
gameOverTxt.alpha = 0;
gameOverTxt.color = win ? 'blue' : 'red';
gameOverTxt.textAlign = 'center';
gameOverTxt.textBaseline = 'middle';
gameOverTxt.x = stage.canvas.width / 2;
gameOverTxt.y = stage.canvas.height / 2;
stage.addChild(gameOverTxt);
createjs.Tween.get(gameOverTxt).to({alpha:1},1000);
}
This final game logic function is used to handle the end of the game, whether the player wins or loses. All display
objects can easily be removed by calling removeAllChildren on the stage. A message string is then created, based
 
Search WWH ::




Custom Search