Game Development Reference
In-Depth Information
parameters for init, which include the source image object to be
used for the puzzle, the number of rows and columns the grid
should be divided into, the width and height in pixels of the image
that will be displayed, and the physical position of the GameBoard
object in the form of a point. Only the source image, rows, and col-
umns are required. By default, we will use the native width and
height of the image we
re slicing up and set the board at 0,0. The
total number of pieces for the puzzle is calculated as the number
of rows multiplied by the number of columns. The init function is
also where the GameBoard object is actually created. Most of the
same parameters that were passed into the function are similarly
passed along to the GameBoard constructor, and it is subsequently
added to the Stage. The GameBoard will dispatch a number of
events as things occur in the game, so in startGame, we add listen-
ers for these events. We
ll look at these listeners next.
private function pauseBeforeGameOver(e:Event):void {
setTimeout(gameOver, 2000, null);
private function pieceSwap(e:Event):void {
private function pieceLock(e:Event):void {
piecesLeft −− ;
private function gameOver(e:Event):void {
dispatchEvent(new Event(GAME_OVER));
private function timerUpdate(e:TimerEvent):void {
timeElapsed = _timer.currentCount;
The method pauseBeforeGameOver merely stops gameplay and
inserts a two-second pause before calling the gameOver method, so
that the player has a moment to see the image they completed.
When a piece swap is made, the number of moves is incremented,
and when a piece is locked into its correct position, the number of
pieces is decremented. Finally, after the post-game pause is com-
plete, gameOver deactivates the GameBoard, performs clean up,
and dispatches the GAME_OVER event back up to the MixUp class.
Search Nedrilad ::

Custom Search