PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/view/GameChrome.as

https://github.com/fogAndWhisky/TestCodeRepo
ActionScript | 708 lines | 423 code | 113 blank | 172 comment | 23 complexity | 1b9d3088ec07f95b16ba8d6f40b9c096 MD5 | raw file
  1. /**
  2. * The skin for the game. Includes some items which are "controller" and not strictly "viewer".
  3. *
  4. * Viewer elements:
  5. * - Game logo
  6. * - Stats board
  7. * - Help and info windows
  8. *
  9. * Controller elements
  10. * - Play/Pause button
  11. * - Help button
  12. * - Learn button
  13. *
  14. * The chrome also defines a "game mask" available through the static method GameChrome.getGameMask().
  15. * This allows other game elements, such as the game viewer or game controller, to access the mask
  16. * and use it to mask themselves.
  17. */
  18. package view
  19. {
  20. import assetLib.ColorLib;
  21. import assetLib.ResourceStrings;
  22. import assetLib.SoundLib;
  23. import controller.GameButton;
  24. import controller.InfoButton;
  25. import controller.MultiStateButton;
  26. import events.GameEvent;
  27. import events.LevelEvent;
  28. import flash.display.Bitmap;
  29. import flash.display.SimpleButton;
  30. import flash.display.Sprite;
  31. import flash.events.Event;
  32. import flash.events.MouseEvent;
  33. import flash.geom.Point;
  34. import flash.geom.Rectangle;
  35. import flash.media.Sound;
  36. import flash.media.SoundMixer;
  37. import flash.media.SoundTransform;
  38. import model.LevelStats;
  39. public class GameChrome extends Sprite
  40. {
  41. /************
  42. * Static properties
  43. ************/
  44. /** Reference to the rect which defines the play area */
  45. public static var _playField:Rectangle;
  46. /************
  47. * Private consts
  48. ************/
  49. /** Unit for spacing out game elements */
  50. private const SPACER:uint = 20;
  51. /* Colors for chrome */
  52. private const playButtonColor:uint = ColorLib.PARTICLE_4;
  53. private const helpButtonColor:uint = ColorLib.PARTICLE_3;
  54. private const learnButtonColor:uint = ColorLib.PARTICLE_5;
  55. private const overButtonColor:uint = ColorLib.PARTICLE_2;
  56. private const downButtonColor:uint = ColorLib.PARTICLE_3;
  57. /** Time in MS before auto-dismissing a notification */
  58. private const autoDismissMS:uint = 4000;
  59. /** ID for the Play state of the play/pause button */
  60. private const PLAY:uint = 0;
  61. /** ID for the Pause state of the play/pause button */
  62. private const PAUSE:uint = 1;
  63. /** Embedded PNG representing the game logo */
  64. [Embed(source="images/boson-logo2.png")]
  65. private var Logo:Class;
  66. /** Embedded PNG representing the Sound On icon */
  67. [Embed(source="images/soundOnIcon.png")]
  68. private var SoundOnIcon:Class;
  69. /** Embedded PNG representing the Sound Off icon */
  70. [Embed(source="images/soundOffIcon.png")]
  71. private var SoundOffIcon:Class;
  72. /** Instance of the embedded Logo PNG */
  73. private var logo:Bitmap;
  74. /** Instance of board with all player stats */
  75. private var statsBoard:StatsBoard;
  76. /* Game buttons */
  77. private var learnBtn:GameButton;
  78. private var helpBtn:GameButton;
  79. private var playPauseBtn:MultiStateButton;
  80. private var soundBtn:MultiStateButton;
  81. /** The background */
  82. private var gameBG:Sprite;
  83. /** List of alerts (info and help boxes) */
  84. private var alerts:Array;
  85. /**
  86. * Constructor
  87. *
  88. * @param playField The rectangle defining the play area
  89. */
  90. public function GameChrome(playField:Rectangle)
  91. {
  92. super();
  93. _playField = playField;
  94. var left:Number = playField.x + playField.width + SPACER;
  95. var top:Number = playField.y;
  96. var bottom:Number = playField.y + playField.height;
  97. logo = new Logo();
  98. logo.x = left;
  99. logo.y = top;
  100. addChild(logo);
  101. createPlayPauseBtn();
  102. createSoundBtn();
  103. learnBtn = new GameButton(ResourceStrings.LEARN, learnButtonColor, overButtonColor, downButtonColor);
  104. learnBtn.x = left;
  105. learnBtn.y = playPauseBtn.y - (learnBtn.height + SPACER);
  106. helpBtn = new GameButton(ResourceStrings.HELP, helpButtonColor, overButtonColor, downButtonColor);
  107. helpBtn.x = left;
  108. helpBtn.y = learnBtn.y - (helpBtn.height + SPACER);
  109. addChild(helpBtn);
  110. addChild(learnBtn);
  111. helpBtn.addEventListener(MouseEvent.CLICK, onHelp);
  112. learnBtn.addEventListener(MouseEvent.CLICK, onHelp);
  113. statsBoard = new StatsBoard(logo.width, 275);
  114. statsBoard.x = left;
  115. statsBoard.y = logo.y + logo.height + SPACER;
  116. addChild(statsBoard);
  117. alerts = new Array();
  118. newInfo(ResourceStrings.WELCOME);
  119. }
  120. /**
  121. * Generate a clone of the game background.
  122. *
  123. * Static so easily accessible across the app.
  124. *
  125. * @return A sprite whose shape perfectly matches the game background
  126. */
  127. public static function getGameMask():Sprite
  128. {
  129. var sprite:Sprite = new Sprite();
  130. sprite.graphics.beginFill(ColorLib.GAME_FIELD, 1);
  131. sprite.graphics.drawRoundRectComplex(_playField.x, _playField.y,
  132. _playField.width, _playField.height,
  133. 15, 5, 5, 15);
  134. sprite.graphics.endFill();
  135. return sprite;
  136. }
  137. /**
  138. * Reset any readouts to initial conditions
  139. *
  140. * @param isFullReset Set to true if resetting a complete game. Use false to reset just
  141. * the current level.
  142. */
  143. public function reset(isFullReset:Boolean):void
  144. {
  145. if (isFullReset)
  146. {
  147. statsBoard.reset();
  148. }
  149. }
  150. /**
  151. * Refresh for a new level
  152. *
  153. * @param isDemo Flag to indicate this is a demo.
  154. * @param level The level number
  155. * @param count The number of particles on this level
  156. * @param bombs The number of bombs the user has
  157. * @param success The number of particles to destroy to win on this level
  158. * @param isReplay (optional) If true, user is re-playing this level. Default is false.
  159. */
  160. public function initLevel(isDemo:Boolean, level:uint, count:uint, bombs:uint,
  161. success:uint, isReplay:Boolean = false):void
  162. {
  163. if (!isDemo)
  164. {
  165. var msg:String;
  166. if (isReplay)
  167. msg = ResourceStrings.INSTRUCTIONS_REPLAY;
  168. else
  169. msg = ResourceStrings["INSTRUCTIONS_CALL_TO_ARMS" + String(level)];
  170. msg += ResourceStrings.LEVEL + String(level) + "!<br /><br />";
  171. var instructions:Array = ResourceStrings.INSTUCTIONS.split("XX");
  172. msg += instructions[0] + bombs + instructions[1] + String(success) + instructions[2] +
  173. String(count) + instructions[3] + "<br /><br />";
  174. msg += ResourceStrings.WARNING;
  175. newInfo(msg, true);
  176. statsBoard.alpha = 1;
  177. }
  178. else
  179. {
  180. statsBoard.alpha = .75;
  181. }
  182. statsBoard.charges = bombs;
  183. statsBoard.resetForNewLevel();
  184. statsBoard.updateStats(0, success, count);
  185. }
  186. /**
  187. * Event from Level. User has scored. Display it.
  188. *
  189. * @param e The LevelEvent.SCORE event
  190. */
  191. public function onScore(e:LevelEvent):void
  192. {
  193. var levelStats:LevelStats = e.levelStats;
  194. var reactionPoint:Point = levelStats.lastPointOfInterest;
  195. var scoreItem:ScoreItem = new ScoreItem("+" + String(levelStats.lastScore),
  196. reactionPoint.x, reactionPoint.y);
  197. addChild(scoreItem);
  198. var sound:Sound = new SoundLib.EXPLODE_SOUND();
  199. sound.play();
  200. var destroyed:uint = levelStats.itemsTotal - levelStats.itemsRemaining;
  201. statsBoard.updateStats(destroyed, levelStats.itemsRequired, levelStats.itemsTotal);
  202. }
  203. /**
  204. * Event from Level. User has scored. Display it.
  205. *
  206. * @param e The LevelEvent.BOMB event
  207. */
  208. public function onBomb(e:LevelEvent):void
  209. {
  210. statsBoard.debitCharge();
  211. }
  212. /**
  213. * Event from the level. Level has concluded in failure
  214. *
  215. * @param e The LevelEvent.FAILURE event
  216. */
  217. public function onLevelFailure(e:LevelEvent):void
  218. {
  219. var sound:Sound = new SoundLib.FAIL_SOUND();
  220. sound.play();
  221. var levelStats:LevelStats = e.levelStats;
  222. var remaining:uint = levelStats.itemsRemaining;
  223. var total:uint = levelStats.itemsTotal;
  224. var destroyed:uint = total - remaining;
  225. var suddenDeath:Boolean = levelStats.suddenDeath;
  226. var condolenceNum:uint = Math.random() * 10;
  227. var condolence:String = ResourceStrings["CONDOLENCE" + String(condolenceNum)];
  228. var msg:String = condolence + "<br /><br />";
  229. if (suddenDeath)
  230. {
  231. msg += ResourceStrings.SUDDEN_FAIL;
  232. }
  233. else
  234. {
  235. var failMsgArray:Array = ResourceStrings.PERFORMANCE_FAIL.split("XX");
  236. msg += failMsgArray[0] + String(destroyed) + failMsgArray[1] + String(total) + failMsgArray[2];
  237. }
  238. var buttonRank:Array = new Array();
  239. var replayLevelButton:InfoButton = new InfoButton("Replay level", playButtonColor,
  240. overButtonColor, downButtonColor);
  241. replayLevelButton.addEventListener(MouseEvent.CLICK, restartLevel);
  242. var restartButton:InfoButton = new InfoButton("Start over", playButtonColor,
  243. overButtonColor, downButtonColor);
  244. restartButton.addEventListener(MouseEvent.CLICK, restartGame);
  245. buttonRank.push(replayLevelButton);
  246. buttonRank.push(restartButton);
  247. newInfo(msg, false, buttonRank, false, null, true);
  248. }
  249. /**
  250. * Event passed forward from the level. Level has concluded in success
  251. *
  252. * @param levelStats The stats from the current level
  253. * @param score The total game score
  254. */
  255. public function onLevelSuccess(levelStats:LevelStats, score:Number):void
  256. {
  257. var sound:Sound = new SoundLib.SUCCESS_SOUND();
  258. sound.play();
  259. var remaining:uint = levelStats.itemsRemaining;
  260. var total:uint = levelStats.itemsTotal;
  261. var destroyed:uint = total - remaining;
  262. var msg:String = ResourceStrings.PERFORMANCE_SUCCESS0;
  263. var msgArray:Array = ResourceStrings.PERFORMANCE_SUCCESS1.split("XX");
  264. statsBoard.totalScore = String(score);
  265. var buttonRank:Array = new Array();
  266. var nextLevelButton:InfoButton = new InfoButton("Next Level", playButtonColor,
  267. overButtonColor, downButtonColor);
  268. nextLevelButton.addEventListener(MouseEvent.CLICK, nextLevel);
  269. buttonRank.push(nextLevelButton);
  270. var msgQueue:Array = new Array();
  271. msgQueue.push(msgArray[0] + destroyed + msgArray[1] + total + msgArray[2]);
  272. if (levelStats.squiffs)
  273. msgQueue.push(ResourceStrings.SQUIFFS + ": " + levelStats.squiffs +
  274. " (" + levelStats.squiffCost + ")");
  275. if (levelStats.cleared)
  276. {
  277. var clearBonusMsg:String = ResourceStrings.LEVEL_CLEARED;
  278. if (levelStats.bombs)
  279. clearBonusMsg += ResourceStrings.BOMBS_REMAINING;
  280. if (levelStats.minScoreOverride)
  281. msgQueue.push(ResourceStrings.LEVEL_CLEARED_MINIMUM + levelStats.scoreModifier);
  282. msgQueue.push(clearBonusMsg + "! (x" + levelStats.clearedBonus + ")");
  283. }
  284. msgQueue.push(ResourceStrings.LEVEL_SCORE + ": " + levelStats.score);
  285. msgQueue.push(ResourceStrings.GAME_SCORE + ": " + score);
  286. newInfo(msg, false, buttonRank, true, msgQueue, true);
  287. }
  288. /**
  289. * Event forwarded from the game. Game is over.
  290. *
  291. * @param levelStats The stats from the current level
  292. * @param score The total game score
  293. */
  294. public function onGameOver(levelStats:LevelStats, score:Number):void
  295. {
  296. var sound:Sound = new SoundLib.SUCCESS_SOUND();
  297. sound.play();
  298. var remaining:uint = levelStats.itemsRemaining;
  299. var total:uint = levelStats.itemsTotal;
  300. var destroyed:uint = total - remaining;
  301. var msg:String = ResourceStrings.FINAL_SUCCESS0;
  302. var msgArray:Array = ResourceStrings.FINAL_SUCCESS1.split("XX");
  303. statsBoard.totalScore = String(score);
  304. var msgQueue:Array = new Array();
  305. msgQueue.push(msgArray[0] + destroyed + msgArray[1] + total + msgArray[2]);
  306. if (levelStats.squiffs)
  307. msgQueue.push(ResourceStrings.SQUIFFS + ": " + levelStats.squiffs +
  308. " (" + levelStats.squiffCost + ")");
  309. if (levelStats.cleared)
  310. {
  311. var clearBonusMsg:String = ResourceStrings.LEVEL_CLEARED;
  312. if (levelStats.bombs)
  313. clearBonusMsg += ResourceStrings.BOMBS_REMAINING;
  314. if (levelStats.minScoreOverride)
  315. msgQueue.push(ResourceStrings.LEVEL_CLEARED_MINIMUM + levelStats.scoreModifier);
  316. msgQueue.push(clearBonusMsg + "! (x" + levelStats.clearedBonus + ")");
  317. }
  318. msgQueue.push(ResourceStrings.LEVEL_SCORE + ": " + levelStats.score);
  319. msgQueue.push(ResourceStrings.GAME_SCORE + ": " + score);
  320. msgQueue.push(ResourceStrings.FINAL_SUCCESS2);
  321. msgQueue.push(ResourceStrings.FINAL_SUCCESS3);
  322. var buttonRank:Array = new Array();
  323. var restartButton:InfoButton = new InfoButton("Start over", playButtonColor,
  324. overButtonColor, downButtonColor);
  325. restartButton.addEventListener(MouseEvent.CLICK, restartGame);
  326. buttonRank.push(restartButton);
  327. newInfo(msg, false, buttonRank, true, msgQueue, true);
  328. }
  329. /**
  330. * User has "squiffed", ie, Dropped a bomb and hit nothing whatsoever
  331. *
  332. * @param e The LevelEvent.SQUIFF event
  333. */
  334. public function onSquiff(e:LevelEvent):void
  335. {
  336. var reactionPoint:Point = e.levelStats.lastPointOfInterest;
  337. var scoreItem:ScoreItem = new ScoreItem(ResourceStrings.SQUIFF, reactionPoint.x, reactionPoint.y);
  338. addChild(scoreItem);
  339. }
  340. /**
  341. * User has cleared all bots on the current level
  342. *
  343. * @param e The LevelEvent.BOTS_CLEARED event
  344. */
  345. public function onBotsCleared(e:LevelEvent):void
  346. {
  347. /** No implementation for now */
  348. }
  349. /**
  350. * Event from the play/pause button
  351. *
  352. * @param e The CLICK MouseEvent
  353. */
  354. private function onPlayPause(e:MouseEvent):void
  355. {
  356. var event:uint = (e.currentTarget.lastEventIndex);
  357. var gameEventType:String;
  358. if (event == PLAY)
  359. {
  360. dismissBoxes();
  361. gameEventType = GameEvent.PLAY;
  362. }
  363. else
  364. {
  365. gameEventType = GameEvent.PAUSE;
  366. }
  367. dispatchEvent(new GameEvent(gameEventType));
  368. }
  369. /**
  370. * Event from the sound button. Toggle sound off/on
  371. *
  372. * @param e The CLICK MouseEvent
  373. */
  374. private function onToggleSound(e:MouseEvent):void
  375. {
  376. var event:uint = (e.currentTarget.lastEventIndex);
  377. var vol:Number = (event == PLAY) ? 0 : 1;
  378. var sTrans:SoundTransform = new SoundTransform(vol);
  379. SoundMixer.soundTransform = sTrans;
  380. }
  381. /**
  382. * Create the play/pause multi-state button
  383. */
  384. private function createPlayPauseBtn():void
  385. {
  386. var playButton:GameButton = new GameButton( ResourceStrings.PLAY, playButtonColor,
  387. overButtonColor, downButtonColor);
  388. var pauseButton:GameButton = new GameButton(ResourceStrings.PAUSE, playButtonColor,
  389. overButtonColor, downButtonColor);
  390. playPauseBtn = new MultiStateButton([playButton, pauseButton]);
  391. playPauseBtn.x = _playField.x + _playField.width + SPACER;
  392. playPauseBtn.y = _playField.x + _playField.height - playPauseBtn.height;
  393. addChild(playPauseBtn);
  394. playPauseBtn.addEventListener(MouseEvent.CLICK, onPlayPause);
  395. }
  396. /**
  397. * Create the sound/mute button
  398. */
  399. private function createSoundBtn():void
  400. {
  401. var btnHeight:Number = playPauseBtn.height - 6;
  402. var playSoundUpState:Sprite = new Sprite();
  403. playSoundUpState.graphics.beginFill(ColorLib.SOUND_BTN);
  404. playSoundUpState.graphics.drawRoundRect(0, 0, 50, btnHeight, 20, 20);
  405. playSoundUpState.graphics.endFill();
  406. playSoundUpState.addChild(new SoundOnIcon());
  407. var playSoundOverState:Sprite = new Sprite();
  408. playSoundOverState.graphics.beginFill(overButtonColor);
  409. playSoundOverState.graphics.drawRoundRect(0, 0, 50, btnHeight, 20);
  410. playSoundOverState.graphics.endFill();
  411. playSoundOverState.addChild(new SoundOnIcon());
  412. var playSoundDownState:Sprite = new Sprite();
  413. playSoundDownState.graphics.beginFill(downButtonColor);
  414. playSoundDownState.graphics.drawRoundRect(0, 0, 50, btnHeight, 20);
  415. playSoundDownState.graphics.endFill();
  416. playSoundDownState.addChild(new SoundOnIcon());
  417. var pauseSoundUpState:Sprite = new Sprite();
  418. pauseSoundUpState.graphics.beginFill(ColorLib.SOUND_BTN);
  419. pauseSoundUpState.graphics.drawRoundRect(0, 0, 50, btnHeight, 20);
  420. pauseSoundUpState.graphics.endFill();
  421. pauseSoundUpState.addChild(new SoundOffIcon());
  422. var pauseSoundOverState:Sprite = new Sprite();
  423. pauseSoundOverState.graphics.beginFill(overButtonColor);
  424. pauseSoundOverState.graphics.drawRoundRect(0, 0, 50, btnHeight, 20);
  425. pauseSoundOverState.graphics.endFill();
  426. pauseSoundOverState.addChild(new SoundOffIcon());
  427. var pauseSoundDownState:Sprite = new Sprite();
  428. pauseSoundDownState.graphics.beginFill(downButtonColor);
  429. pauseSoundDownState.graphics.drawRoundRect(0, 0, 50, btnHeight, 20);
  430. pauseSoundDownState.graphics.endFill();
  431. pauseSoundDownState.addChild(new SoundOffIcon());
  432. var playSoundBtn:SimpleButton = new SimpleButton(playSoundUpState, playSoundOverState,
  433. playSoundDownState, playSoundUpState);
  434. var muteSoundBtn:SimpleButton = new SimpleButton(pauseSoundUpState, pauseSoundOverState,
  435. pauseSoundDownState, pauseSoundUpState);
  436. soundBtn = new MultiStateButton([playSoundBtn, muteSoundBtn]);
  437. soundBtn.x = playPauseBtn.x + playPauseBtn.width - soundBtn.width;
  438. soundBtn.y = playPauseBtn.y + 3;
  439. addChild(soundBtn);
  440. soundBtn.addEventListener(MouseEvent.CLICK, onToggleSound);
  441. }
  442. /**
  443. * Post a new info box
  444. *
  445. * @param msg The text for the info box
  446. * @param autoDismiss If true, the window will dismiss itself automatically
  447. * @param buttonRank An array of InfoButtons to appear within the alert
  448. * @param success If true, level is complete
  449. * @param msgQueue Array of strings to display in the box
  450. * @param isModal If the infobox is modal, disable buttons
  451. */
  452. protected function newInfo(msg:String, autoDismiss:Boolean = false,
  453. buttonRank:Array = null, success:Boolean = false,
  454. msgQueue:Array = null, isModal:Boolean = false):void
  455. {
  456. dismissBoxes();
  457. if (isModal)
  458. disable();
  459. var ms:uint = (autoDismiss) ? autoDismissMS : 0;
  460. var infoBox:InfoBox;
  461. if (success)
  462. infoBox = new ExpandingInfoBox(300, 300, msg, ms, buttonRank, msgQueue);
  463. else
  464. infoBox = new InfoBox(300, 300, msg, ms, buttonRank);
  465. infoBox.x = _playField.x + (_playField.width/2);
  466. infoBox.y = _playField.y + (_playField.height/2);
  467. infoBox.addEventListener(Event.CLOSE, onClose);
  468. infoBox.addEventListener(Event.COMPLETE, onInfoComplete);
  469. alerts.push(infoBox);
  470. addChild(infoBox);
  471. }
  472. /**
  473. * Event from Help button
  474. *
  475. * @param e The Mouse CLICK event
  476. */
  477. private function onHelp(e:MouseEvent):void
  478. {
  479. dismissBoxes();
  480. var helpBox:HelpBox;
  481. if (e.currentTarget == learnBtn)
  482. helpBox = new HelpBox(300, 400, "content/learn.swf");
  483. else
  484. helpBox = new HelpBox(300, 400, "content/help.swf");
  485. helpBox.addEventListener(Event.CLOSE, onClose);
  486. helpBox.addEventListener(Event.COMPLETE, onInfoComplete);
  487. helpBox.x = _playField.x + (_playField.width/2);
  488. helpBox.y = _playField.y + (_playField.height/2);
  489. alerts.push(helpBox);
  490. addChild(helpBox);
  491. }
  492. /**
  493. * Enable chrome buttons
  494. */
  495. private function enable():void
  496. {
  497. playPauseBtn.alpha = 1;
  498. learnBtn.alpha = 1;
  499. helpBtn.alpha = 1;
  500. playPauseBtn.enabled = true;
  501. learnBtn.enabled = learnBtn.mouseEnabled = true;
  502. helpBtn.enabled = helpBtn.mouseEnabled = true;
  503. playPauseBtn.addEventListener(MouseEvent.CLICK, onPlayPause);
  504. }
  505. /**
  506. * Disable chrome buttons
  507. */
  508. private function disable():void
  509. {
  510. playPauseBtn.alpha = .25;
  511. learnBtn.alpha = .25;
  512. helpBtn.alpha = .25;
  513. playPauseBtn.enabled = false;
  514. learnBtn.enabled = learnBtn.mouseEnabled = false;
  515. helpBtn.enabled = helpBtn.mouseEnabled = false;
  516. playPauseBtn.removeEventListener(MouseEvent.CLICK, onPlayPause);
  517. }
  518. /**
  519. * Event from info/help box. It's informing us it would like to close.
  520. *
  521. * @param e The CLOSE event
  522. */
  523. private function onClose(e:Event):void
  524. {
  525. dismissBoxes();
  526. }
  527. /**
  528. * Event from info/help box. It's requesting to destroyed.
  529. *
  530. * @param e The COMPLETE event
  531. */
  532. private function onInfoComplete(e:Event):void
  533. {
  534. var info:InfoBox = e.target as InfoBox;
  535. var a:uint = alerts.length;
  536. while (a--)
  537. {
  538. var alert:InfoBox = alerts[a] as InfoBox;
  539. if (alert == info)
  540. {
  541. alerts.splice(a, 1);
  542. alert.destroy();
  543. break;
  544. }
  545. }
  546. enable();
  547. }
  548. /**
  549. * Event from Infobox. User requests move to next level
  550. *
  551. * @param e The MouseEvent.CLICK event
  552. */
  553. private function nextLevel(e:MouseEvent):void
  554. {
  555. dismissBoxes();
  556. dispatchEvent(new GameEvent(GameEvent.NEXT_LEVEL));
  557. }
  558. /**
  559. * Event from Infobox. User requests replay of current level
  560. *
  561. * @param e The MouseEvent.CLICK event
  562. */
  563. private function restartLevel(e:MouseEvent):void
  564. {
  565. dismissBoxes();
  566. dispatchEvent(new GameEvent(GameEvent.RESTART_LEVEL));
  567. }
  568. /**
  569. * Event from Infobox. User requests new game
  570. *
  571. * @param e The MouseEvent.CLICK event
  572. */
  573. private function restartGame(e:MouseEvent):void
  574. {
  575. dismissBoxes();
  576. dispatchEvent(new GameEvent(GameEvent.RESTART_GAME));
  577. }
  578. /**
  579. * Dismiss existing info and help boxes
  580. *
  581. * We only allow one info box at a time, but we want the old one to be able
  582. * to animate away cleanly. Storing in an array like this allows unrestricted
  583. * monkey-bashing.
  584. */
  585. private function dismissBoxes():void
  586. {
  587. var a:uint = alerts.length;
  588. while (a--)
  589. {
  590. var alert:InfoBox = alerts.pop() as InfoBox;
  591. alert.dismiss();
  592. }
  593. }
  594. }
  595. }