PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Minesweeper/src/classes/minesweeper/objects/Display.as

http://as3-minesweeper.googlecode.com/
ActionScript | 127 lines | 75 code | 8 blank | 44 comment | 3 complexity | c5e730ac92acdb5b37e8e25766f16bb7 MD5 | raw file
  1. /**
  2. * VERSION: 1.0
  3. * DATE: 26-02-2011
  4. * AS3
  5. * UPDATES AND DOCS AT: https://code.google.com/p/as3-minesweeper/
  6. *
  7. * Released under GNU GPL v3 License
  8. * @author Jose Heriberto Lopez Ruiz, jlopez@joselopez.com.mx
  9. **/
  10. package minesweeper.objects
  11. {
  12. import flash.display.Sprite;
  13. import flash.text.TextField;
  14. import flash.text.TextFormat;
  15. /**
  16. * Display class
  17. * Counts the flags that can be used to put above a square.
  18. * @author Jose Heriberto Lopez Ruiz, jlopez@joselopez.com.mx
  19. **/
  20. public class Display extends Sprite
  21. {
  22. /**
  23. * EMBEBED FONT INFO:
  24. * By Sizenko Alexander
  25. * http://www.dafont.com/digital-7.font
  26. * http://www.styleseven.com
  27. * Please read the 'Readme (digital-7).txt' file on 'assets' directory.
  28. **/
  29. [Embed(source="../../../assets/digital-7 (mono).TTF", fontName="watchFont_embedded", fontStyle="normal", fontWeight="normal", embedAsCFF="false", unicodeRange="U+0030-U+0039")]
  30. /** Class registered for the embed font. **/
  31. private var WatchFont_embedded:Class;
  32. /** Textfield where the numbers of the display are shown. **/
  33. protected var displayNumbers_txt:TextField = new TextField();
  34. /** Textfield that shows the number '888', just to simulate a shadow for the numbers of the display. **/
  35. protected var shadowNumbers_txt:TextField = new TextField();
  36. /** TextFormat for the numbers shown on the display. **/
  37. private var displayTextFormat:TextFormat = new TextFormat();
  38. /** TextFormat for the shadow of the numbers of the display. **/
  39. private var shadowTextFormat:TextFormat = new TextFormat();
  40. /**
  41. * Constructor.
  42. *
  43. * Draws the display.
  44. * Initialize the TextFields and the TextFormats and adds it to the stage.
  45. **/
  46. public function Display()
  47. {
  48. drawDisplay();
  49. initialize();
  50. }
  51. /**
  52. * Initialize the TextFields and the TextFormats.
  53. * Position them.
  54. * Adds them to the stage.
  55. **/
  56. private function initialize():void
  57. {
  58. displayTextFormat.font = "watchFont_embedded";
  59. displayTextFormat.color = 0xFF0000;
  60. displayTextFormat.size = 30;
  61. displayTextFormat.letterSpacing = 2;
  62. shadowTextFormat.font = displayTextFormat.font;
  63. shadowTextFormat.color = displayTextFormat.color;
  64. shadowTextFormat.size = displayTextFormat.size;
  65. shadowTextFormat.letterSpacing = displayTextFormat.letterSpacing;
  66. shadowNumbers_txt.alpha = 0.4;
  67. displayNumbers_txt.embedFonts = true;
  68. displayNumbers_txt.defaultTextFormat = displayTextFormat;
  69. displayNumbers_txt.height = displayTextFormat.size;
  70. displayNumbers_txt.selectable = false;
  71. displayNumbers_txt.x = 1;
  72. displayNumbers_txt.y = -4;
  73. displayNumbers_txt.text = "000";
  74. shadowNumbers_txt.embedFonts = displayNumbers_txt.embedFonts;
  75. shadowNumbers_txt.defaultTextFormat = displayNumbers_txt.defaultTextFormat;
  76. shadowNumbers_txt.height = displayNumbers_txt.height;
  77. shadowNumbers_txt.selectable = displayNumbers_txt.selectable;
  78. shadowNumbers_txt.x = displayNumbers_txt.x;
  79. shadowNumbers_txt.y = displayNumbers_txt.y;
  80. shadowNumbers_txt.text = "888";
  81. this.addChild(displayNumbers_txt);
  82. this.addChild(shadowNumbers_txt);
  83. }
  84. /**
  85. * Renders on the display the number specified by its parameter.
  86. * @param count Number that will be rendered on this display.
  87. **/
  88. protected function writeTime(count):void
  89. {
  90. if(count <= 9){
  91. this.displayNumbers_txt.text = "00"+ count;
  92. }else if(count >= 10 && count <= 99){
  93. this.displayNumbers_txt.text = "0"+ count;
  94. }else{
  95. this.displayNumbers_txt.text = count;
  96. }
  97. }
  98. /**
  99. * Draws a black rectangle to simulate the display screen.
  100. **/
  101. public function drawDisplay():void
  102. {
  103. const displayWidth:int = 50;
  104. const displayHeigth:int = 25;
  105. this.graphics.clear();
  106. this.graphics.lineStyle(1, 0x808080, 1);
  107. this.graphics.beginFill(0x000000);
  108. this.graphics.moveTo(0, 0);
  109. this.graphics.lineTo(displayWidth, 0);
  110. this.graphics.lineStyle(1, 0xFFFFFF, 1);
  111. this.graphics.lineTo(displayWidth, displayHeigth);
  112. this.graphics.lineStyle(1, 0xFFFFFF, 1);
  113. this.graphics.lineTo(0, displayHeigth);
  114. this.graphics.lineStyle(1, 0x808080, 1);
  115. this.graphics.lineTo(0, 0);
  116. this.graphics.endFill();
  117. }
  118. }
  119. }