index.js 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. gameurl = 'http://game.ikongzhong.cn/games/coreball/';
  2. imgUrl = "http://game.ikongzhong.cn/games/coreball/icon.png";
  3. openid = '';
  4. var reg = new RegExp("[?&]" + 'openid' + "=([^?&]*)[&]?", "i");
  5. var match = window.location.search.match(reg);
  6. match == null ? "" : match[1];
  7. if (match) {
  8. openid = match[1];
  9. }
  10. "undefined" == typeof window.define && (window.define = function() {}, window.define.amd = 1),
  11. "undefined" == typeof window.$AJB && (window.$AJB = {}),
  12. $AJB.lib = {},
  13. $AJB.general = {},
  14. $AJB.page = {},
  15. $AJB.lib.stopEvent = function() {
  16. "use strict";
  17. return function(a) {
  18. a && (a.preventDefault ? (a.preventDefault(), a.stopPropagation()) : (a.returnValue = !1, a.cancelBubble = !0))
  19. }
  20. },
  21. $AJB.lib.Storage = function() {
  22. "use strict";
  23. var a = {
  24. setValue: function(a, b) {
  25. window.localStorage && (window.localStorage[a] = b)
  26. },
  27. getValue: function(a) {
  28. return window.localStorage ? window.localStorage[a] : void 0
  29. }
  30. };
  31. return a
  32. },
  33. $AJB.general.BeginStage = function() {
  34. "use strict";
  35. function a(a) {
  36. function c() {
  37. b(h, "click", function() {
  38. e.fire(g, f)
  39. }),
  40. j.innerHTML = d.isAndroid ? "GO" : ""
  41. }
  42. var h = a.getElementsByClassName("button")[0],
  43. i = a.getElementsByClassName("text")[0],
  44. j = document.getElementById("txtAr"),
  45. k = {
  46. show: function() {
  47. a.style.display = ""
  48. },
  49. hide: function() {
  50. a.style.display = "none"
  51. },
  52. level: function(a) {
  53. f = a,
  54. i.innerHTML = "level " + a
  55. },
  56. on: function(a, b) {
  57. e.add(a, b)
  58. },
  59. off: function(a, b) {
  60. e.remove(a, b)
  61. }
  62. };
  63. return c(),
  64. k
  65. }
  66. var b = $AJB.lib.addEvent(),
  67. c = $AJB.lib.CustEvent(),
  68. d = $AJB.lib.util(),
  69. e = c(),
  70. f = 0,
  71. g = "start";
  72. return a
  73. },
  74. $AJB.general.Switcher = function() {
  75. "use strict";
  76. function a(a, b, c) {
  77. var d, e, f = null,
  78. g = !1,
  79. h = {
  80. point: [0, 0],
  81. enabled: !1,
  82. color: "#c8c8c8",
  83. update: function() {
  84. var a = h.point,
  85. c = 30;
  86. h.enabled && (0 === e ? (d = h.color, a[0] < b / 2 ? (a[0] = Math.min(a[0] + c, b / 2), h.point = a) : (h.point = a, g = !0)) : 1 === e && (d = "#000", a[0] > b / 2 ? (a[0] = Math.max(a[0] - c, b / 2), h.point = a) : (h.point = a, g = !0)))
  87. },
  88. render: function() {
  89. var e = h.point;
  90. h.enabled && (a.fillStyle = d, a.fillRect(e[0] - b / 2, e[1] - c / 2, b, c), g && (h.enabled = !1, f && f()))
  91. },
  92. switchStage: function(d, i) {
  93. 0 === d ? h.point = [-b / 2, c / 2] : 1 === d && (a.fillStyle = h.color, a.fillRect(0, 0, b, c), h.point = [b + b / 2, c / 2]),
  94. h.enabled = !0,
  95. g = !1,
  96. e = d,
  97. f = i
  98. }
  99. };
  100. return h
  101. }
  102. return a
  103. },
  104. $AJB.lib.addEvent = function() {
  105. var a = $AJB.lib.util(),
  106. b = {
  107. click: "touchstart",
  108. mousedown: "touchstart",
  109. mouseup: "touchend"
  110. };
  111. return function(c, d, e, f) {
  112. c.addEventListener ? c.addEventListener(a.isMobile ? b[d] || d : d, e, f) : c.attachEvent ? c.attachEvent("on" + d, e) : c["on" + d] = e
  113. }
  114. },
  115. $AJB.general.Levels = function() {
  116. "use strict";
  117. function a(a, b) {
  118. return function() {
  119. var c = 0;
  120. return function() {
  121. return c += a * b % 360
  122. }
  123. }
  124. }
  125. function b(a, b) {
  126. return function() {
  127. var c = 0,
  128. d = 1,
  129. e = +new Date;
  130. return function() {
  131. var f = +new Date;
  132. return f - e > b && (d = -d, e = f),
  133. c += d * a % 360
  134. }
  135. }
  136. }
  137. function c(a, b, c, d) {
  138. return function() {
  139. var e = 0,
  140. f = +new Date;
  141. return function() {
  142. var g = +new Date;
  143. return g - f > c && (a = b - a, f = g),
  144. e += a * d % 360
  145. }
  146. }
  147. }
  148. function d(a) {
  149. var b = 1;
  150. return h(document.body, "mousedown", function() {
  151. b = -b
  152. }),
  153. function() {
  154. var c = 0;
  155. return function() {
  156. return c += a * b % 360
  157. }
  158. }
  159. }
  160. function e(a, b, c, d) {
  161. return h(document.body, "mousedown", function() {
  162. d = -d
  163. }),
  164. function() {
  165. var e = 0,
  166. f = +new Date;
  167. return function() {
  168. var g = +new Date;
  169. return g - f > c && (a = b - a, f = g),
  170. e += a * d % 360
  171. }
  172. }
  173. }
  174. function f(a, b, c, d) {
  175. i[a] = {
  176. childs: k[b],
  177. queueCount: c,
  178. round: j[d]
  179. }
  180. }
  181. var g, h = $AJB.lib.addEvent(),
  182. i = {},
  183. j = {
  184. A1: a(1.5, 1),
  185. A2: a(1.5, -1),
  186. B1: a(2.5, 1),
  187. B2: a(2.5, -1),
  188. C1: b(2.2, 3e3),
  189. C2: b(3.5, 2e3),
  190. D1: c(2, 2.3, 1200, 1),
  191. D2: c(2, 2.3, 1200, -1),
  192. D3: c(4, 4.5, 1700, 1),
  193. D4: c(4, 4.5, 1700, -1),
  194. D5: c(4, 4.5, 1700, 1),
  195. D6: c(4, 4.5, 1700, -1),
  196. E1: d(2),
  197. E2: e(2, 2.3, 1e3, 1)
  198. },
  199. k = {
  200. 0: [],
  201. 2: [0, 180],
  202. 3: [0, 120, 240],
  203. 4: [0, 90, 180, 270],
  204. 5: [0, 72, 144, 216, 288],
  205. 6: [0, 60, 120, 180, 240, 300],
  206. 7: [0, 52, 103, 155, 206, 258, 309],
  207. 8: [0, 45, 90, 135, 180, 225, 270, 315],
  208. 9: [0, 40, 80, 120, 160, 200, 240, 280, 320],
  209. 10: [0, 36, 72, 108, 144, 180, 216, 252, 288, 324],
  210. 11: [0, 33, 66, 99, 131, 164, 197, 230, 262, 295, 328],
  211. 12: [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330],
  212. 13: [0, 28, 56, 84, 111, 139, 167, 194, 222, 250, 277, 305, 333],
  213. 14: [0, 26, 52, 78, 103, 129, 155, 180, 206, 232, 258, 283, 309, 335],
  214. 15: [0, 24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336],
  215. 16: [0, 23, 45, 68, 90, 113, 135, 158, 180, 203, 225, 248, 270, 293, 315, 338]
  216. },
  217. l = {
  218. 1: ["4", 8, "A1"],
  219. 2: ["6", 10, "A1"],
  220. 3: ["2", 20, "A1"],
  221. 4: ["8", 12, "A2"],
  222. 5: ["12", 8, "A1"],
  223. 6: ["10", 10, "A2"],
  224. 7: ["12", 13, "A1"],
  225. 8: ["16", 3, "A2"],
  226. 9: ["0", 26, "A2"],
  227. 10: ["16", 10, "A1"],
  228. 11: ["10", 8, "B1"],
  229. 12: ["6", 12, "B2"],
  230. 13: ["12", 4, "B1"],
  231. 14: ["8", 14, "B2"],
  232. 15: ["8", 6, "B1"],
  233. 16: ["5", 10, "B2"],
  234. 17: ["6", 12, "B1"],
  235. 18: ["8", 14, "B2"],
  236. 19: ["0", 23, "B1"],
  237. 20: ["10", 13, "B2"],
  238. 21: ["4", 12, "C1"],
  239. 22: ["6", 10, "C1"],
  240. 23: ["8", 12, "C1"],
  241. 24: ["7", 14, "C1"],
  242. 25: ["2", 18, "C1"],
  243. 26: ["4", 18, "C1"],
  244. 27: ["0", 24, "C1"],
  245. 28: ["4", 10, "C2"],
  246. 29: ["6", 13, "C2"],
  247. 30: ["4", 20, "C1"],
  248. 31: ["6", 8, "D1"],
  249. 32: ["2", 12, "D2"],
  250. 33: ["3", 14, "D2"],
  251. 34: ["3", 18, "D1"],
  252. 35: ["8", 12, "D1"],
  253. 36: ["7", 15, "D2"],
  254. 37: ["16", 8, "D2"],
  255. 38: ["0", 23, "D1"],
  256. 39: ["12", 12, "D1"],
  257. 40: ["12", 15, "D2"],
  258. 41: ["5", 10, "E1"],
  259. 42: ["6", 12, "E1"],
  260. 43: ["3", 15, "E1"],
  261. 44: ["3", 19, "E1"],
  262. 45: ["0", 24, "E1"],
  263. 46: ["2", 15, "E2"],
  264. 47: ["4", 16, "E2"],
  265. 48: ["12", 8, "E2"],
  266. 49: ["3", 20, "E2"],
  267. 50: ["16", 14, "E2"],
  268. 51: ["4", 6, "D3"],
  269. 52: ["4", 12, "D4"],
  270. 53: ["6", 13, "D3"],
  271. 54: ["0", 24, "D4"],
  272. 55: ["4", 21, "D3"],
  273. 56: ["16", 16, "A1"],
  274. 57: ["4", 24, "C1"],
  275. 58: ["4", 26, "D1"],
  276. 59: ["4", 25, "E2"],
  277. 60: ["13", 19, "E2"]
  278. };
  279. for (g in l) f(g, l[g][0], l[g][1], l[g][2]);
  280. return i
  281. },
  282. $AJB.general.Collide = function() {
  283. "use strict";
  284. var a = $AJB.lib.util(),
  285. b = {
  286. check: function(b, c, d) {
  287. var e = b.childs(),
  288. f = e.length,
  289. g = Math.ceil(2 * c.rad());
  290. for (d = d || 1; f--;)
  291. if (c !== e[f].ball && a.getPointDistance(c.pos(), e[f].ball.pos()) <= g + Math.ceil(2 * d)) return !0;
  292. return !1
  293. }
  294. };
  295. return b
  296. },
  297. $AJB.general.Tween = function() {
  298. "use strict";
  299. var a = {
  300. simple: function(b, c, d, e) {
  301. var f = (c - b) / e,
  302. g = +new Date;
  303. return e > g - d ? (a.isEnd = !1, b + (g - d) * f) : (a.isEnd = !0, c)
  304. },
  305. isEnd: !0
  306. };
  307. return a
  308. },
  309. $AJB.general.BallQueue = function() {
  310. "use strict";
  311. function a(a, f, g, h, i) {
  312. function j() {
  313. var b, d, e = k(a),
  314. j = e.length;
  315. for (b = 0; j > b; b++) d = c(h, null, e[b], null, i),
  316. d.pos(f, g + 3 * d.rad() * b),
  317. m.push(d)
  318. }
  319. function k(a) {
  320. for (var b = a, c = []; b--;) c.push(b + 1);
  321. return c
  322. }
  323. var l, m = [],
  324. n = [],
  325. o = b();
  326. return i = i || 1,
  327. l = {
  328. ballList: m,
  329. add: function() {},
  330. remove: function(a) {
  331. var b = m[a];
  332. return m.splice(a, 1),
  333. b
  334. },
  335. clear: function() {
  336. n = [],
  337. m = []
  338. },
  339. popup: function() {
  340. var a = m.shift();
  341. a.st = +new Date,
  342. a.sv = a.pos().y,
  343. n.push(a)
  344. },
  345. update: function() {
  346. var a, b, c, h = n.length,
  347. i = m.length;
  348. if (h) {
  349. for (b = n[0].rad(), a = g - 3 * b; h--;) n[h].pos(f, d.simple(n[h].sv, a, n[h].st, 50)),
  350. c = n[n.length - 1].pos().y,
  351. n[h].pos().y === a && (o.fire(e, n[h]), n.splice(h, 1));
  352. for (; i--;) m[i].pos(f, c + 3 * b * (i + 1))
  353. }
  354. },
  355. render: function() {
  356. for (var a = m.length, b = n.length; a--;) m[a].render();
  357. for (; b--;) n[b].render()
  358. },
  359. on: function(a, b) {
  360. o.add(a, b)
  361. },
  362. off: function(a, b) {
  363. o.remove(a, b)
  364. },
  365. destroy: function() {
  366. for (var a = m.length; a--;) m[a].destroy();
  367. o.destroy()
  368. }
  369. },
  370. j(),
  371. l
  372. }
  373. var b = $AJB.lib.CustEvent(),
  374. c = $AJB.general.Ball(),
  375. d = $AJB.general.Tween(),
  376. e = "popup";
  377. return a
  378. },
  379. $AJB.general.Ball = function() {
  380. "use strict";
  381. function a(a, c, d, e, f) {
  382. function g() {
  383. var c = b.getTextWidth(a, 0, 0, d, e);
  384. b.drawText(a, i - c / 2, j + e / 3, d, e, "black")
  385. }
  386. var h, i = 0,
  387. j = 0;
  388. return f = f || 1,
  389. c = (c || 12) * f,
  390. e = (e || 15) * f,
  391. h = {
  392. pos: function(a, b) {
  393. return "undefined" != typeof a && (i = a),
  394. "undefined" != typeof b && (j = b), {
  395. x: i,
  396. y: j
  397. }
  398. },
  399. scale: function(a) {
  400. return "undefined" != typeof a && (f = a),
  401. f
  402. },
  403. rad: function(a) {
  404. return "undefined" != typeof a && (c = a),
  405. c
  406. },
  407. render: function(e) {
  408. b.drawCircle(a, i, j, c, "#ffffff"),
  409. "undefined" != typeof d ? g(d) : "undefined" != typeof e && g(e)
  410. },
  411. destroy: function() {
  412. h = null
  413. }
  414. }
  415. }
  416. var b = $AJB.lib.util();
  417. return a
  418. },
  419. $AJB.lib.util = function() {
  420. "use strict";
  421. return {
  422. drawCircle: function(a, b, c, d, e) {
  423. a.beginPath(),
  424. a.arc(b, c, d, 0, 2 * Math.PI, !1),
  425. a.fillStyle = e || "red",
  426. a.fill()
  427. },
  428. drawLine: function(a, b, c, d, e, f, g) {
  429. a.strokeStyle = f || "red",
  430. a.lineWidth = g || 1,
  431. a.beginPath(),
  432. a.moveTo(b, c),
  433. a.lineTo(d, e),
  434. a.stroke()
  435. },
  436. drawText: function(a, b, c, d, e, f) {
  437. a.font = e + "px Verdana",
  438. a.fillStyle = f || "red",
  439. a.fillText(d, b, c)
  440. },
  441. getTextWidth: function(a, b, c, d, e, f) {
  442. return a.font = e + "px Verdana",
  443. a.fillStyle = f || "red",
  444. a.measureText(d).width
  445. },
  446. getPointDistance: function(a, b) {
  447. return Math.floor(Math.sqrt(Math.floor(Math.pow(a.x - b.x, 2)) + Math.floor(Math.pow(a.y - b.y, 2))))
  448. },
  449. isMobile: /(mobile|iphone|ipod|ipad|ios|android|windows phone)/i.test(navigator.userAgent),
  450. isAndroid: /android/i.test(navigator.userAgent),
  451. isWeixin: /MicroMessenger/i.test(navigator.userAgent)
  452. }
  453. },
  454. $AJB.general.Core = function() {
  455. "use strict";
  456. function a(a, d, e, f, g) {
  457. function h() {
  458. for (var a, b, c, d, e = l.length; e--;) a = 3 * Math.cos((l[e].angle + j.angle()) * Math.PI / 180) * m * g + n,
  459. b = 3 * Math.sin((l[e].angle + j.angle()) * Math.PI / 180) * m * g + o,
  460. c = a / Math.abs(a),
  461. d = b / Math.abs(b),
  462. l[e].ball.pos(a, b)
  463. }
  464. var i, j, k = 0,
  465. l = [],
  466. m = 50,
  467. n = a.width / 2,
  468. o = 4 * m * g;
  469. return g = g || 1,
  470. i = c(d, m, e, f, g),
  471. i.pos(n, o),
  472. j = {
  473. pos: i.pos,
  474. scale: i.scale,
  475. rad: i.rad,
  476. angle: function(a) {
  477. return "undefined" != typeof a && (k = a),
  478. k
  479. },
  480. addChild: function(a, b) {
  481. l.push({
  482. angle: a,
  483. ball: b
  484. })
  485. },
  486. clear: function() {
  487. l = []
  488. },
  489. childs: function() {
  490. return l
  491. },
  492. update: function() {
  493. h()
  494. },
  495. render: function() {
  496. var c, e = l.length,
  497. f = a.width,
  498. h = a.height;
  499. for (d.clearRect(0, 0, f, h), c = 0; e > c; c++) b.drawLine(d, n, o, l[c].ball.pos().x, l[c].ball.pos().y, "#ffffff", 1.5 * g),
  500. l[c].ball.render();
  501. i.render()
  502. },
  503. destroy: function() {
  504. j.clear(),
  505. i = null,
  506. j = null
  507. }
  508. }
  509. }
  510. var b = $AJB.lib.util(),
  511. c = $AJB.general.Ball();
  512. return a
  513. },
  514. $AJB.lib.CustEvent = function() {
  515. return function(a) {
  516. function b(a) {
  517. return Object.prototype.toString.call(a).slice(8, -1).toLowerCase()
  518. }
  519. var c = {};
  520. return !a && (a = {}), {
  521. add: function(a, d) {
  522. if ("function" === b(d)) {
  523. var e = c;
  524. a = a.toLowerCase(), !e[a] && (e[a] = []),
  525. e[a].push(d)
  526. }
  527. },
  528. remove: function(a, d) {
  529. var e, f = c[a];
  530. if (a = a.toLowerCase(), "function" === b(d) && f && f.length)
  531. for (e = f.length - 1; e >= 0; e--) f[e] === d && f.splice(e, 1)
  532. },
  533. fire: function(b) {
  534. var d, e, f, g;
  535. if (b = b.toLowerCase(), d = c[b], d && d.length)
  536. for (e = Array.prototype.slice.call(arguments, 1), g = d.length, f = 0; g > f; f++) d[f].apply(a, e)
  537. },
  538. destroy: function() {
  539. var a, b = c.length - 1;
  540. for (a = b; a >= 0; a--) evts.splice(a, 1)
  541. }
  542. }
  543. }
  544. },
  545. $AJB.general.Scene = function() {
  546. "use strict";
  547. function a(a, b, l, m) {
  548. function n(a) {
  549. var g = a.childs,
  550. h = g.length;
  551. for (y = a.round(), w && w.destroy(), w = c(b, l, B, 50, m); h--;) w.addChild(g[h], d(l, null, "", null, m));
  552. x && x.destroy(),
  553. x = e(a.queueCount, b.width / 2, w.pos().y + 4 * w.rad(), l, m),
  554. x.on("popup", function(a) {
  555. w.addChild(90 - w.angle(), a),
  556. f.check(w, a, m) ? (z = a, s()) : !x.ballList.length && r()
  557. })
  558. }
  559. function o() {
  560. y && (w.angle(y()), w.update(), x.update())
  561. }
  562. function p() {
  563. var b, c, d, e, f = w.childs(),
  564. g = f.length,
  565. h = 25;
  566. for (a.style.backgroundColor = u.bgColor; g--;) b = f[g].angle + w.angle(),
  567. c = Math.cos(b * Math.PI / 180) * h,
  568. d = Math.sin(b * Math.PI / 180) * h,
  569. e = f[g].ball.pos(),
  570. f[g].ball.pos(e.x + c, e.y + d)
  571. }
  572. function q(a) {
  573. var b, c = [25, 15, 20, 15],
  574. d = c.length,
  575. e = 200,
  576. f = e / d;
  577. for (w.update(), b = 1; d >= b; b++) a > f * b && z.rad(c[b - 1] * m)
  578. }
  579. function r() {
  580. "pass" !== A && (a.style.backgroundColor = "#1CB01A", A = "pass", v = +new Date)
  581. }
  582. function s() {
  583. "fail" !== l && (a.style.backgroundColor = "#B8111C", A = "fail", v = +new Date)
  584. }
  585. function t() {
  586. var a = "to be continued...",
  587. c = h.getTextWidth(l, 0, 0, a, 30 * m);
  588. h.drawText(l, (b.width - c) / 2, 200 * m, a, 30 * m, "yellow")
  589. }
  590. var u, v, w, x, y, z, A = "run",
  591. B = 1;
  592. return u = {
  593. enabled: !1,
  594. run: function(b) {
  595. var c = g[b];
  596. B = b,
  597. c ? (u.enabled = !0, n(c), a.style.backgroundColor = "#000", A = "run") : t()
  598. },
  599. shot: function() {
  600. x && x.ballList.length && x.popup()
  601. },
  602. update: function() {
  603. var a;
  604. u.enabled && ("run" === A ? o() : "pass" === A ? (p(), +new Date - v > 1e3 && (A = "", k.fire(i))) : "fail" === A && (a = +new Date - v, q(a), a > 1e3 && (A = "", k.fire(j))))
  605. },
  606. render: function() {
  607. u.enabled && (w.render(), x.render())
  608. },
  609. on: function(a, b) {
  610. k.add(a, b)
  611. },
  612. off: function(a, b) {
  613. k.remove(a, b)
  614. }
  615. }
  616. }
  617. var b = $AJB.lib.CustEvent(),
  618. c = $AJB.general.Core(),
  619. d = $AJB.general.Ball(),
  620. e = $AJB.general.BallQueue(),
  621. f = $AJB.general.Collide(),
  622. g = $AJB.general.Levels(),
  623. h = $AJB.lib.util(),
  624. i = "passed",
  625. j = "failed",
  626. k = b();
  627. return a
  628. },
  629. $AJB.general.Game = function() {
  630. "use strict";
  631. function a() {
  632. var a = document.body.scrollWidth || document.documentElement.scrollWidth,
  633. b = document.body.scrollHeight || document.documentElement.scrollHeight;
  634. r.width = a,
  635. r.height = b,
  636. i = l(x, a, b),
  637. s.style.backgroundColor = i.color,
  638. s.style.width = a + "px",
  639. s.style.height = b + "px",
  640. j = b / 560
  641. }
  642. function b() {
  643. u.href = B.replace(/#\{level\}/, D)
  644. }
  645. function c() {
  646. p.isWeixin ? n(u, "mousedown", function() {
  647. w.style.display = ""
  648. }) : p.isMobile && b()
  649. }
  650. function d(a) {
  651. D = +a,
  652. o.setValue(z, D),
  653. document.title = A.replace(/\#\{level\}/, D),
  654. GlobalLevel = D,
  655. C.level(D), !p.isWeixin && p.isMobile && b()
  656. }
  657. function e() {
  658. n(document.body, "mousedown", function(a) {
  659. var b;
  660. if (a && a.changedTouches)
  661. for (b = a.changedTouches.length; b--;) h.shot();
  662. else h.shot();
  663. "1" != a.target.getAttribute("data-capture") && q(a)
  664. }),
  665. n(w, "mousedown", function() {
  666. w.style.display = "none"
  667. }),
  668. n(v, "mousedown", function() {
  669. E || (E = !0, t.style.display = "", d(1), setTimeout(function() {
  670. t.style.display = "none",
  671. E = !1
  672. }, 1e3))
  673. }),
  674. h.on("passed", function() {
  675. i.switchStage(0, function() {
  676. h.enabled = !1,
  677. d(D + 1),
  678. r.style.display = "none",
  679. C.show(),
  680. // 2. 分享接口
  681. // 2.1 监听“分享给朋友”,按钮点击、自定义分享内容及分享结果接口
  682. wx.onMenuShareAppMessage({
  683. title: "Core Ball,我已玩到第" + D + "关了,你也来试试吧!",
  684. desc: "Core Ball,我已玩到第" + D + "关了,你也来试试吧!",
  685. link: gameurl,
  686. imgUrl: imgUrl,
  687. trigger: function(res) {
  688. // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
  689. // alert('用户点击发送给朋友');
  690. },
  691. success: function(res) {
  692. var UserInfo = new Object();
  693. UserInfo.openid = openid;
  694. UserInfo.shareLevel = D;
  695. // alert('已分享');
  696. ga('send', {
  697. 'hitType': 'event', // Required.
  698. 'eventCategory': 'wx', // Required.
  699. 'eventAction': 'onMenuShareAppMessage_' + openid, // Required.
  700. 'eventLabel': JSON.stringify(UserInfo),
  701. 'eventValue': 1
  702. });
  703. },
  704. cancel: function(res) {
  705. // alert('已取消');
  706. },
  707. fail: function(res) {
  708. // alert(JSON.stringify(res));
  709. }
  710. }),
  711. // 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口
  712. wx.onMenuShareTimeline({
  713. title: "Core Ball,我已玩到第" + D + "关了,你也来试试吧!",
  714. link: gameurl,
  715. imgUrl: imgUrl,
  716. trigger: function(res) {
  717. // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
  718. // alert('用户点击分享到朋友圈');
  719. },
  720. success: function(res) {
  721. // alert('已分享');
  722. var UserInfo = new Object();
  723. UserInfo.openid = openid;
  724. UserInfo.shareLevel = D;
  725. // alert('已分享');
  726. ga('send', {
  727. 'hitType': 'event', // Required.
  728. 'eventCategory': 'wx', // Required.
  729. 'eventAction': 'onMenuShareTimeline_' + openid, // Required.
  730. 'eventLabel': JSON.stringify(UserInfo),
  731. 'eventValue': 1
  732. });
  733. },
  734. cancel: function(res) {
  735. // alert('已取消');
  736. },
  737. fail: function(res) {
  738. // alert(JSON.stringify(res));
  739. }
  740. }),
  741. // 2.3 监听“分享到QQ”按钮点击、自定义分享内容及分享结果接口
  742. wx.onMenuShareQQ({
  743. title: "Core Ball,我已玩到第" + D + "关了,你也来试试吧!",
  744. desc: "Core Ball,我已玩到第" + D + "关了,你也来试试吧!",
  745. link: gameurl,
  746. imgUrl: imgUrl,
  747. trigger: function(res) {
  748. // alert('用户点击分享到QQ');
  749. },
  750. complete: function(res) {
  751. // alert(JSON.stringify(res));
  752. },
  753. success: function(res) {
  754. // alert('已分享');
  755. var UserInfo = new Object();
  756. UserInfo.openid = openid;
  757. UserInfo.shareLevel = D;
  758. // alert('已分享');
  759. ga('send', {
  760. 'hitType': 'event', // Required.
  761. 'eventCategory': 'wx', // Required.
  762. 'eventAction': 'onMenuShareQQ_' + openid, // Required.
  763. 'eventLabel': JSON.stringify(UserInfo),
  764. 'eventValue': 1
  765. });
  766. },
  767. cancel: function(res) {
  768. // alert('已取消');
  769. },
  770. fail: function(res) {
  771. // alert(JSON.stringify(res));
  772. }
  773. })
  774. })
  775. }),
  776. h.on("failed", function() {
  777. i.switchStage(0, function() {
  778. h.enabled = !1,
  779. r.style.display = "none",
  780. C.level(D),
  781. C.show()
  782. })
  783. }),
  784. C.on("start", function() {
  785. r.style.display = "",
  786. C.hide(),
  787. i.switchStage(1, function() {
  788. h.run(D)
  789. // ga('send', {
  790. // 'hitType': 'event', // Required.
  791. // 'eventCategory': 'click', // Required.
  792. // 'eventAction': 'start_' + openid, // Required.
  793. // 'eventLabel': 'other',
  794. // 'eventValue': 1
  795. // })
  796. })
  797. })
  798. }
  799. function f() {
  800. window.clearTimeout(F),
  801. h.update(),
  802. h.render(),
  803. i.update(),
  804. i.render(),
  805. F = window.setTimeout(f, 1e3 / y)
  806. }
  807. function g() {
  808. a(),
  809. h = k(document.body, r, x, j),
  810. e(),
  811. c(),
  812. C.level(D),
  813. C.show(),
  814. f()
  815. }
  816. var h, i, j, k = $AJB.general.Scene(),
  817. l = $AJB.general.Switcher(),
  818. m = $AJB.general.BeginStage(),
  819. n = $AJB.lib.addEvent(),
  820. o = $AJB.lib.Storage(),
  821. p = $AJB.lib.util(),
  822. q = $AJB.lib.stopEvent(),
  823. r = document.getElementById("stage"),
  824. s = document.getElementById("begin"),
  825. t = document.getElementById("tip"),
  826. u = document.getElementById("btnFW"),
  827. v = document.getElementById("btnReset"),
  828. w = document.getElementById("wxArrow"),
  829. x = r.getContext("2d"),
  830. y = 60,
  831. z = "core-ball-level",
  832. A = "Core Ball,我已玩到第#{level}关了,你也来试试吧!",
  833. B = "sinaweibo://share?content=Core Ball,我已玩到第#{level}关了,你也来试试吧! http://timelineapp.pointstone.org/coreball/",
  834. C = m(s),
  835. D = +o.getValue(z) || 1,
  836. E = !1,
  837. F = 0,
  838. G = {
  839. start: g,
  840. shareTitle: A,
  841. shareLevel: D
  842. };
  843. return G;
  844. },
  845. $AJB.page.index = function() {
  846. "use strict";
  847. var a = $AJB.general.Game();
  848. a.start();
  849. // var myShareTitle = a.shareTitle;
  850. // console.log(myShareTitle);
  851. },
  852. $AJB.page.index();
  853. GlobalLevel = $AJB.general.Game().shareLevel;
  854. var ajax = {};
  855. ajax.x = function() {
  856. if (typeof XMLHttpRequest !== 'undefined') {
  857. return new XMLHttpRequest();
  858. }
  859. var versions = [
  860. "MSXML2.XmlHttp.5.0",
  861. "MSXML2.XmlHttp.4.0",
  862. "MSXML2.XmlHttp.3.0",
  863. "MSXML2.XmlHttp.2.0",
  864. "Microsoft.XmlHttp"
  865. ];
  866. var xhr;
  867. for (var i = 0; i < versions.length; i++) {
  868. try {
  869. xhr = new ActiveXObject(versions[i]);
  870. break;
  871. } catch (e) {}
  872. }
  873. return xhr;
  874. };
  875. ajax.send = function(url, callback, method, data, sync) {
  876. var x = ajax.x();
  877. x.open(method, url, sync);
  878. x.onreadystatechange = function() {
  879. if (x.readyState == 4) {
  880. callback(x.responseText)
  881. }
  882. };
  883. if (method == 'POST') {
  884. x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  885. }
  886. x.send(data)
  887. };
  888. ajax.get = function(url, data, callback, sync) {
  889. var query = [];
  890. for (var key in data) {
  891. query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
  892. }
  893. ajax.send(url + '?' + query.join('&'), callback, 'GET', null, sync)
  894. };
  895. ajax.post = function(url, data, callback, sync) {
  896. var query = [];
  897. for (var key in data) {
  898. query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
  899. }
  900. ajax.send(url, callback, 'POST', query.join('&'), sync)
  901. };
  902. ajax.post('http://timelineapp.pointstone.org/ci/authorize/get_jssdk_info', {
  903. url: window.location.href
  904. }, function(data) {
  905. // console.log(data);
  906. // alert(data);
  907. var jssdk_info_obj = JSON.parse(data);
  908. wx.config({
  909. debug: false,
  910. appId: jssdk_info_obj.appid,
  911. timestamp: jssdk_info_obj.timestamp,
  912. nonceStr: jssdk_info_obj.noncestr,
  913. signature: jssdk_info_obj.signature,
  914. jsApiList: [
  915. 'checkJsApi',
  916. 'onMenuShareTimeline',
  917. 'onMenuShareAppMessage',
  918. 'onMenuShareQQ',
  919. 'onMenuShareWeibo',
  920. 'hideMenuItems',
  921. 'showMenuItems',
  922. 'hideAllNonBaseMenuItem',
  923. 'showAllNonBaseMenuItem',
  924. 'translateVoice',
  925. 'startRecord',
  926. 'stopRecord',
  927. 'onRecordEnd',
  928. 'playVoice',
  929. 'pauseVoice',
  930. 'stopVoice',
  931. 'uploadVoice',
  932. 'downloadVoice',
  933. 'chooseImage',
  934. 'previewImage',
  935. 'uploadImage',
  936. 'downloadImage',
  937. 'getNetworkType',
  938. 'openLocation',
  939. 'getLocation',
  940. 'hideOptionMenu',
  941. 'showOptionMenu',
  942. 'closeWindow',
  943. 'scanQRCode',
  944. 'chooseWXPay',
  945. 'openProductSpecificView',
  946. 'addCard',
  947. 'chooseCard',
  948. 'openCard'
  949. ]
  950. });
  951. wx.ready(function() {
  952. // 2. 分享接口
  953. // 2.1 监听“分享给朋友”,按钮点击、自定义分享内容及分享结果接口
  954. wx.onMenuShareAppMessage({
  955. title: "Core Ball,我已玩到第" + GlobalLevel + "关了,你也来试试吧!",
  956. desc: "Core Ball,我已玩到第" + GlobalLevel + "关了,你也来试试吧!",
  957. link: gameurl,
  958. imgUrl: imgUrl,
  959. trigger: function(res) {
  960. // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
  961. // alert('用户点击发送给朋友');
  962. },
  963. success: function(res) {
  964. var UserInfo = new Object();
  965. UserInfo.openid = openid;
  966. UserInfo.shareLevel = GlobalLevel;
  967. // alert('已分享');
  968. ga('send', {
  969. 'hitType': 'event', // Required.
  970. 'eventCategory': 'wx', // Required.
  971. 'eventAction': 'onMenuShareAppMessage_' + openid, // Required.
  972. 'eventLabel': JSON.stringify(UserInfo),
  973. 'eventValue': 1
  974. });
  975. },
  976. cancel: function(res) {
  977. // alert('已取消');
  978. },
  979. fail: function(res) {
  980. // alert(JSON.stringify(res));
  981. }
  982. });
  983. // 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口
  984. wx.onMenuShareTimeline({
  985. title: "Core Ball,我已玩到第" + GlobalLevel + "关了,你也来试试吧!",
  986. link: gameurl,
  987. imgUrl: imgUrl,
  988. trigger: function(res) {
  989. // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
  990. // alert('用户点击分享到朋友圈');
  991. },
  992. success: function(res) {
  993. // alert('已分享');
  994. var UserInfo = new Object();
  995. UserInfo.openid = openid;
  996. UserInfo.shareLevel = GlobalLevel;
  997. // alert('已分享');
  998. ga('send', {
  999. 'hitType': 'event', // Required.
  1000. 'eventCategory': 'wx', // Required.
  1001. 'eventAction': 'onMenuShareTimeline_' + openid, // Required.
  1002. 'eventLabel': JSON.stringify(UserInfo),
  1003. 'eventValue': 1
  1004. });
  1005. },
  1006. cancel: function(res) {
  1007. // alert('已取消');
  1008. },
  1009. fail: function(res) {
  1010. // alert(JSON.stringify(res));
  1011. }
  1012. });
  1013. // 2.3 监听“分享到QQ”按钮点击、自定义分享内容及分享结果接口
  1014. wx.onMenuShareQQ({
  1015. title: "Core Ball,我已玩到第" + GlobalLevel + "关了,你也来试试吧!",
  1016. desc: "Core Ball,我已玩到第" + GlobalLevel + "关了,你也来试试吧!",
  1017. link: gameurl,
  1018. imgUrl: imgUrl,
  1019. trigger: function(res) {
  1020. // alert('用户点击分享到QQ');
  1021. },
  1022. complete: function(res) {
  1023. // alert(JSON.stringify(res));
  1024. },
  1025. success: function(res) {
  1026. // alert('已分享');
  1027. var UserInfo = new Object();
  1028. UserInfo.openid = openid;
  1029. UserInfo.shareLevel = GlobalLevel;
  1030. // alert('已分享');
  1031. ga('send', {
  1032. 'hitType': 'event', // Required.
  1033. 'eventCategory': 'wx', // Required.
  1034. 'eventAction': 'onMenuShareQQ_' + openid, // Required.
  1035. 'eventLabel': JSON.stringify(UserInfo),
  1036. 'eventValue': 1
  1037. });
  1038. },
  1039. cancel: function(res) {
  1040. // alert('已取消');
  1041. },
  1042. fail: function(res) {
  1043. // alert(JSON.stringify(res));
  1044. }
  1045. });
  1046. // 2.4 监听“分享到微博”按钮点击、自定义分享内容及分享结果接口
  1047. wx.onMenuShareWeibo({
  1048. title: "Core Ball,我已玩到第" + GlobalLevel + "关了,你也来试试吧!",
  1049. desc: "Core Ball,我已玩到第" + GlobalLevel + "关了,你也来试试吧!",
  1050. link: gameurl,
  1051. imgUrl: imgUrl,
  1052. trigger: function(res) {
  1053. // alert('用户点击分享到微博');
  1054. },
  1055. complete: function(res) {
  1056. // alert(JSON.stringify(res));
  1057. },
  1058. success: function(res) {
  1059. // alert('已分享');
  1060. var UserInfo = new Object();
  1061. UserInfo.openid = openid;
  1062. UserInfo.shareLevel = GlobalLevel;
  1063. // alert('已分享');
  1064. ga('send', {
  1065. 'hitType': 'event', // Required.
  1066. 'eventCategory': 'wx', // Required.
  1067. 'eventAction': 'onMenuShareWeibo_' + openid, // Required.
  1068. 'eventLabel': JSON.stringify(UserInfo),
  1069. 'eventValue': 1
  1070. });
  1071. },
  1072. cancel: function(res) {
  1073. // alert('已取消');
  1074. },
  1075. fail: function(res) {
  1076. // alert(JSON.stringify(res));
  1077. }
  1078. });
  1079. });
  1080. });