GameOverState.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. FZ.Game.GameOverState = new (FZ.newClass({
  2. StateName : FZ.StateDefs.GAME_STATE_OVER,
  3. CUR_UI_DEFS : ["GAME_OVER_BG","NUM_STAGE_OVER_TOTAL_1","NUM_STAGE_OVER_TOTAL_2",
  4. "NUM_STAGE_OVER_TOTAL_3","NUM_STAGE_OVER_TOTAL_4","NUM_STAGE_OVER_TOTAL_5"],
  5. UI_SCORE_START_INDEX: 1,
  6. TOTAL_SCORE: 5,
  7. BTN_REPLAY_INDEX : 0,
  8. CUR_BTN_DEFS : [["BTN_RETRY", "BTN_RETRY_TOUCH"],],
  9. STR_RECT : [173, 280, 138, 36],
  10. // m_last_score_div : null,
  11. m_load_ui : false,
  12. popState: false,
  13. COLOR_YELLOW:"#F0D751",
  14. COLOR_BROWN:"#B97F00",
  15. COLOR_ORANGE:"#FFC72A",
  16. LABEL_TEXT_SIZE_SMALL:12,
  17. LABEL_TEXT_SIZE_MIDDLE:18,
  18. LABEL_TEXT_SIZE_LARGE:24,
  19. m_title_div:null,
  20. m_conten_div:null,
  21. createLabelTitleTextSprite : function(x,y,w,h, text, color) {
  22. this.m_title_div = document.createElement("div");
  23. this.m_title_div.style.width = w + "px";
  24. this.m_title_div.style.height = h + "px";
  25. this.m_title_div.style.left = x + "px";
  26. this.m_title_div.style.top = y + "px";
  27. this.m_title_div.style.position = "absolute";
  28. this.m_ui_list[0].appendChild(this.m_title_div);
  29. this.m_title_div.style.zIndex = 300;
  30. var lnH = h-2;
  31. this.m_title_div.style.textAlign = "center";
  32. this.m_title_div.style.lineHeight = Math.round(lnH) + "px";;
  33. this.m_title_div.style.fontFamily = "Arial";
  34. this.m_title_div.style.fontWeight = "bolder";
  35. this.m_title_div.style.fontSize = Math.round(h-10) + "px";
  36. // add shadow from up down left and right
  37. this.m_title_div.style.textShadow = "-1px -1px 1px #972301, 1px 1px 1px #972301, 1px -1px 1px #972301, -1px 1px 1px #972301 ";
  38. this.m_title_div.style.color = color;
  39. this.m_title_div.innerHTML = text;
  40. },
  41. createLabelContentTextSprite : function(x,y,w,h, text, color) {
  42. this.m_conten_div = document.createElement("div");
  43. this.m_conten_div.style.width = w + "px";
  44. this.m_conten_div.style.height = h + "px";
  45. this.m_conten_div.style.left = x + "px";
  46. this.m_conten_div.style.top = y + "px";
  47. this.m_conten_div.style.position = "absolute";
  48. this.m_ui_list[0].appendChild(this.m_conten_div);
  49. this.m_conten_div.style.zIndex = 300;
  50. var lnH = h-2;
  51. this.m_conten_div.style.textAlign = "center";
  52. this.m_conten_div.style.lineHeight = Math.round(lnH) + "px";;
  53. this.m_conten_div.style.fontFamily = "Arial";
  54. this.m_conten_div.style.fontWeight = "900";
  55. this.m_conten_div.style.fontSize = Math.round(h-10) + "px";
  56. // add shadow from up down left and right
  57. this.m_conten_div.style.textShadow = "-1px -1px 1px #972301, 1px 1px 1px #972301, 1px -1px 1px #972301, -1px 1px 1px #972301 ";
  58. this.m_conten_div.style.color = color;
  59. this.m_conten_div.innerHTML = text;
  60. },
  61. createBtnTextSprite: function(divSprite, text, color){
  62. var spr = divSprite;
  63. var h = spr.m_h;
  64. spr.m_div.style.textAlign="center";
  65. // spr.m_div.style.textIndent = -20+ "px";
  66. spr.m_div.style.lineHeight= spr.m_div.style.height;
  67. spr.m_div.style.fontFamily="Arial";
  68. spr.m_div.style.fontWeight="bold";
  69. spr.m_div.style.fontSize=Math.round(h/3)+"px";
  70. //add shadow from up down left and right
  71. spr.m_div.style.textShadow="-2px -2px 2px #7c2e1a, 2px 2px 2px #7c2e1a, 2px -2px 2px #7c2e1a, -2px 2px 2px #7c2e1a ";
  72. spr.m_div.style.color=color;
  73. spr.m_div.innerHTML=text;
  74. return spr;
  75. },
  76. preProcess : function(preState, curState, score) {
  77. var index = 0;
  78. // var img = null;
  79. var btn = null;
  80. var info = null;
  81. var infoDown = null;
  82. var ctx = null;
  83. if(!this.m_load_ui) {
  84. this.createUIs(this.CUR_UI_DEFS);
  85. this.createLabelTitleTextSprite(30,25,230,40, FZ.GameText.TEXT_GAME_OVER, "#FEE7B4");
  86. this.createLabelContentTextSprite(40,80,230,25,FZ.GameText.TEXT_YOUR_TOTAL_SCORE, this.COLOR_YELLOW);
  87. this.createBtns(this.CUR_BTN_DEFS, true);
  88. this.createBtnTextSprite(this.m_btn_list[this.BTN_REPLAY_INDEX], FZ.GameText.TEXT_RETRY, this.COLOR_ORANGE);
  89. // this.createStrScoreDiv();
  90. FZ.DivManager.addChild(this.m_main_div);
  91. this.m_load_ui = true;
  92. }
  93. else {
  94. this.m_main_div.style.display = "inline";
  95. }
  96. var scoreNum = FZ.AG.SearchSpecialPath.setScoreNum(score);
  97. for(var index = 0; index < scoreNum.length; index++){
  98. this.m_ui_list[this.UI_SCORE_START_INDEX + this.TOTAL_SCORE - scoreNum.length + index].style.backgroundImage = "url(imgs/number_score_" + scoreNum[scoreNum.length - 1- index] + ".png)";
  99. }
  100. if(scoreNum.length < this.TOTAL_SCORE){
  101. for(var index = 0; index < this.TOTAL_SCORE - scoreNum.length ; index++){
  102. this.m_ui_list[this.UI_SCORE_START_INDEX + index].style.backgroundImage = "url(imgs/number_score_0.png)";
  103. }
  104. }
  105. this.popState = false;
  106. // this.m_last_score_div.innerHTML = "" + score;
  107. },
  108. postProcess : function() {
  109. this.m_main_div.style.display = "none";
  110. },
  111. createStrScoreDiv : function() {
  112. this.m_last_score_div = document.createElement("div");
  113. this.m_last_score_div.style.position = "absolute";
  114. this.m_last_score_div.style.width = this.STR_RECT[2] + "px";
  115. this.m_last_score_div.style.height = this.STR_RECT[3] + "px";
  116. this.m_last_score_div.style.left = this.STR_RECT[0] + "px";
  117. this.m_last_score_div.style.top = this.STR_RECT[1] + "px";
  118. this.m_last_score_div.style.color = "#fff";
  119. this.m_last_score_div.style.fontSize = FZ.GameDefs.STATS_FONT_SIZE + "px";
  120. this.m_last_score_div.style.fontFamily = "Arial";
  121. this.m_last_score_div.style.lineHeight = this.STR_RECT[3] + "px";
  122. this.m_last_score_div.style.textAlign = "left";
  123. this.m_main_div.appendChild(this.m_last_score_div);
  124. },
  125. buttonClick : function(btn) {
  126. if(this.popState){
  127. return;
  128. }
  129. var preState = null;
  130. if(this.m_btn_list[this.BTN_REPLAY_INDEX] === btn) {
  131. this.postProcess();
  132. this.popState = true;
  133. Gamehub.Score.submit(0);
  134. return;
  135. FZ.GameBase.popState(this.StateName);
  136. //FZ.GameBase.switchToState(FZ.StateDefs.GAME_STATE_GAME_IN);
  137. }
  138. // else if(this.m_btn_list[this.BTN_NO_INDEX] === btn) {
  139. // preState = FZ.GameBase.getState(FZ.StateDefs.GAME_STATE_GAME_IN);
  140. //
  141. // if(preState.m_main_div.parentNode) {
  142. // preState.m_main_div.parentNode.removeChild(preState.m_main_div);
  143. // }
  144. // FZ.GameBase.switchToState(FZ.StateDefs.GAME_STATE_MAINMEN);
  145. // }
  146. }
  147. }, FZ.BaseState))();