Game Development Reference
In-Depth Information
_timer = new Timer(1000);
_timer.addEventListener(TimerEvent.TIMER,
timerUpdate, false, 0, true);
}
private function addedToStage(e:Event):void {
quitButton.addEventListener(MouseEvent.CLICK,
gameOver, false, 0, true);
}
There are three TextField objects that display the remaining
number of pieces, number of moves that have been made, and the
time that has elapsed, as well as a button the player can use to
quit the game. Each of the private variables stores some piece of
information related to gameplay, including the source image in the
form of an interface (rather than a class). Along with the Game-
Board, we
ll discuss this interface in a subsequent section. The con-
structor sets up the quit button and also creates a Timer object.
The timer will fire every second (or 1000 ms) once started, creating
a very basic clock. Whenever a second passes, the Timer will call
timerUpdate.
'
public function get movesMade():int { return _movesMade; }
public function set movesMade(value:int):void {
_movesMade = value;
movesMadeText.text = String(_movesMade);
}
public function get piecesLeft():int { return _piecesLeft; }
public function set piecesLeft(value:int):void {
_piecesLeft = value;
piecesLeftText.text = String(_piecesLeft);
}
public function get timeElapsed():int { return _timeElapsed; }
public function set timeElapsed(value:int):void {
_timeElapsed = value;
var timeString:String;
if (_timeElapsed
60) {
timeString =
<
"
0:
"
;
} else {
timeString = String(Math.floor(_timeElapsed /
60)) +
"
:
"
;
}
var seconds:int = _timeElapsed % 60;
if (seconds < 10) {
timeString += " 0 " + String(seconds);
} else {
Search Nedrilad ::




Custom Search