main.min.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. var _config = {
  2. color: {
  3. allTime: 60,
  4. addTime: 0,
  5. lvMap: [2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9]
  6. },
  7. pic: {
  8. isOpen: !1,
  9. allTime: 5,
  10. addTime: 0,
  11. lvMap: [2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8]
  12. }
  13. },
  14. shareData = {
  15. imgUrl: "http://game.ikongzhong.cn/games/se/assets/img/find.logo.png",
  16. timeLineLink: "http://game.ikongzhong.cn/games/se/",
  17. tTitle: "看你有多色?",
  18. tContent: "找出所有色块中颜色不同的一块。分享朋友圈,找到身边的色魔,关注空中传媒:mkongzhong"
  19. };
  20. ! function() {
  21. var a = $("#box"),
  22. b = {
  23. lv: $("#room .lv em"),
  24. time: $("#room .time"),
  25. start: $("#dialog .btn-restart"),
  26. back: $("#dialog .btn-back"),
  27. share: $("#dialog .btn-share"),
  28. pause: $("#room .btn-pause"),
  29. resume: $("#dialog .btn-resume"),
  30. dialog: $("#dialog"),
  31. d_content: $("#dialog .content"),
  32. d_pause: $("#dialog .pause"),
  33. d_gameover: $("#dialog .gameover")
  34. },
  35. c = {
  36. init: function(a, b, c) {
  37. this.type = a, this.api = API[a], this.config = _config[a], this.reset(), this.parent = c, this.el = b, this.renderUI(), this.inited || this.initEvent(), this.inited = !0, this.start()
  38. },
  39. renderUI: function() {
  40. var b = 90 == window.orientation || -90 == window.orientation,
  41. c = b ? window.innerHeight : window.innerWidth;
  42. c -= 20, c = Math.min(c, 500), a.width(c).height(c), this.el.show()
  43. },
  44. initEvent: function() {
  45. var d = "ontouchstart" in document.documentElement ? "touchend" : "click",
  46. e = this;
  47. $(window).resize(function() {
  48. c.renderUI()
  49. }), a.on(d, "span", function() {
  50. var a = $(this).data("type");
  51. "a" == a && e.nextLv.call(e)
  52. }), b.pause.on(d, _.bind(this.pause, this)), b.resume.on(d, _.bind(this.resume, this)), b.start.on(d, _.bind(this.start, this)), b.back.on(d, _.bind(this.back, this)), b.share.on(d, _.bind(this.share, this))
  53. },
  54. start: function() {
  55. this.time > 5 && b.time.removeClass("danger"), b.dialog.hide(), this._pause = !1, this.lv = "undefined" != typeof this.lv ? this.lv + 1 : 0, this.lvMap = this.config.lvMap[this.lv] || _.last(this.config.lvMap), this.renderMap(), this.renderInfo(), this.timer || (this.timer = setInterval(_.bind(this.tick, this), 1e3))
  56. },
  57. share: function() {},
  58. resume: function() {
  59. b.dialog.hide(), this._pause = !1
  60. },
  61. pause: function() {
  62. this._pause = !0, b.d_content.hide(), b.d_pause.show(), b.dialog.show()
  63. },
  64. tick: function() {
  65. return this._pause ? void 0 : (this.time--, this.time < 6 && b.time.addClass("danger"), this.time < 0 ? void this.gameOver() : void b.time.text(parseInt(this.time)))
  66. },
  67. renderMap: function() {
  68. if (!this._pause) {
  69. var b = this.lvMap * this.lvMap,
  70. c = "",
  71. d = "lv" + this.lvMap;
  72. _(b).times(function() {
  73. c += "<span></span>"
  74. }), a.attr("class", d).html(c), this.api.render(this.lvMap, this.lv)
  75. }
  76. },
  77. renderInfo: function() {
  78. b.lv.text(this.lv + 1)
  79. },
  80. gameOver: function() {
  81. try {
  82. WeixinJSBridge.call("showOptionMenu")
  83. } catch (c) {}
  84. var d = this.api.getGameOverText(this.lv);
  85. this.lastLv = this.lv, this.lastGameTxt = d.txt, this.lastGamePercent = d.percent, b.d_content.hide(), b.d_gameover.show().find("h3").text(this.lastGameTxt), a.find("span").fadeOut(1e3, function() {
  86. b.dialog.fadeIn()
  87. }), this._pause = !0, this.reset()
  88. },
  89. reset: function() {
  90. this.time = this.config.allTime, this.lv = -1
  91. },
  92. nextLv: function() {
  93. this.time += this.config.addTime, b.time.text(parseInt(this.time)), this._pause || this.start()
  94. },
  95. back: function() {
  96. this._pause = !0, this.el.hide(), b.dialog.hide(), this.parent.render()
  97. }
  98. };
  99. window.Game = c
  100. }(),
  101. function(a) {
  102. var b = {
  103. index: $("#index"),
  104. room: $("#room"),
  105. loading: $("#loading"),
  106. dialog: $("#dialog"),
  107. play: $(".play-btn")
  108. },
  109. c = {
  110. init: function() {
  111. this.initEvent(), this.loading()
  112. },
  113. loading: function() {
  114. function a() {
  115. f++, f == e && c.render()
  116. }
  117. function b() {}
  118. if (_config.pic.isOpen)
  119. for (var d = ["assets/img/1.png", "assets/img/2.png", "assets/img/3.png", "assets/img/4.png", "assets/img/5.png", "assets/img/6.png", "assets/img/7.png", "assets/img/8.png", "assets/img/9.png", "assets/img/10.png", "assets/img/11.png", "assets/img/12.png", "assets/img/13.png", "assets/img/14.png", "assets/img/15.png", "assets/img/16.png", "assets/img/17.png", "assets/img/18.png"], e = d.length, f = 0, g = 0; e > g; g++) {
  120. var h = new Image;
  121. h.onload = a, h.src = d[g]
  122. } else c.render();
  123. document.addEventListener("WeixinJSBridgeReady", function() {
  124. WeixinJSBridge && (WeixinJSBridge.on("menu:share:appmessage", function() {
  125. var a = Game.lastLv > 0 ? "我闯过" + (Game.lastLv + 1) + "关,击败" + Game.lastGamePercent + "%的人!我是【" + Game.lastGameTxt + "】!不服来战!" : shareData.tTitle;
  126. WeixinJSBridge.invoke("sendAppMessage", {
  127. img_url: shareData.imgUrl,
  128. link: shareData.timeLineLink,
  129. desc: shareData.tContent,
  130. title: a
  131. }, b)
  132. }), WeixinJSBridge.on("menu:share:timeline", function() {
  133. var a = Game.lastLv > 0 ? "我闯过" + (Game.lastLv + 1) + "关,击败" + Game.lastGamePercent + "%的人!我是【" + Game.lastGameTxt + "】!不服来战!" : shareData.tTitle;
  134. WeixinJSBridge.invoke("shareTimeline", {
  135. img_url: shareData.imgUrl,
  136. img_width: "640",
  137. img_height: "640",
  138. link: shareData.timeLineLink,
  139. desc: shareData.tContent,
  140. title: a
  141. }, b)
  142. }))
  143. }, !1)
  144. },
  145. render: function() {
  146. b.loading.hide(), b.index.show()
  147. },
  148. initEvent: function() {
  149. var a = "ontouchstart" in document.documentElement ? "touchstart" : "click",
  150. c = this;
  151. b.play.on(a, function() {
  152. var a = $(this).data("type") || "color";
  153. b.index.hide(), Game.init(a, b.room, c)
  154. })
  155. }
  156. };
  157. c.init(), a.API = {}
  158. }(window),
  159. function() {
  160. var a = $("#box"),
  161. b = "span",
  162. c = $("#help p"),
  163. d = $("#help_color"),
  164. e = {
  165. lvT: ["瞎子", "色盲", "色郎", "色狼", "色鬼", "色魔", "超级色魔", "变态色魔", "孤独求色"],
  166. render: function(e, f) {
  167. this.lv = f, c.hide(), d.show();
  168. var g = _config.color.lvMap[f] || _.last(_config.color.lvMap);
  169. this.d = 15 * Math.max(9 - g, 1), this.d = f > 20 ? 10 : this.d, this.d = f > 40 ? 8 : this.d, this.d = f > 50 ? 5 : this.d;
  170. var h = Math.floor(Math.random() * e * e),
  171. i = this.getColor(255 - this.d),
  172. j = this.getLvColor(i[0]);
  173. a.find(b).css("background-color", i[1]).data("type", "b"), a.find(b).eq(h).css("background-color", j[1]).data("type", "a")
  174. },
  175. getColor: function(a) {
  176. var b = [Math.round(Math.random() * a), Math.round(Math.random() * a), Math.round(Math.random() * a)],
  177. c = "rgb(" + b.join(",") + ")";
  178. return [b, c]
  179. },
  180. getLvColor: function(a) {
  181. var b = this.d,
  182. c = _.map(a, function(a) {
  183. return a + b
  184. }),
  185. d = "rgb(" + c.join(",") + ")";
  186. return [c, d]
  187. },
  188. getGameOverText: function(a) {
  189. var b = 15 > a ? 0 : Math.ceil((a - 15) / 5),
  190. c = this.lvT[b] || _.last(this.lvT),
  191. d = c + "lv" + (a + 1),
  192. e = 2 * a;
  193. return e = e > 90 ? 90 + .15 * a : e, e = Math.min(e, 100), {
  194. txt: d,
  195. percent: e
  196. }
  197. }
  198. };
  199. API.color = e
  200. }();