GameBody.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. function GameBody(){
  2. base(this,LSprite,[]);
  3. this.init();
  4. }
  5. GameBody.prototype.init = function(){
  6. var self = this;
  7. self.gameover = false;
  8. LGlobal.align = LStageAlign.MIDDLE;
  9. LGlobal.stageScale = LStageScaleMode.SHOW_ALL;
  10. LSystem.screen(LStage.FULL_SCREEN);
  11. var background = new Background();
  12. background.name = "background";
  13. self.addChild(background);
  14. var schedule = self.schedule = new Schedule();
  15. schedule.name = "schedule";
  16. self.addChild(schedule);
  17. var numberManager = self.numberManager = new NumberManager();
  18. numberManager.name = "numberManager";
  19. self.addChild(numberManager);
  20. var nextNumberTips = new LTextField();
  21. nextNumberTips.color = "#953c00";
  22. nextNumberTips.size = 26;
  23. nextNumberTips.x = LGlobal.width*.54;
  24. nextNumberTips.y = LGlobal.height*.025;
  25. nextNumberTips.font = "微软雅黑";
  26. nextNumberTips.text = "1";
  27. self.nextNumberTips = nextNumberTips;
  28. self.addChild(nextNumberTips);
  29. var seriesCountTips = new LTextField();
  30. seriesCountTips.color = "#953c00";
  31. seriesCountTips.size = 26;
  32. seriesCountTips.x = LGlobal.width*.84;
  33. seriesCountTips.y = LGlobal.height*.025;
  34. seriesCountTips.font = "微软雅黑";
  35. seriesCountTips.text = "0";
  36. self.seriesCountTips = seriesCountTips;
  37. self.addChild(seriesCountTips);
  38. self.maxSeriesCount = 0;
  39. self.numberFound = 0;
  40. self.targetNumberFound = COLOR_MAP.positions.length;
  41. // self.targetNumberFound = 1;
  42. self.isGameOver = false;
  43. self.addEventListener(LMouseEvent.MOUSE_DOWN, self.onmousedown);
  44. };
  45. GameBody.prototype.updateNextTips = function(){
  46. var self = this;
  47. var number = self.numberManager.getNextNumber();
  48. var numberS = number +"";
  49. self.nextNumberTips.text = numberS;
  50. if(number > self.numberFound+1){
  51. self.numberFound = number-1;
  52. }
  53. }
  54. GameBody.prototype.updateSeriesCountTips = function(){
  55. var self = this;
  56. var number = self.numberManager.getSeriesCount();
  57. var numberS = number+"";
  58. self.seriesCountTips.text = numberS;
  59. if(number > self.maxSeriesCount){
  60. self.maxSeriesCount = number;
  61. }
  62. }
  63. GameBody.prototype.gameOver = function(){
  64. console.log("gameOver");
  65. var self = this;
  66. self.isGameOver = true;
  67. self.schedule.stop();
  68. var shape = new LShape();
  69. self.addChild(shape);
  70. shape.graphics.drawRect(0, "#000000", [0, 0, LGlobal.width, LGlobal.height], true, "#000000");
  71. shape.alpha = 0.5;
  72. $("#mask").css("display", "block");
  73. var overBoard = self.overBoard = new LSprite();
  74. var overBoardBitmapData = new LBitmapData(dataList["over_board"]);
  75. var overBoardBitmap = new LBitmap(overBoardBitmapData);
  76. overBoard.x = LGlobal.width*(.5)-overBoardBitmapData.width*.5;
  77. overBoard.y = 65;
  78. overBoard.addChild(overBoardBitmap);
  79. self.addChild(overBoard);
  80. gScore = (self.numberFound*100+self.maxSeriesCount*10)+parseInt(self.schedule.getTimeRemain()/45*100);
  81. var scoreText = self.scoreText = new LTextField();
  82. scoreText.color = "#ef4a10";
  83. scoreText.size = 40;
  84. scoreText.y = LGlobal.height*0.42;
  85. scoreText.weight = "bold"
  86. scoreText.font = "微软雅黑";
  87. scoreText.text = gScore+"";
  88. self.addChild(scoreText);
  89. scoreText.x = LGlobal.width*(.5+.19)-scoreText.getWidth()/2;
  90. var maxSeriesCountText = self.maxSeriesCountText = new LTextField();
  91. maxSeriesCountText.color = "#ef4a10";
  92. maxSeriesCountText.size = 40;
  93. maxSeriesCountText.y = LGlobal.height*0.42;
  94. maxSeriesCountText.weight = "bold"
  95. maxSeriesCountText.font = "微软雅黑";
  96. maxSeriesCountText.text = self.maxSeriesCount+"";
  97. self.addChild(maxSeriesCountText);
  98. maxSeriesCountText.x = LGlobal.width*(.5-.21)-maxSeriesCountText.getWidth()/2;
  99. var numberFoundText = self.numberFoundText = new LTextField();
  100. numberFoundText.color = "#ef4a10";
  101. numberFoundText.size = 46;
  102. numberFoundText.x = LGlobal.width*(.5-.09)-numberFoundText.getWidth()/2;
  103. numberFoundText.y = LGlobal.height*0.22;
  104. numberFoundText.weight = "bold"
  105. numberFoundText.font = "微软雅黑";
  106. numberFoundText.text = self.numberFound+"";
  107. self.addChild(numberFoundText);
  108. numberFoundText.x = LGlobal.width*(.5-.04)-numberFoundText.getWidth();
  109. var totalNumber = self.totalNumber = new LTextField();
  110. totalNumber.color = "#72490e";
  111. totalNumber.size = 46;
  112. totalNumber.x = LGlobal.width*(.5-.09)-totalNumber.getWidth()/2;
  113. totalNumber.y = LGlobal.height*0.22;
  114. totalNumber.weight = "bold"
  115. totalNumber.font = "微软雅黑";
  116. totalNumber.text = "/35";
  117. self.addChild(totalNumber);
  118. totalNumber.x = LGlobal.width*(.5+.05)-totalNumber.getWidth()/2;
  119. var continueBtn = self.continueBtn = new LSprite();
  120. var continueBtnBitmapData = new LBitmapData(dataList["continue_btn"]);
  121. var continueBtnBitmap = new LBitmap(continueBtnBitmapData);
  122. continueBtnBitmap.x = -continueBtnBitmapData.width*.5;
  123. continueBtnBitmap.y = -continueBtnBitmapData.height*.5;
  124. continueBtn.x = LGlobal.width*(.5-.21);
  125. continueBtn.y = continueBtnBitmapData.height*.5+LGlobal.height*.56;
  126. continueBtn.addChild(continueBtnBitmap);
  127. self.addChild(continueBtn);
  128. var shareBtn = self.shareBtn = new LSprite();
  129. var shareBtnBitmapData = new LBitmapData(dataList["share_btn"]);
  130. var shareBtnBitmap = new LBitmap(shareBtnBitmapData);
  131. shareBtnBitmap.x = -shareBtnBitmapData.width*.5;
  132. shareBtnBitmap.y = -shareBtnBitmapData.height*.5;
  133. shareBtn.x = LGlobal.width*(.5+.21);
  134. shareBtn.y = shareBtnBitmapData.height*.5+LGlobal.height*.56;
  135. shareBtn.addChild(shareBtnBitmap);
  136. self.addChild(shareBtn);
  137. var more = self.more = new LSprite();
  138. var moreBitmapData = new LBitmapData(dataList["more"]);
  139. var moreBitmap = new LBitmap(moreBitmapData);
  140. moreBitmap.x = -moreBitmapData.width*.5;
  141. moreBitmap.y = -moreBitmapData.height*.5;
  142. more.x = LGlobal.width*(.5);
  143. more.y = moreBitmapData.height*.5+LGlobal.height*.8;
  144. more.addChild(moreBitmap);
  145. self.addChild(more);
  146. self.continueBtn.addEventListener(LMouseEvent.MOUSE_DOWN, self.onContinueBtnDown);
  147. self.shareBtn.addEventListener(LMouseEvent.MOUSE_DOWN, self.onShareBtnDown);
  148. //self.more.addEventListener(/*LMouseEvent.MOUSE_DOWN, self.onMoreBtnDown*/"click", alert(1232455));
  149. //self.more.addEventListener("click", alert(1232455));
  150. self.share(self.numberFound, gScore);
  151. }
  152. GameBody.prototype.share = function(number, score) {
  153. var self = this;
  154. // updateShare(number,score);
  155. // Play68.setRankingLevelScoreDesc(number,score,Play68.rankingShowType.RANKING_SHOW);
  156. }
  157. GameBody.prototype.checkGameOver = function(){
  158. var self = this;
  159. if(self.numberFound >= self.targetNumberFound) {
  160. return true;
  161. }
  162. return false;
  163. }
  164. GameBody.prototype.onmousedown = function(event){
  165. var self = event.target.parent;
  166. if(!self.isGameOver) {
  167. offset = {x:parseInt(event.offsetX),y:parseInt(event.offsetY)};
  168. self.numberManager.hit(offset);
  169. self.updateNextTips();
  170. self.updateSeriesCountTips();
  171. if(self.checkGameOver()){
  172. self.gameOver();
  173. }
  174. }
  175. }
  176. GameBody.prototype.onContinueBtnDown = function(event) {
  177. gameStart();
  178. }
  179. GameBody.prototype.onShareBtnDown = function(event) {
  180. /*btGame.playShareTip();*/
  181. }
  182. GameBody.prototype.onMoreBtnDown = function(event) {
  183. /*window.location.href = btGame.URL.getMoreGame();*/
  184. //window.location.href="http://www.7724.com";
  185. }