Game Development Reference
In-Depth Information
game.addEventListener(Game.GAME_OVER, gameOver, false,
0, true);
}
protected function gameOver(e:Event):void {
var history:GameHistory = new GameHistory(true, e.target.
timeElapsed, e.target.movesMade);
history.formattedTime = e.target.timeElapsedText.text;
gameHistory.unshift(history);
gotoAndStop(FRAME_RESULTS);
}
protected function setupResults(e:Event):void {
results.addEventListener(Results.PLAY_AGAIN, playGame,
false, 0, true);
results.addEventListener(Results.MAIN_MENU, mainMenu,
false, 0, true);
}
These three methods follow much the same pattern of doing
initialization, when a frame label is reached. The setupGame method
runs functions on the game object and adds a listener for the
GAME_OVER event. We
'
ll return to the gameOver method, later,
once we
ve progressed through the game logic that will get us there.
Suffice it to say that we
'
smostrecent
game in the history array. Now that the document class is defined,
we
'
ll store stats about the player
'
'
re ready to delve into each of the individual screens.
The Title Class
Mostgameshavesomesortofmainmenuofoptions;fewdrop
you directly into the action without explanation or pause. In this
example, we have only two options on the title screen, which keeps
it simple for explanation. A player can choose to start a game or
first view the rules.
public class Title extends MovieClip {
static public const PLAY_GAME:String =
"
playGame
"
;
static public const SHOW_RULES:String =
"
showRules
"
;
public var playButton:SimpleButton;
public var rulesButton:SimpleButton;
public function Title() {
addEventListener(Event.ADDED_TO_STAGE, addedToStage,
false, 0, true);
}
Search Nedrilad ::




Custom Search