main.min3.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /**
  2. * -------------------------------------------------------------
  3. * Copyright (c) 2014 boyaa All rights reserved.
  4. * http://html5.boyaa.com/
  5. * -------------------------------------------------------------
  6. */
  7. var _lang = {
  8. zh1: {
  9. title: "看你有多色",
  10. help_txt: "找出所有色块里颜色不同的一个",
  11. score: "得分:",
  12. btn_pause: "暂停",
  13. btn_start: "开始游戏",
  14. btn_reTry: "再来一次",
  15. btn_more_game: "更多游戏",
  16. game_pause: "游戏暂停",
  17. btn_resume: "继续游戏",
  18. loading: "加载中...",
  19. lv_txt: ["瞎子", "色盲", "色郎", "色狼", "色鬼", "色魔", "超级色魔", "变态色魔", "孤独求色"],
  20. share_txt1: "我闯过",
  21. share_txt2: "关,击败",
  22. share_txt3: "%的人,我是【",
  23. share_txt4: "】,不服来战!",
  24. desc: "找出所有色块中颜色不同的一块。分享朋友圈,找到身边的色魔"
  25. },
  26. zh: {
  27. title: "微信找你妹",
  28. help_txt: "在众多<span style='font-size:240%'>袜</span>子中找到唯一的<span style='font-size:240%'>妹</span>子",
  29. score: "过关:",
  30. btn_pause: "暂停",
  31. btn_start: "开始游戏",
  32. btn_reTry: "再来一次",
  33. btn_more_game: "更多游戏",
  34. game_pause: "游戏暂停",
  35. btn_resume: "继续游戏",
  36. loading: "加载中...",
  37. lv_txt: ["色郎", "色狼", "色鬼", "色魔", "超级色魔", "变态色魔", "孤独求色",],
  38. share_txt1: "【微信找你妹】我在",
  39. share_txt2: "只袜子中找到",
  40. share_txt3: "个妹子,我是【",
  41. share_txt4: "】,不服来战!",
  42. desc: "找出所有'袜'字中的'妹'字。分享朋友圈,找到身边的色魔"
  43. },
  44. en: {
  45. title: "How strong is your eyesight",
  46. help_txt: "Find the box with the different colour",
  47. score: "Score:",
  48. btn_pause: "Pause",
  49. btn_start: "Start",
  50. btn_reTry: "Again",
  51. btn_more_game: "More games",
  52. game_pause: "Pause",
  53. btn_resume: "Continues",
  54. loading: "loading...",
  55. lv_txt: ["Blind", "Very weak", "Weak", "Just so so", "Not bad", "Nice one", "Great", "Amazing", "Insane"],
  56. share_txt1: "I passed ",
  57. share_txt2: "stages and defeated ",
  58. share_txt3: "% people. I am ",
  59. share_txt4: ", come to challenge me if you dare!",
  60. desc: "Find the box with the different colour, share it to your friends!"
  61. }
  62. },
  63. _config = {
  64. lang: "zh",
  65. color: {
  66. allTime: 60,
  67. addTime: 0,
  68. lvMap: [2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9]
  69. },
  70. pic: {
  71. isOpen: !1,
  72. allTime: 5,
  73. addTime: 0,
  74. 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]
  75. }
  76. },
  77. shareData = {
  78. imgUrl: "http://game.ikongzhong.cn/games/zhaonimei/zhaonimei.jpg",
  79. timeLineLink: "http://game.ikongzhong.cn/games/zhaonimei/",
  80. tTitle: _lang[_config.lang].title + "?",
  81. tContent: _lang[_config.lang].desc,
  82. totalWazi:0
  83. }; !
  84. function() {
  85. var a = _lang[_config.lang],
  86. b = $("#tpl").html(),
  87. c = _.template(b, a);
  88. $("body").html(c),
  89. $("title").html(a.title)
  90. } (),
  91. function() {
  92. var a = $("#box"),
  93. b = {
  94. lv: $("#room .lv em"),
  95. time: $("#room .time"),
  96. start: $("#dialog .btn-restart"),
  97. back: $("#dialog .btn-back"),
  98. share: $("#dialog .btn-share"),
  99. pause: $("#room .btn-pause"),
  100. resume: $("#dialog .btn-resume"),
  101. dialog: $("#dialog"),
  102. d_content: $("#dialog .content"),
  103. d_pause: $("#dialog .pause"),
  104. d_gameover: $("#dialog .gameover")
  105. },
  106. c = {
  107. init: function(a, b, c) {
  108. this.type = a,
  109. this.api = API[a],
  110. this.config = _config[a],
  111. this.reset(),
  112. this.parent = c,
  113. this.el = b,
  114. this.renderUI(),
  115. this.inited || this.initEvent(),
  116. this.inited = !0,
  117. this.start()
  118. },
  119. renderUI: function() {
  120. var b = 90 == window.orientation || -90 == window.orientation,
  121. c = b ? window.innerHeight: window.innerWidth;
  122. c -= 20,
  123. c = Math.min(c, 500),
  124. a.width(c).height(c),
  125. this.el.show()
  126. },
  127. initEvent: function() {
  128. var d = "ontouchstart" in document.documentElement ? "touchend": "click",
  129. e = this;
  130. $(window).resize(function() {
  131. c.renderUI()
  132. }),
  133. a.on(d, "span",
  134. function() {
  135. var a = $(this).data("type");
  136. "a" == a && e.nextLv.call(e)
  137. }),
  138. b.pause.on(d, _.bind(this.pause, this)),
  139. b.resume.on(d, _.bind(this.resume, this)),
  140. b.start.on(d, _.bind(this.start, this)),
  141. b.back.on(d, _.bind(this.back, this)),
  142. b.share.on(d, _.bind(this.share, this))
  143. },
  144. start: function() {
  145. if(this.lv==-1) shareData.totalWazi=0;
  146. this.time > 5 && b.time.removeClass("danger"),
  147. b.dialog.hide(),
  148. this._pause = !1,
  149. //shareData.totalWazi = 0,
  150. this.lv = "undefined" != typeof this.lv ? this.lv + 1 : 0,
  151. this.lvMap = this.config.lvMap[this.lv] || _.last(this.config.lvMap),
  152. this.renderMap(),
  153. this.renderInfo(),
  154. this.timer || (this.timer = setInterval(_.bind(this.tick, this), 1e3));
  155. },
  156. share: function() {},
  157. resume: function() {
  158. b.dialog.hide(),
  159. this._pause = !1
  160. },
  161. pause: function() {
  162. this._pause = !0,
  163. b.d_content.hide(),
  164. b.d_pause.show(),
  165. b.dialog.show()
  166. },
  167. tick: function() {
  168. 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)))
  169. },
  170. renderMap: function() {
  171. if (!this._pause) {
  172. var b = this.lvMap * this.lvMap,
  173. c = "",
  174. d = "lv" + this.lvMap;
  175. _(b).times(function() {
  176. c += "<span></span>"
  177. }),
  178. a.attr("class", d).html(c),
  179. this.api.render(this.lvMap, this.lv)
  180. }
  181. },
  182. renderInfo: function() {
  183. b.lv.text(this.lv + 1)
  184. },
  185. gameOver: function() {
  186. try {
  187. WeixinJSBridge.call("showOptionMenu")
  188. } catch(c) {}
  189. var d = this.api.getGameOverText(this.lv);
  190. this.lastLv = this.lv,
  191. this.lastGameTxt = d.txt,
  192. this.lastGamePercent = d.percent,
  193. b.d_content.hide(),
  194. b.d_gameover.show().find("h3").text(this.lastGameTxt),
  195. a.find("span").fadeOut(1500,
  196. function() {
  197. b.dialog.show()
  198. }),
  199. this._pause = !0,
  200. _hmt.push(["_trackEvent", "score", "score_" + (this.lv + 1)]),
  201. this.reset()
  202. },
  203. reset: function() {
  204. this.time = this.config.allTime,
  205. this.lv = -1
  206. },
  207. nextLv: function() {
  208. this.time += this.config.addTime,
  209. b.time.text(parseInt(this.time)),
  210. this._pause || this.start()
  211. },
  212. back: function() {
  213. this._pause = !0,
  214. this.el.hide(),
  215. b.dialog.hide(),
  216. this.parent.render()
  217. }
  218. };
  219. window.Game = c
  220. } (),
  221. function(a) {
  222. var b = {
  223. index: $("#index"),
  224. room: $("#room"),
  225. loading: $("#loading"),
  226. dialog: $("#dialog"),
  227. play: $(".play-btn"),
  228. btn_boyaa: $(".btn-boyaa"),
  229. banner: $(".banner"),
  230. boyaa_logo: $(".boyaa-logo")
  231. },
  232. c = window.navigator.userAgent.toLowerCase(),
  233. d = /android/i.test(c),
  234. e = /iphone|ipad|ipod/i.test(c),
  235. f = {
  236. init: function() {
  237. this.initEvent(),
  238. this.loading(),
  239. /android/i.test(c) ? (b.banner.attr("href", "http://game.ikongzhong.cn/").data("type", "android").find("img").attr("src", "assets/img/banner.android.jpg"), b.banner.show()) : /iphone|ipad|ipod/i.test(c) && (b.banner.attr("href", "http://game.ikongzhong.cn/").data("type", "ios").find("img").attr("src", "assets/img/banner.ios.jpg"), b.banner.show())
  240. },
  241. loading: function() {
  242. function a() {
  243. d++,
  244. d == c && f.render()
  245. }
  246. if (_config.pic.isOpen) for (var b = ["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"], c = b.length, d = 0, e = 0; c > e; e++) {
  247. var g = new Image;
  248. g.onload = a,
  249. g.src = b[e]
  250. } else f.render();
  251. var h = _lang[_config.lang];
  252. document.addEventListener("WeixinJSBridgeReady",
  253. function() {
  254. WeixinJSBridge && (WeixinJSBridge.on("menu:share:appmessage",
  255. function() {
  256. //var a = Game.lastLv > 0 ? h.share_txt1 + (Game.lastLv + 1) + h.share_txt2 + Game.lastGamePercent + h.share_txt3 + Game.lastGameTxt + h.share_txt4: shareData.tTitle;
  257. var a = Game.lastLv > 0 ? h.share_txt1 + (shareData.totalWazi + 1) + h.share_txt2 + (Game.lastLv+1) + h.share_txt3 + Game.lastGameTxt + h.share_txt4: shareData.tTitle;
  258. WeixinJSBridge.invoke("sendAppMessage", {
  259. img_url: shareData.imgUrl,
  260. link: shareData.timeLineLink,
  261. desc: shareData.tContent,
  262. title: a
  263. },
  264. function() {
  265. _hmt.push(["_trackEvent", "share", "appmessage"])
  266. })
  267. }), WeixinJSBridge.on("menu:share:timeline",
  268. function() {
  269. //var a = Game.lastLv > 0 ? h.share_txt1 + (Game.lastLv + 1) + h.share_txt2 + Game.lastGamePercent + h.share_txt3 + Game.lastGameTxt + h.share_txt4: shareData.tTitle;
  270. var a = Game.lastLv > 0 ? h.share_txt1 + (shareData.totalWazi + 1) + h.share_txt2 + (Game.lastLv+1) + h.share_txt3 + Game.lastGameTxt + h.share_txt4: shareData.tTitle;
  271. WeixinJSBridge.invoke("shareTimeline", {
  272. img_url: shareData.imgUrl,
  273. img_width: "640",
  274. img_height: "640",
  275. link: shareData.timeLineLink,
  276. desc: shareData.tContent,
  277. title: a
  278. },
  279. function() {
  280. _hmt.push(["_trackEvent", "share", "timeline"])
  281. })
  282. }))
  283. },
  284. !1)
  285. },
  286. render: function() {
  287. setTimeout(function() {
  288. b.loading.hide(),
  289. b.index.show()
  290. },
  291. 1e3)
  292. },
  293. initEvent: function() {
  294. var a = "ontouchstart" in document.documentElement ? "touchstart": "click",
  295. c = this;
  296. b.play.on(a,
  297. function() {
  298. var a = $(this).data("type") || "color";
  299. b.index.hide(),
  300. Game.init(a, b.room, c)
  301. }),
  302. b.btn_boyaa.on(a,
  303. function() {
  304. _hmt.push(["_trackEvent", "button", "more_game"])
  305. }),
  306. b.boyaa_logo.on(a,
  307. function() {
  308. _hmt.push(["_trackEvent", "button", "boyaa_logo"])
  309. }),
  310. b.banner.on(a,
  311. function() {
  312. var a = $(this).data("t") || "",
  313. b = d ? "android": e ? "ios": "other_os";
  314. _hmt.push(["_trackEvent", "banner", b + "_" + a])
  315. })
  316. }
  317. };
  318. f.init(),
  319. a.API = {}
  320. } (window),
  321. function() {
  322. var a = $("#box"),
  323. b = "span",
  324. c = $("#help p"),
  325. d = $("#help_color"),
  326. e = {
  327. lvT: _lang[_config.lang].lv_txt,
  328. render: function(e, f) {
  329. this.lv = f,
  330. c.hide(),
  331. d.show();
  332. var g = _config.color.lvMap[f] || _.last(_config.color.lvMap);
  333. this.d = 15 * Math.max(9 - g, 1),
  334. this.d = f > 20 ? 10 : this.d,
  335. this.d = f > 40 ? 8 : this.d,
  336. this.d = f > 50 ? 5 : this.d;
  337. var h = Math.floor(Math.random() * e * e),
  338. i = this.getColor(255 - this.d),
  339. j = this.getLvColor(i[0]);
  340. shareData.totalWazi += e*e;
  341. //a.find(b).css("background-color", i[1]).data("type", "b"),
  342. //a.find(b).eq(h).css("background-color", j[1]).data("type", "a")
  343. var size= a.find(b).height()*0.96;
  344. a.find(b).css("background-color", i[1]).data("type", "b").html('<span style="padding:0px;border:0;font-size:'+size+'px;line-height:'+size+'px;width:100%;height:100%" >袜</span>'),
  345. a.find(b).eq(h).css("background-color", i[1]).data("type", "a").html('<span style="padding:0px;border:0;font-size:'+size+'px;line-height:'+size+'px;width:100%;height:100%" >妹</span>')
  346. },
  347. getColor: function(a) {
  348. var b = [Math.round(Math.random() * a), Math.round(Math.random() * a), Math.round(Math.random() * a)],
  349. c = "rgb(" + b.join(",") + ")";
  350. return [b, c]
  351. },
  352. getLvColor: function(a) {
  353. var b = this.d,
  354. c = _.map(a,
  355. function(a) {
  356. return a + b + 10
  357. }),
  358. d = "rgb(" + c.join(",") + ")";
  359. return [c, d]
  360. },
  361. getGameOverText: function(a) {
  362. var b = 20 > a ? 0 : Math.ceil((a - 20) / 10),
  363. c = this.lvT[b] || _.last(this.lvT),
  364. d = c + "lv" + (a + 1),
  365. e = a;
  366. return e = 20 > e ? 2 * a: 30 > a ? 3 * (a - 20) + 40 : 40 > a ? 1.5 * (a - 30) + 70 : 50 > a ? 1.35 * (a - 40) + 85 : 60 > a ? .05 * (a - 50) + 98.5 : 70 > a ? .02 * (a - 60) + 99 : 80 > a ? .02 * (a - 70) + 99.2 : 90 > a ? .02 * (a - 80) + 99.4 : 100 > a ? .02 * (a - 90) + 99.6 : 110 > a ? .02 * (a - 100) + 99.8 : 100,
  367. e = ("" + e).length > 5 ? e.toFixed(2) : e,
  368. {
  369. txt: d,
  370. percent: e
  371. }
  372. }
  373. };
  374. API.color = e
  375. } ();