main.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. var memory;
  2. null == memory && (memory = {});
  3. var game;
  4. null == game && (game = {});
  5. (function () {
  6. Array.prototype.indexOf = function (a) {
  7. for (var b = 0; b < this.length; b++) {
  8. if (this[b] == a) {
  9. return b;
  10. }
  11. }
  12. return -1;
  13. };
  14. Array.prototype.remove = function (a) {
  15. a = this.indexOf(a);
  16. -1 < a && this.splice(a, 1);
  17. };
  18. Array.prototype.shuffle = function () {
  19. for (var a = this.length, b = 0; b < a; b++) {
  20. var c = Math.randomInt(a - b);
  21. this.push(this[c]);
  22. this.splice(c, 1);
  23. }
  24. console.log(this);
  25. };
  26. Array.prototype.clear = function () {
  27. this.length = 0;
  28. };
  29. Math.randomInt = function (a) {
  30. return parseInt(Math.random() * a);
  31. };
  32. })();
  33. (function () {
  34. game.qp_a = function (a) {
  35. return game.queue.getResult(a);
  36. };
  37. game.qp_b = function (a, b) {
  38. a = a * W / 4 + W / 8 + 2 * a;
  39. b = b * W / 4 + W / 8 + 4 * (b + 3);
  40. return [a, b];
  41. };
  42. game.qp_c = function (a) {
  43. if (2 <= game.arrOpenedCard.length) {
  44. for (; 0 < game.arrOpenedCard.length; ) {
  45. game.arrOpenedCard.pop().close();
  46. }
  47. }
  48. game.arrOpenedCard.push(a);
  49. };
  50. game.qp_d = function (a) {
  51. 1 == game.arrOpenedCard.length && a.cid == game.arrOpenedCard[0].cid ? (a.dismiss(function () {
  52. game.score += 1;
  53. createjs.Sound.play("bonus", !0);
  54. 0 >= game.gv.getNumChildren() && (game.qp_e(), game.score += 5);
  55. }), game.arrOpenedCard.pop().dismiss()) : game.qp_c(a);
  56. };
  57. game.qp_e = function () {
  58. game.arrOpenedCard = [];
  59. game.gv.clearCard();
  60. game.gv.mouseChildren = !0;
  61. for (var a = [], b = 0; 10 > b; b++) {
  62. a[2 * b] = a[2 * b + 1] = b % 6 + 1;
  63. }
  64. a.shuffle();
  65. game.gv.setupCard(a);
  66. };
  67. game.qp_f = function () {
  68. game.countDown = memory.qp_g;
  69. game.score = 0;
  70. game.gv.clearCard();
  71. game.view.ready(function () {
  72. game.qp_e();
  73. game.interval = setInterval(function () {
  74. game.countDown -= 1;
  75. 0 >= game.countDown && game.qp_h();
  76. }, 1000);
  77. });
  78. };
  79. game.qp_h = function () {
  80. clearInterval(game.interval);
  81. game.gv.mouseChildren = !1;
  82. game.view.addChild(new memory.Qp_i);
  83. score = game.score;
  84. onNewScore(score);
  85. };
  86. })();
  87. (function () {
  88. memory.qp_j = 4;
  89. memory.qp_k = 5;
  90. memory.qp_g = 60;
  91. memory.Qp_l = function () {
  92. this.initialize();
  93. this.x = this.y = 0;
  94. this.addChild(new createjs.Bitmap(game.qp_a("bg")));
  95. var a = new createjs.Bitmap;
  96. a.regX = 290;
  97. a.regY = 80;
  98. a.x = 320;
  99. a.y = 450;
  100. this.ready = function (b) {
  101. a.image = game.qp_a("ready");
  102. this.addChild(a);
  103. a.scaleX = a.scaleY = 3;
  104. a.regX = a.getBounds().width / 2;
  105. a.regY = a.getBounds().height / 2;
  106. a.alpha = 0;
  107. createjs.Tween.get(a).to({alpha:1, scaleX:1, scaleY:1}, 300).to({}, 900).call(function () {
  108. a.image = game.qp_a("go");
  109. a.regX = a.getBounds().width / 2;
  110. a.regY = a.getBounds().height / 2;
  111. createjs.Tween.get(a).to({scaleX:1}, 300).to({alpha:0}, 200).call(function () {
  112. a.parent.removeChild(a);
  113. b();
  114. });
  115. });
  116. };
  117. };
  118. memory.Qp_m = function () {
  119. this.initialize();
  120. this.x = W / 2;
  121. this.y = H / 2;
  122. this.regX = W / 2;
  123. this.regY = H / 3;
  124. this.scaleX = this.scaleY = 0.9;
  125. this.setupCard = function (a) {
  126. for (var b = 0; b < a.length; b++) {
  127. var c = parseInt(b / memory.qp_k), c = new memory.Qp_n(c, b % memory.qp_k, a[b]);
  128. this.addChild(c);
  129. }
  130. };
  131. this.clearCard = function () {
  132. this.removeAllChildren();
  133. };
  134. };
  135. memory.Qp_o = function () {
  136. this.initialize();
  137. var a = new createjs.Text("0", "bold 49px Arial", "#ff0000");
  138. a.x = 200;
  139. var b = new createjs.Text(memory.qp_g, "bold 49px Arial", "#ff0000");
  140. b.x = 500;
  141. a.y = b.y = H / 8 / 2;
  142. a.regY = b.regY = a.getBounds().height / 2;
  143. this.addChild(a, b);
  144. this.on("tick", function (c) {
  145. a.text = game.score;
  146. b.text = game.countDown;
  147. });
  148. };
  149. memory.Qp_n = function (a, b, c) {
  150. this.initialize();
  151. this.x = game.qp_b(a, b)[0];
  152. this.y = game.qp_b(a, b)[1];
  153. this.scaleX = this.scaleY = this.initScale = 150 / 130;
  154. this.cid = c;
  155. this.mouseChildren = !1;
  156. a = new createjs.Bitmap(game.qp_a(c));
  157. a.name = "bm";
  158. var d = new createjs.Bitmap(game.qp_a("back"));
  159. d.name = "back";
  160. var e = new createjs.Shape;
  161. e.name = "frame";
  162. e.graphics.beginFill("#888888").drawRect(8, 8, a.getBounds().width + 2, a.getBounds().height + 2).endFill();
  163. e.graphics.beginStroke("#888888").setStrokeStyle(10).drawRect(2, 2, a.getBounds().width - 2, a.getBounds().height - 2).endStroke();
  164. e.visible = !1;
  165. this.regX = d.getBounds().width / 2;
  166. this.regY = d.getBounds().height / 2;
  167. this.addChild(e, a, d);
  168. this.onClick(function (a) {
  169. a.target.open();
  170. });
  171. this.open = function () {
  172. d.visible && (this.mouseEnabled = !1, createjs.Tween.get(this).to({scaleX:0}, 50).call(function () {
  173. d.visible = !1;
  174. e.visible = !0;
  175. createjs.Tween.get(this).to({scaleX:this.initScale}, 50).call(function () {
  176. game.qp_d(this);
  177. this.mouseEnabled = !0;
  178. });
  179. }), createjs.Sound.play("flip", !0));
  180. };
  181. this.close = function () {
  182. d.visible || (this.mouseEnabled = !1, createjs.Tween.get(this).to({scaleX:0}, 50).call(function () {
  183. d.visible = !0;
  184. e.visible = !1;
  185. createjs.Tween.get(this).to({scaleX:this.initScale}, 50).call(function () {
  186. this.mouseEnabled = !0;
  187. });
  188. }));
  189. };
  190. this.dismiss = function (a) {
  191. createjs.Tween.get(this).wait(200).to({rotation:1080, scaleX:0, scaleY:0}, 100).call(function () {
  192. this.parent.removeChild(this);
  193. a && a();
  194. });
  195. };
  196. };
  197. memory.Qp_i = function () {
  198. this.initialize();
  199. this.setBounds(0, 0, W, H);
  200. var a = new createjs.Bitmap(game.qp_a("gameover"));
  201. a.regX = 180;
  202. a.regY = 30;
  203. a.x = 320;
  204. a.y = 170;
  205. var b = new createjs.Bitmap(game.qp_a("curscore"));
  206. b.y = 260;
  207. var c = new createjs.Bitmap(game.qp_a("bestscore"));
  208. c.y = 380;
  209. b.x = c.x = 90;
  210. var d = new createjs.Text(game.score, "bold 48px Arial", "#ff1e50");
  211. d.y = 300;
  212. var e = new createjs.Text(0 > best ? 0 : best, "bold 48px Arial", "#ff1e50");
  213. e.y = 410;
  214. d.x = e.x = 400;
  215. d.textBaseline = e.textBaseline = "middle";
  216. var f = new createjs.Bitmap(game.qp_a("replaybtn"));
  217. f.x = 200;
  218. var g = new createjs.Bitmap(game.qp_a("toplistbtn"));
  219. g.x = 440;
  220. f.regX = g.regX = 115;
  221. f.regY = g.regY = 40;
  222. f.y = g.y = 540;
  223. var h = new createjs.Bitmap(game.qp_a("sharebtn"));
  224. h.regX = 125;
  225. h.regY = 42;
  226. h.x = 320;
  227. h.y = 670;
  228. var l = new createjs.Shape, k = this.getBounds();
  229. l.graphics.beginFill("#ffffff").drawRect(k.x, k.y, k.width, k.height);
  230. l.alpha = 0.8;
  231. this.addChild(l, a, b, c, d, e, f, g, h);
  232. f.onClick(function (a) {
  233. game.view.removeChild(a.target.parent);
  234. game.qp_f();
  235. });
  236. g.onClick(function (a) {
  237. goHome();
  238. });
  239. h.onClick(function (a) {
  240. dp_share();
  241. });
  242. };
  243. memory.Qp_m.prototype = new createjs.Container;
  244. memory.Qp_o.prototype = new createjs.Container;
  245. memory.Qp_n.prototype = new createjs.Container;
  246. memory.Qp_i.prototype = new createjs.Container;
  247. memory.Qp_l.prototype = new createjs.Container;
  248. createjs.DisplayObject.prototype.onClick = function (a) {
  249. this.on("click", function (b) {
  250. createjs.Touch.isSupported() && b.nativeEvent.constructor == MouseEvent || a(b);
  251. });
  252. };
  253. })();
  254. var queue;
  255. function loadResource() {
  256. SCREEN_SHOW_ALL = !0;
  257. H = 1000;
  258. var a = new ProgressBar(0.8 * W, 40);
  259. a.regX = a.w / 2;
  260. a.regY = a.h / 2;
  261. a.x = W / 2;
  262. a.y = H / 2;
  263. stage.addChild(a);
  264. queue = game.queue = new createjs.LoadQueue(!1);
  265. queue.setMaxConnections(30);
  266. loadGameData();
  267. queue.on("complete", setup, null, !0);
  268. queue.loadManifest({path:RES_DIR + "img/", manifest:[{src:"1.jpg", id:"1"}, {src:"2.jpg", id:"2"}, {src:"3.jpg", id:"3"}, {src:"4.jpg", id:"4"}, {src:"5.jpg", id:"5"}, {src:"6.jpg", id:"6"}, {src:"frame.png", id:"frame"}, {src:"back.png", id:"back"}, {src:"ready.png", id:"ready"}, {src:"go.png", id:"go"}, {src:"bg.png", id:"bg"}, {src:"topline.png", id:"topline"}, {src:"bestscore.png", id:"bestscore"}, {src:"curscore.png", id:"curscore"}, {src:"gameover.png", id:"gameover"}, {src:"replaybtn.png", id:"replaybtn"}, {src:"sharebtn.png", id:"sharebtn"}, {src:"toplistbtn.png", id:"toplistbtn"}]}, !1);
  269. USE_NATIVE_SOUND || (IS_NATIVE_ANDROID ? (createjs.Sound.registMySound("flip", 0), createjs.Sound.registMySound("bonus", 2), createjs.Sound.registMySound("silenttail", 4), queue.loadFile({id:"sound", src:RES_DIR + "audio/all.mp3"})) : (createjs.Sound.alternateExtensions = ["ogg"], queue.installPlugin(createjs.Sound), queue.loadManifest({path:RES_DIR + "audio/", manifest:[{src:"flip.mp3", id:"flip"}, {src:"bonus.mp3", id:"bonus"}]}, !1)));
  270. a.forQueue(queue);
  271. queue.load();
  272. }
  273. function setup() {
  274. game.view = new memory.Qp_l;
  275. game.gv = new memory.Qp_m;
  276. game.sv = new memory.Qp_o;
  277. game.view.addChild(game.gv, game.sv);
  278. stage.addChild(game.view);
  279. game.qp_f();
  280. }