/src/se/salomonsson/ttt/view/GameInfoView.as

https://github.com/Tommislav/tic-tac-tommy
ActionScript | 72 lines | 54 code | 13 blank | 5 comment | 2 complexity | b2f5280553712db82b6b38cefe4fd41f MD5 | raw file
  1. package se.salomonsson.ttt.view
  2. {
  3. import flash.display.Shape;
  4. import flash.display.Sprite;
  5. import flash.text.TextField;
  6. import flash.text.TextFieldAutoSize;
  7. import flash.text.TextFormat;
  8. /**
  9. * implementation for gameInfoView. Shows the player whos turn it is, or if any player has won.
  10. * @author Tommislav
  11. */
  12. public class GameInfoView extends Sprite implements IGameInfoView
  13. {
  14. private const PLAYER_SYMBOL_WIDTH:int = 8;
  15. private var _playerSymbol:PlayerSymbol;
  16. private var _textfield:TextField;
  17. public function GameInfoView()
  18. {
  19. _textfield = new TextField();
  20. _textfield.defaultTextFormat = new TextFormat( "Verdana", 10 );
  21. _textfield.autoSize = TextFieldAutoSize.LEFT;
  22. _textfield.selectable = false;
  23. _textfield.y = -4;
  24. _textfield.x = 14;
  25. addChild(_textfield);
  26. }
  27. private function setPlayerSymbol(playerId:uint):void
  28. {
  29. clearPlayerSymbol();
  30. _playerSymbol = new PlayerSymbol(playerId);
  31. _playerSymbol.width = _playerSymbol.height = PLAYER_SYMBOL_WIDTH;
  32. addChild(_playerSymbol);
  33. }
  34. private function clearPlayerSymbol():void
  35. {
  36. if (_playerSymbol != null)
  37. {
  38. removeChild(_playerSymbol);
  39. _playerSymbol = null;
  40. }
  41. }
  42. /* INTERFACE se.salomonsson.ttt.view.IGameInfoView */
  43. public function showCurrentPlayer(name:String, playerId:uint):void
  44. {
  45. setPlayerSymbol(playerId);
  46. _textfield.text = "IT'S YOUR TURN: " + name;
  47. }
  48. public function showWinner(name:String, playerId:uint):void
  49. {
  50. setPlayerSymbol(playerId);
  51. _textfield.text = "A WINNER IS YOU: " + name;
  52. }
  53. public function reset():void
  54. {
  55. clearPlayerSymbol();
  56. _textfield.text = "";
  57. }
  58. }
  59. }