game.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. var probe = {
  2. support: function(key) {
  3. var bln = true;
  4. switch (key) {
  5. case "boxshadow":
  6. bln = this.supportBoxShadow();
  7. break;
  8. default:
  9. break
  10. }
  11. return bln
  12. },
  13. supportBoxShadow: function() {
  14. var $testDiv = $('<div style="box-shadow:inset 0px -1px 1px -1px #b2b2b2;"></div>');
  15. try {
  16. if ($testDiv.css("box-shadow")) {
  17. return true
  18. } else {
  19. return false
  20. }
  21. } catch (e) {
  22. return false
  23. }
  24. }
  25. };
  26. var dialog = {
  27. alert: function(options, callback) {
  28. var self = this;
  29. var closebtn = {
  30. title: "\u5173\u95ed",
  31. click: function() {}
  32. };
  33. var opt = {
  34. title: null,
  35. content: null,
  36. zindex: 4200,
  37. bgcolor: "#ccc",
  38. opacity: .5,
  39. topOffset: 0,
  40. width: "280",
  41. loadDefaultCss: true,
  42. buttons: {
  43. close: {
  44. title: "\u5173\u95ed",
  45. click: function() {}
  46. }
  47. }
  48. };
  49. if (typeof options == "string") {
  50. opt.content = options;
  51. if (callback) {
  52. closebtn.click = callback;
  53. opt = $.extend(true, opt, {
  54. buttons: {
  55. close: closebtn
  56. }
  57. })
  58. }
  59. } else {
  60. opt = $.extend(true, opt, options)
  61. }
  62. self.dialog(opt)
  63. },
  64. confirm: function(options, callback) {
  65. var self = this;
  66. var confirmbtn = {
  67. title: "\u786e\u5b9a",
  68. click: function() {}
  69. };
  70. var opt = {
  71. title: null,
  72. content: null,
  73. zindex: 4200,
  74. bgcolor: "#ccc",
  75. opacity: .5,
  76. topOffset: 0,
  77. width: "280",
  78. loadDefaultCss: true,
  79. buttons: {
  80. confirm: {
  81. title: "\u786e\u5b9a",
  82. click: function() {}
  83. },
  84. close: {
  85. title: "\u53d6\u6d88",
  86. click: function() {}
  87. }
  88. }
  89. };
  90. if (typeof options == "string") {
  91. opt.content = options;
  92. if (callback) {
  93. confirmbtn.click = callback;
  94. opt = $.extend(true, opt, {
  95. buttons: {
  96. confirm: confirmbtn
  97. }
  98. })
  99. }
  100. } else {
  101. opt = $.extend(true, opt, options)
  102. }
  103. self.dialog(opt)
  104. },
  105. dialog: function(options) {
  106. var self = this;
  107. var id = "dialog_" + (new Date).getTime();
  108. var opt = {
  109. title: null,
  110. content: null,
  111. zindex: 4200,
  112. bgcolor: "#ccc",
  113. opacity: .5,
  114. topOffset: 0,
  115. width: "280",
  116. loadDefaultCss: true,
  117. buttons: {
  118. close: {
  119. title: "\u5173\u95ed",
  120. click: function() {}
  121. }
  122. }
  123. };
  124. opt = $.extend(true, opt, options);
  125. opt.id = id;
  126. if (String(opt.width).indexOf("%") < 0) {
  127. opt.width = opt.width + "px"
  128. }
  129. if (opt.loadDefaultCss == true) {
  130. this.loadDialogCss()
  131. }
  132. var $mask = $('<div id="' + id + '_cover" ></div>');
  133. $mask.css({
  134. "z-index": opt.zindex,
  135. "background-color": opt.bgcolor,
  136. position: "fixed",
  137. left: 0,
  138. top: 0,
  139. width: "100%",
  140. height: "100%",
  141. opacity: opt.opacity
  142. });
  143. $("body").append($mask);
  144. var $dialog = $('<div id="' + id + '" class="amsmobi_dialog" style="width:' + opt.width + ";z-index:" + parseInt(opt.zindex + 1) + ";top:50%;left:50%;position:fixed;_position:absolute;_top:expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop+(document.documentElement.clientHeight - this.offsetHeight)/2+this.offsetHeight/2:document.body.scrollTop+(document.body.clientHeight - this.clientHeight)/2);\"></div>");
  145. var $head = $("<header></header>");
  146. var $body = $("<section></section>");
  147. if (probe.support("boxshadow")) {
  148. $body.css("box-shadow", "inset 0px -1px 1px -1px #b2b2b2")
  149. } else {
  150. $body.css("border-bottom", "1px solid #b2b2b2")
  151. }
  152. var $footer = $("<footer></footer>");
  153. var closeDialog = function() {
  154. $dialog.remove();
  155. $mask.animate({
  156. opacity: 0
  157. }, 600, "ease-out", function() {
  158. $mask.remove()
  159. })
  160. };
  161. if (opt.title) {
  162. $head.append($("<h2>" + opt.title + "</h2>"))
  163. }
  164. $dialog.append($head);
  165. if (opt.content) {
  166. $body.append(opt.content)
  167. }
  168. $dialog.append($body);
  169. var newButtons = new Array;
  170. $.each(opt.buttons, function(key, btn) {
  171. if (key.toLowerCase() != "close") {
  172. btn.key = key;
  173. newButtons.push(btn)
  174. }
  175. });
  176. if (opt.buttons["close"]) {
  177. var btn = opt.buttons["close"];
  178. btn.key = "close";
  179. newButtons.push(btn)
  180. }
  181. var ibtnWidth = parseFloat((100 - newButtons.length) / newButtons.length);
  182. $.each(newButtons, function(key, btn) {
  183. var $btn = $('<a href="javascript:;" style="width:' + ibtnWidth + '%" data-key="' + key + '">' + btn.title + "</a>");
  184. if (btn.key != "close") {
  185. if (probe.support("boxshadow")) {
  186. $btn.css("box-shadow", "inset -1px 0px 1px -1px #b2b2b2")
  187. } else {
  188. $btn.css("border-right", "1px solid #b2b2b2")
  189. }
  190. }
  191. if ($.os.ios) {
  192. $btn.click(function(e) {
  193. e.stopPropagation();
  194. e.preventDefault();
  195. if (btn.click) {
  196. btn.click();
  197. closeDialog()
  198. }
  199. })
  200. } else {
  201. $btn.click(function(e) {
  202. e.stopPropagation();
  203. e.preventDefault();
  204. if (btn.click) {
  205. btn.click();
  206. closeDialog()
  207. }
  208. })
  209. }
  210. $footer.append($btn)
  211. });
  212. $dialog.append($footer);
  213. $("body").append($dialog);
  214. var fixDialog = function() {
  215. var maxHeight = $(window).height() - 40;
  216. if ($dialog.height() > maxHeight) {
  217. var mTop = -(maxHeight / 2) + $(window).scrollTop();
  218. if ($.os.ios) {
  219. $dialog.css({
  220. "margin-left": -($dialog.width() / 2) + "px",
  221. "margin-top": mTop + "px",
  222. position: "absolute"
  223. })
  224. } else {
  225. $mask.css("position", "absolute");
  226. $(window).on("scroll", function() {
  227. var newHeight = $(window).height() + $(window).scrollTop();
  228. $mask.css("height", newHeight + "px")
  229. });
  230. var left = ($(window).width() - $dialog.width()) / 2;
  231. var style = "width:" + opt.width + ";z-index:" + parseInt(opt.zindex + 1) + ";position:absolute;top:" + ($(window).scrollTop() + 20) + "px;left:" + left + "px;";
  232. $dialog.attr("style", style)
  233. }
  234. } else {
  235. $dialog.css({
  236. "margin-left": -($dialog.width() / 2) + "px",
  237. "margin-top": -($dialog.height() / 2) + "px"
  238. })
  239. }
  240. };
  241. fixDialog();
  242. $(window).on("resize", function() {
  243. fixDialog()
  244. });
  245. $(window).on("orientationchange", function() {
  246. fixDialog()
  247. }, false);
  248. return $dialog
  249. },
  250. showLoading: function(options) {
  251. this.loadLoadingCSS();
  252. var opt = {
  253. zindex: 4100,
  254. bgcolor: "#ccc",
  255. opacity: .5
  256. };
  257. opt = $.extend(true, opt, options);
  258. var id = "amsmobi_loading";
  259. if ($("#" + id).length == 0) {
  260. var $mask = $('<div id="' + id + '_cover" style="z-index:' + opt.zindex + ";background-color:" + opt.bgcolor + ";position:fixed;left:0;top:0;width:100%;height:100%;filter:alpha(opacity=" + opt.opacity * 100 + ");opacity:" + opt.opacity + ';_position:absolute;_top:expression(eval(document.compatMode && document.compatMode==\'CSS1Compat\') ? documentElement.scrollTop+(document.documentElement.clientHeight-this.offsetHeight)/2:document.body.scrollTop+(document.body.clientHeight - this.clientHeight)/2); "><iframe style="position:fixed;_position:absolute;width:100%;height:100%;border:none;filter:alpha(opacity=0);opacity:0;left:0;top:0;z-index:-1;" src="about:blank"></iframe></div>');
  261. var $dialog = $('<div id="' + id + '" style="background-color:#999;width:106px;height:106px;margin-left:-53px;margin-top:-53px;-moz-border-radius: 8px;-webkit-border-radius: 8px;border-radius:8px; z-index:' + parseInt(opt.zindex + 1) + ";top:50%;left:50%;position:fixed;_position:absolute;_top:expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop+(document.documentElement.clientHeight - this.offsetHeight)/2+this.offsetHeight/2:document.body.scrollTop+(document.body.clientHeight - this.clientHeight)/2);\"></div>");
  262. if (probe.support("boxshadow")) {
  263. $dialog.append('<div class="amsmobi_loader" >Loading...</div>')
  264. } else {
  265. $dialog.append('<div style="margin-top:41px;margin-left:15px;color:#666">Loading...</div>')
  266. }
  267. $("body").append($mask).append($dialog)
  268. } else {
  269. $("#" + id + "_cover").show();
  270. $("#" + id).show()
  271. }
  272. },
  273. hideLoading: function() {
  274. $("#amsmobi_loading").hide();
  275. $("#amsmobi_loading_cover").hide()
  276. },
  277. loadLoadingCSS: function() {
  278. var style = ".amsmobi_loader {margin: 4em auto;font-size: 12px;width: 1em;height: 1em;border-radius: 50%;position: relative;text-indent: -9999em;-webkit-animation: amsmobi_load5 1.1s infinite ease;animation: amsmobi_load5 1.1s infinite ease;}" + " @-webkit-keyframes amsmobi_load5 {0%,100% {box-shadow: 0em -2.6em 0em 0em #ffffff, 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.5), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.7);}" + " 12.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.7), 1.8em -1.8em 0 0em #ffffff, 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.5);}" + " 25% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.5), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.7), 2.5em 0em 0 0em #ffffff, 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 37.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.5), 2.5em 0em 0 0em rgba(255, 255, 255, 0.7), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 50% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.5), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.7), 0em 2.5em 0 0em #ffffff, -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 62.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.5), 0em 2.5em 0 0em rgba(255, 255, 255, 0.7), -1.8em 1.8em 0 0em #ffffff, -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 75% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.5), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.7), -2.6em 0em 0 0em #ffffff, -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 87.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.5), -2.6em 0em 0 0em rgba(255, 255, 255, 0.7), -1.8em -1.8em 0 0em #ffffff;} }" + " @keyframes amsmobi_load5 {0%,100% { box-shadow: 0em -2.6em 0em 0em #ffffff, 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.5), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.7);} " + " 12.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.7), 1.8em -1.8em 0 0em #ffffff, 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.5);} " + " 25% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.5), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.7), 2.5em 0em 0 0em #ffffff, 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 37.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.5), 2.5em 0em 0 0em rgba(255, 255, 255, 0.7), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 50% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.5), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.7), 0em 2.5em 0 0em #ffffff, -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.2), -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);} " + " 62.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.5), 0em 2.5em 0 0em rgba(255, 255, 255, 0.7), -1.8em 1.8em 0 0em #ffffff, -2.6em 0em 0 0em rgba(255, 255, 255, 0.2), -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 75% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.5), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.7), -2.6em 0em 0 0em #ffffff, -1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2);}" + " 87.5% {box-shadow: 0em -2.6em 0em 0em rgba(255, 255, 255, 0.2), 1.8em -1.8em 0 0em rgba(255, 255, 255, 0.2), 2.5em 0em 0 0em rgba(255, 255, 255, 0.2), 1.75em 1.75em 0 0em rgba(255, 255, 255, 0.2), 0em 2.5em 0 0em rgba(255, 255, 255, 0.2), -1.8em 1.8em 0 0em rgba(255, 255, 255, 0.5), -2.6em 0em 0 0em rgba(255, 255, 255, 0.7), -1.8em -1.8em 0 0em #ffffff;}}";
  279. this.loadCss("mobi_loading_style", style)
  280. },
  281. loadDialogCss: function() {
  282. var style = ".amsmobi_dialog {color:#000;background-color:#fff; text-align:center;-moz-border-radius: 8px;-webkit-border-radius: 8px;border-radius:8px;font-family:Arial,Helvetica,sans-serif;font-weight:normal;font-size:14px;}" + " .amsmobi_dialog header{font-weight:bold;margin-top:10px;line-height:20px;text-align:center;font-family:Arial,Helvetica,sans-serif;height:auto;width:auto;}" + " .amsmobi_dialog footer{height:40px;padding:0px 0px;width:auto;}" + " .amsmobi_dialog footer a{display:block;color:#007afe;float:left;text-align:center;height:40px;line-height:36px;font-weight:bold;text-decoration: none;font-family:Arial,Helvetica,sans-serif;font-size:16px; }" + " .amsmobi_dialog footer a:hover{text-decoration:none;}" + " .amsmobi_dialog footer button{border:none;background:none;}" + " .amsmobi_dialog section{padding:20px;overflow-x:hidden;text-align:center;font-family:Arial,Helvetica,sans-serif;font-weight:normal;height:auto;width:auto;}";
  283. this.loadCss("mobi_dialog_style", style)
  284. },
  285. loadCss: function(id, style) {
  286. if ($("#" + id).length == 0) {
  287. var newStyle = $('<style id="' + id + '">' + style + "</style>");
  288. $("head").append(newStyle)
  289. }
  290. }
  291. };
  292. var randomDomain = "heromm" + Math.floor(Math.random() * 1e5);
  293. var datajsDom = document.getElementById("gamedata");
  294. var version = datajsDom.getAttribute("data-version");
  295. //var share_url="http://"+randomDomain+".weiue.com/game/heromm2/index.html";
  296. var share_url = "http://k03.ali.118us.com/game/mrg1/index.html";
  297. //var share_img="http://static.weiue.com/game/all/images/cover20140829.jpg";
  298. var share_img = "http://0579jhms.duapp.com/game/mrg1/images/cover20140829.jpg";
  299. console.log(share_url);
  300. var picgame = {
  301. action: {
  302. totalNum: 0,
  303. clickNum: 0,
  304. correctNum: 0,
  305. correctPecent: 0,
  306. timerPasser: 0,
  307. clickData: null
  308. },
  309. timer: null,
  310. second: 0,
  311. maxSecond: 60,
  312. currIndex: 0,
  313. firstInit: 0,
  314. init: function(index, type) {
  315. var img = picimgs[index];
  316. this.currIndex = index;
  317. var self = this;
  318. this.action.totalNum = img.data.length;
  319. this.action.clickData = img.data;
  320. //for(var i=0;i<this.action.clickData.length;i++){this.action.clickData[i].find=false}$("#leftpic").css({width:img.w+"px",height:img.h+"px",background:"url(http://static.weiue.com/game/heromm2/"+img.url1+"?v="+version+")","background-size":img.w+"px "+img.h+"px"});
  321. for (var i = 0; i < this.action.clickData.length; i++) {
  322. this.action.clickData[i].find = false
  323. }
  324. $("#leftpic").css({
  325. width: img.w + "px",
  326. height: img.h + "px",
  327. background: "url(" + img.url1 + "?v=" + version + ")",
  328. "background-size": img.w + "px " + img.h + "px"
  329. });
  330. //$("#rightpic").css({width:img.w+"px",height:img.h+"px",background:"url(http://static.weiue.com/game/heromm2/"+img.url2+"?v="+version+")","background-size":img.w+"px "+img.h+"px"});
  331. $("#rightpic").css({
  332. width: img.w + "px",
  333. height: img.h + "px",
  334. background: "url(" + img.url2 + "?v=" + version + ")",
  335. "background-size": img.w + "px " + img.h + "px"
  336. });
  337. for (var i = 0; i < img.data.length; i++) {
  338. var item = img.data[i];
  339. var $mask1 = $("<div id='maskleft" + i + "' data-id='" + i + "'></div>").addClass("floatmask").css({
  340. width: item.w + "px",
  341. height: item.h + "px",
  342. left: item.l + "px",
  343. top: item.t + "px"
  344. });
  345. var $mask2 = $("<div id='maskright" + i + "' data-id='" + i + "'></div>").addClass("floatmask").css({
  346. width: item.w + "px",
  347. height: item.h + "px",
  348. left: item.l + "px",
  349. top: item.t + "px"
  350. });
  351. $mask1.click(function(e) {
  352. var id = $(this).attr("data-id");
  353. $("#maskleft" + id).addClass("showborder");
  354. $("#maskright" + id).addClass("showborder");
  355. self.action.clickData[id].find = 1;
  356. self.action.clickNum = self.action.clickNum + 1;
  357. self.showTips();
  358. e.stopPropagation();
  359. e.preventDefault()
  360. });
  361. $mask2.click(function(e) {
  362. var id = $(this).attr("data-id");
  363. $("#maskleft" + id).addClass("showborder");
  364. $("#maskright" + id).addClass("showborder");
  365. self.action.clickData[id].find = 1;
  366. self.action.clickNum = self.action.clickNum + 1;
  367. self.showTips();
  368. e.stopPropagation();
  369. e.preventDefault()
  370. });
  371. if (type == 1) {
  372. $mask1.addClass("showborder");
  373. $mask2.addClass("showborder")
  374. }
  375. $("#leftpic").append($mask1);
  376. $("#rightpic").append($mask2)
  377. }
  378. if (self.firstInit == 0) {
  379. self.firstInit = 1;
  380. $("#picbox").click(function() {
  381. self.action.clickNum = self.action.clickNum + 1;
  382. self.showTips()
  383. })
  384. }
  385. self.showTips()
  386. },
  387. showTips: function() {
  388. var self = this;
  389. var correctNum = 0;
  390. for (var i = 0; i < this.action.clickData.length; i++) {
  391. var item = this.action.clickData[i];
  392. if (item.find) {
  393. correctNum = correctNum + 1
  394. }
  395. }
  396. this.action.correctNum = correctNum;
  397. this.action.correctPecent = parseInt(correctNum * 100 / this.action.clickNum) ? parseInt(correctNum * 100 / this.action.clickNum) : 0;
  398. $("#totalNum").html(this.action.totalNum);
  399. $("#clickNum").html(this.action.clickNum);
  400. $("#correctNum").html(this.action.correctNum);
  401. $("#correctPecent").html(this.action.correctPecent);
  402. $("#currLevel").html(self.currIndex + 1);
  403. if (this.action.correctNum == this.action.totalNum) {
  404. self.gameNext()
  405. }
  406. if (this.action.clickNum > 6 && this.action.correctPecent < 60) {
  407. self.gameover('\u672c\u5173\u60a8\u7684\u6b63\u786e\u7387\u4f4e\u4e8e60%\uff0c\u8fc7\u5173\u5931\u8d25\uff01\u518d\u6765\u4e00\u5c40\uff1f<br><div style=\'text-align:left;color:#999;\'> \u5173\u6ce8\u516c\u4f17\u53f7 <a href="http://mp.weixin.qq.com/s?__biz=MjM5OTE3NDIzMg==&mid=200696073&idx=1&sn=f3c6abd9de1873662d66da120029e9ed&scene=1&from=singlemessage&isappinstalled=0#rd"><strong style="color:red;">金华美食</strong></a> ,<br>第一时间畅玩微信游戏!</div>')
  408. }
  409. },
  410. startTimer: function() {
  411. var self = this;
  412. this.timer = setInterval(function() {
  413. self.second = self.second + 1;
  414. var percent = Math.max(parseInt((self.maxSecond - self.second) * 100 / self.maxSecond), 0);
  415. var color = "#86e01e";
  416. //if(this.action.correctNum==this.action.totalNum){self.gameNext()}if(this.action.clickNum>6&&this.action.correctPecent<60){self.gameover('\u672c\u5173\u60a8\u7684\u6b63\u786e\u7387\u4f4e\u4e8e60%\uff0c\u8fc7\u5173\u5931\u8d25\uff01\u518d\u6765\u4e00\u5c40\uff1f<br><div style=\'text-align:left;color:#999;\'> \u5173\u6ce8\u516c\u4f17\u53f7 <a href="http://mp.weixin.qq.com/s?__biz=MjM5OTcwNTY1Mg==&mid=200677693&idx=1&sn=b815f48b745879db7447a567f4f1e47a#rd"><strong style="color:red;">linanwsh</strong></a> ,<br>\u7b2c\u4e00\u65f6\u95f4\u7545\u73a9\u539f\u521b\u6e38\u620f\uff01</div>')}},startTimer:function(){var self=this;this.timer=setInterval(function(){self.second=self.second+1;var percent=Math.max(parseInt((self.maxSecond-self.second)*100/self.maxSecond),0);var color="#86e01e";
  417. if (percent > 80) {
  418. color = "#86e01e"
  419. } else if (percent > 60 && percent <= 80) {
  420. color = "#f2d31b"
  421. } else if (percent > 40 && percent <= 60) {
  422. color = "#f2b01e"
  423. } else if (percent > 20 && percent <= 40) {
  424. color = "#f27011"
  425. } else if (percent <= 20) {
  426. color = "#f63a0f"
  427. }
  428. $("#progressbar").css({
  429. width: percent + "%",
  430. "background-color": color
  431. });
  432. $("#timeshow").html(self.maxSecond - self.second);
  433. if (percent == 0) {
  434. self.gameover('\u672c\u5173\u60a8\u6ca1\u57281\u5206\u949f\u5185\u5b8c\u6210\uff0c\u8fc7\u5173\u5931\u8d25\uff01\u518d\u6765\u4e00\u5c40\uff1f<br><div style=\'text-align:left;color:#999;\'> \u5173\u6ce8\u516c\u4f17\u53f7 <a href="http://mp.weixin.qq.com/s?__biz=MjM5OTE3NDIzMg==&mid=200696073&idx=1&sn=f3c6abd9de1873662d66da120029e9ed&scene=1&from=singlemessage&isappinstalled=0#rd"><strong style="color:red;">金华美食</strong></a> ,<br>第一时间畅玩微信游戏!</div>')
  435. }
  436. }, 1e3)
  437. },
  438. stopTimer: function() {
  439. clearInterval(this.timer)
  440. },
  441. gamestart: function() {
  442. if (this.timer) {
  443. this.stopTimer()
  444. }
  445. this.action = {
  446. totalNum: 0,
  447. clickNum: 0,
  448. correctNum: 0,
  449. correctPecent: 0,
  450. timerPasser: 0,
  451. clickData: null
  452. };
  453. this.timer = null;
  454. this.second = 0;
  455. this.maxSecond = 60;
  456. $("#leftpic").empty();
  457. $("#rightpic").empty();
  458. this.init(this.currIndex);
  459. this.startTimer()
  460. },
  461. gameNext: function() {
  462. var self = this;
  463. var title = "";
  464. var msg = "";
  465. if (picimgs.length - 1 == this.currIndex) {
  466. title = "\u606d\u559c\u4f60\uff01\u4f60\u6253\u901a\u5173\u5566\uff01";
  467. msg = "\u4f60\u771f\u662f\u9738\u6c14\u4fa7\u6f0f\u7684\u5927\u82f1\u96c4\uff0c\u7f8e\u4eba\u5173\u7b2c2\u5b63\u5df2\u7ecf\u5168\u90e8\u6253\u901a\u4e86\uff01";
  468. dialog.dialog({
  469. title: title,
  470. content: msg,
  471. buttons: {
  472. close: {
  473. title: "\u6211\u597d\u68d2\uff01\u5fc5\u987b\u70ab\u8000\u4e00\u4e0b",
  474. click: function() {
  475. self.showShare(function() {
  476. self.currIndex = 0;
  477. self.gamestart()
  478. });
  479. dataForWeixin = {
  480. appId: "",
  481. MsgImg: share_img,
  482. TLImg: share_img,
  483. url: share_url,
  484. title: "\u82f1\u96c4\u96be\u8fc7\u7f8e\u4eba\u5173\u7b2c2\u5b63\uff01\u6211\u5df2\u901a\u5173\u5566\uff01\u9738\u6c14\u4fa7\u6f0f\uff01\u4f60\u80fd\u8fc7\u51e0\u5173\uff1f",
  485. desc: "\u6211\u5df2\u7ecf\u901a\u5173\u5566\uff01" + (self.currIndex + 1) + "\u4e2a\u7f8e\u4eba\u5173\u5168\u8fc7\uff01\u6211\u624d\u662f\u9738\u6c14\u4fa7\u6f0f\u6167\u773c\u8bc6\u7f8e\u4eba\u7684\u5927\u82f1\u96c4\uff0c\u4f60\u80fd\u8fc7\u51e0\u5173\uff1f",
  486. desc_tl: "\u6211\u5df2\u7ecf\u901a\u5173\u5566\uff01" + (self.currIndex + 1) + "\u4e2a\u7f8e\u4eba\u5173\u5168\u8fc7\uff01\u6211\u624d\u662f\u9738\u6c14\u4fa7\u6f0f\u6167\u773c\u8bc6\u7f8e\u4eba\u7684\u5927\u82f1\u96c4\uff0c\u4f60\u80fd\u8fc7\u51e0\u5173\uff1f",
  487. fakeid: "",
  488. callback: function() {}
  489. }
  490. }
  491. }
  492. }
  493. })
  494. } else {
  495. title = "\u606d\u559c\u8fc7\u7b2c" + (self.currIndex + 1) + "\u5173";
  496. msg = "\u4f60\u4e00\u5171\u627e\u51fa\u4e86" + this.action.correctNum + "\u4e2a\u4e0d\u540c\uff0c\u6b63\u786e\u7387" + this.action.correctPecent + "%,\u8017\u65f6" + this.second + "\u79d2!";
  497. dialog.dialog({
  498. title: title,
  499. content: msg,
  500. buttons: {
  501. confirm: {
  502. title: "\u518d\u8fc7\u4e00\u5173",
  503. click: function() {
  504. dataForWeixin = {
  505. appId: "",
  506. MsgImg: share_img,
  507. TLImg: share_img,
  508. url: share_url,
  509. title: "\u82f1\u96c4\u96be\u8fc7\u7f8e\u4eba\u5173\u7b2c2\u5b63\uff01\u6211\u5df2\u8fc7" + (self.currIndex + 1) + "\u4e2a\u7f8e\u4eba\u5173\uff0c\u4f60\u80fd\u8fc7\u51e0\u5173\uff1f",
  510. desc: "\u6211\u5df2\u8fc7\u4e86" + (self.currIndex + 1) + "\u4e2a\u7f8e\u4eba\u5173\uff0c\u672c\u5173\u6b63\u786e\u7387" + self.action.correctPecent + "%,\u8017\u65f6" + self.second + "\u79d2!",
  511. desc_tl: "\u6211\u5df2\u8fc7\u4e86" + (self.currIndex + 1) + "\u4e2a\u7f8e\u4eba\u5173\uff0c\u672c\u5173\u6b63\u786e\u7387" + self.action.correctPecent + "%,\u8017\u65f6" + self.second + "\u79d2!",
  512. fakeid: "",
  513. callback: function() {}
  514. };
  515. self.currIndex = self.currIndex + 1;
  516. self.gamestart()
  517. }
  518. },
  519. close: {
  520. title: "\u70ab\u8000\u4e00\u4e0b",
  521. click: function() {
  522. self.showShare(function() {
  523. self.currIndex = self.currIndex + 1;
  524. self.gamestart()
  525. });
  526. dataForWeixin = {
  527. appId: "",
  528. MsgImg: share_img,
  529. TLImg: share_img,
  530. url: share_url,
  531. title: "\u82f1\u96c4\u96be\u8fc7\u7f8e\u4eba\u5173\u7b2c2\u5b63\uff01\u6211\u5df2\u8fc7" + (self.currIndex + 1) + "\u4e2a\u7f8e\u4eba\u5173\uff0c\u4f60\u80fd\u8fc7\u51e0\u5173\uff1f",
  532. desc: "\u6211\u5df2\u8fc7\u4e86" + (self.currIndex + 1) + "\u4e2a\u7f8e\u4eba\u5173\uff0c\u672c\u5173\u6b63\u786e\u7387" + self.action.correctPecent + "%,\u8017\u65f6" + self.second + "\u79d2!",
  533. desc_tl: "\u6211\u5df2\u8fc7\u4e86" + (self.currIndex + 1) + "\u4e2a\u7f8e\u4eba\u5173\uff0c\u672c\u5173\u6b63\u786e\u7387" + self.action.correctPecent + "%,\u8017\u65f6" + self.second + "\u79d2!",
  534. fakeid: "",
  535. callback: function() {}
  536. }
  537. }
  538. }
  539. }
  540. })
  541. }
  542. self.stopTimer()
  543. },
  544. gamefinish: function() {},
  545. gameover: function(optmsg) {
  546. var self = this;
  547. var msg = optmsg;
  548. dialog.dialog({
  549. title: "GAME OVER",
  550. content: msg,
  551. buttons: {
  552. confirm: {
  553. title: "\u518d\u6765\u4e00\u5c40",
  554. click: function() {
  555. self.currIndex = 0;
  556. self.gamestart()
  557. }
  558. },
  559. close: {
  560. title: "\u70ab\u8000\u4e00\u4e0b",
  561. click: function() {
  562. dataForWeixin = {
  563. appId: "",
  564. MsgImg: share_img,
  565. TLImg: share_img,
  566. url: share_url,
  567. title: "\u82f1\u96c4\u96be\u8fc7\u7f8e\u4eba\u5173\u7b2c2\u5b63\uff01\u6211\u5df2\u8fc7" + self.currIndex + "\u4e2a\u7f8e\u4eba\u5173\uff0c\u4f60\u80fd\u8fc7\u51e0\u5173\uff1f",
  568. desc: "\u6211\u5df2\u8fc7\u4e86" + self.currIndex + "\u4e2a\u7f8e\u4eba\u5173\uff0c\u672c\u5173\u6b63\u786e\u7387" + self.action.correctPecent + "%,\u8017\u65f6" + self.second + "\u79d2!",
  569. desc_tl: "\u6211\u5df2\u8fc7\u4e86" + self.currIndex + "\u4e2a\u7f8e\u4eba\u5173\uff0c\u672c\u5173\u6b63\u786e\u7387" + self.action.correctPecent + "%,\u8017\u65f6" + self.second + "\u79d2!",
  570. fakeid: "",
  571. callback: function() {}
  572. };
  573. self.showShare(function() {
  574. self.currIndex = 0;
  575. self.gamestart()
  576. })
  577. }
  578. }
  579. }
  580. });
  581. self.stopTimer()
  582. },
  583. showShare: function(callback) {
  584. $("#share").show();
  585. $("#share").click(function() {
  586. $(this).hide();
  587. callback()
  588. })
  589. }
  590. };
  591. var dataForWeixin = {
  592. appId: "",
  593. MsgImg: share_img,
  594. TLImg: share_img,
  595. url: share_url,
  596. title: "\u82f1\u96c4\u96be\u8fc7\u7f8e\u4eba\u5173\u7b2c2\u5b63,\u5168\u65b018\u4f4d\u7f8e\u5973\uff0c\u7b49\u4f60\u6765\u6311\u6218\uff01",
  597. desc: "\u6211\u8fc7\u4e860\u5173\uff0c\u4f60\u80fd\u8fc7\u51e0\u5173\uff1f\u63a8\u8350\u5f15\u7206\u75af\u72c2\u8f6c\u53d1\u7684\u7f8e\u5973\u627e\u832c\u7c7b\u6e38\u620f\uff0c\u5c0f\u4f19\u4f34\u5feb\u6765\u6311\u6218\u5427\uff01",
  598. desc_tl: "\u6211\u8fc7\u4e860\u5173\uff0c\u4f60\u80fd\u8fc7\u51e0\u5173\uff1f\u63a8\u8350\u5f15\u7206\u75af\u72c2\u8f6c\u53d1\u7684\u7f8e\u5973\u627e\u832c\u7c7b\u6e38\u620f\uff0c\u5c0f\u4f19\u4f34\u5feb\u6765\u6311\u6218\u5427\uff01",
  599. fakeid: "",
  600. callback: function() {}
  601. };
  602. ! function() {
  603. var onBridgeReady = function() {
  604. WeixinJSBridge.on("menu:share:appmessage", function(argv) {
  605. WeixinJSBridge.invoke("sendAppMessage", {
  606. appid: dataForWeixin.appId,
  607. img_url: dataForWeixin.MsgImg,
  608. img_width: "120",
  609. img_height: "120",
  610. link: dataForWeixin.url,
  611. desc: dataForWeixin.desc,
  612. title: dataForWeixin.title
  613. }, function(res) {
  614. dataForWeixin.callback()
  615. })
  616. });
  617. WeixinJSBridge.on("menu:share:timeline", function(argv) {
  618. dataForWeixin.callback();
  619. WeixinJSBridge.invoke("shareTimeline", {
  620. img_url: dataForWeixin.TLImg,
  621. img_width: "120",
  622. img_height: "120",
  623. link: dataForWeixin.url,
  624. desc: dataForWeixin.desc_tl,
  625. title: dataForWeixin.title
  626. }, function(res) {})
  627. });
  628. WeixinJSBridge.on("menu:share:weibo", function(argv) {
  629. WeixinJSBridge.invoke("shareWeibo", {
  630. content: dataForWeixin.title,
  631. url: dataForWeixin.url
  632. }, function(res) {
  633. dataForWeixin.callback()
  634. })
  635. });
  636. WeixinJSBridge.on("menu:share:facebook", function(argv) {
  637. dataForWeixin.callback();
  638. WeixinJSBridge.invoke("shareFB", {
  639. img_url: dataForWeixin.TLImg,
  640. img_width: "120",
  641. img_height: "120",
  642. link: dataForWeixin.url,
  643. desc: dataForWeixin.desc,
  644. title: dataForWeixin.title
  645. }, function(res) {})
  646. })
  647. };
  648. if (document.addEventListener) {
  649. document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false)
  650. } else if (document.attachEvent) {
  651. document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
  652. document.attachEvent("onWeixinJSBridgeReady", onBridgeReady)
  653. }
  654. }();