main.min.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. var Config = {
  2. allTime: 3e4,
  3. liveTimeStart: 3e3,
  4. liveTimeEnd: 1e3,
  5. num: 3,
  6. meiziLen: 13,
  7. interval: 200
  8. },
  9. shareData = {
  10. imgUrl: "http://game.ikongzhong.cn/games/memeda/logo.png",
  11. timeLineLink: "http://game.ikongzhong.cn/games/memeda/index.html",
  12. tTitle: "show girl 么么哒",
  13. tContent: "爱我你就吻我吧"
  14. },
  15. Res = ["http://game.ikongzhong.cn/games/memeda/img/1.jpg", "http://game.ikongzhong.cn/games/memeda/img/2.jpg", "http://game.ikongzhong.cn/games/memeda/img/3.jpg", "http://game.ikongzhong.cn/games/memeda/img/4.jpg", "http://game.ikongzhong.cn/games/memeda/img/5.jpg", "http://game.ikongzhong.cn/games/memeda/img/6.jpg", "http://game.ikongzhong.cn/games/memeda/img/7.jpg", "http://game.ikongzhong.cn/games/memeda/img/8.jpg", "http://game.ikongzhong.cn/games/memeda/img/9.jpg", "http://game.ikongzhong.cn/games/memeda/img/10.jpg", "http://game.ikongzhong.cn/games/memeda/img/11.jpg", "http://game.ikongzhong.cn/games/memeda/img/12.jpg", "http://game.ikongzhong.cn/games/memeda/img/13.jpg", "http://game.ikongzhong.cn/games/memeda/img/14.jpg", "http://game.ikongzhong.cn/games/memeda/img/15.jpg", "http://game.ikongzhong.cn/games/memeda/img/80.png", "http://game.ikongzhong.cn/games/memeda/img/460.png"],
  16. timeoutData = [{
  17. max: 30,
  18. desc: "肥皂诚可贵,基友价更高!若为妹纸故,二者皆可抛~!这位壮士只亲到 #score# 位妹纸,还需努力啊~"
  19. },
  20. {
  21. max: 50,
  22. desc: "眼前的妹纸是我的心头爱,想要亲她就要点的快~这位壮士本次亲到 #score# 位妹纸,再来一次!可以亲更多的妹纸呢~!"
  23. },
  24. {
  25. max: 90,
  26. desc: "这位壮士眼疾手快亲到了 #score# 位showgirl,完美闪避出现的宅男~不亏是真·汉纸·无双!"
  27. },
  28. {
  29. max: 30,
  30. desc: "这位壮士完美闪避如花,亲到 #score# 个showgirl!你行?来试试?"
  31. },
  32. {
  33. max: 1e6,
  34. desc: "这位壮士真直男!爱美女!不畏基友和肥皂的诱惑,居然亲到了 #score# 位妹纸!真是叹为观止~!"
  35. }],
  36. suicideData = [{
  37. max: 0,
  38. desc: "恭喜您亲到了女神如花,他已决定为你生儿育女,和美丽的showgirl say goodbye吧~"
  39. },
  40. {
  41. max: 20,
  42. desc: "人固有一死,或死于老眼昏花错点如花,或死于手速太快误点宅男!马上再来一次,不亲到妹纸不罢休~"
  43. },
  44. {
  45. max: 40,
  46. desc: "此人死于手太快,错把如花当美女~你来亲亲美女试试?"
  47. },
  48. {
  49. max: 60,
  50. desc: "恭喜您亲到了女神如花,他已决定为你生儿育女,和美丽的showgirl say goodbye吧~"
  51. },
  52. {
  53. max: 80,
  54. desc: "壮士断腕,你勇于牺牲自己拯救妹子的精神已感动如花,真英雄,不畏基!"
  55. },
  56. {
  57. max: 1e5,
  58. desc: "虽然你亲到了大波的美女,但还是没能逃过宅男【王大锤】的荼毒……菊花残,满地伤……你的影子已……"
  59. }],
  60. rankData = [{
  61. max: 30,
  62. name: "色中菜鸟"
  63. },
  64. {
  65. max: 50,
  66. name: "色中好手"
  67. },
  68. {
  69. max: 70,
  70. name: "色中饿狼"
  71. },
  72. {
  73. max: 90,
  74. name: "色中领袖"
  75. },
  76. {
  77. max: 1e5,
  78. name: "色中翘楚"
  79. }],
  80. beatData = [{
  81. max: 3,
  82. percent: 0
  83. },
  84. {
  85. max: 5,
  86. percent: 8
  87. },
  88. {
  89. max: 10,
  90. percent: 20
  91. },
  92. {
  93. max: 15,
  94. percent: 40
  95. },
  96. {
  97. max: 30,
  98. percent: 70
  99. },
  100. {
  101. max: 40,
  102. percent: 85
  103. },
  104. {
  105. max: 50,
  106. percent: 98.5
  107. },
  108. {
  109. max: 60,
  110. percent: 99.2
  111. },
  112. {
  113. max: 70,
  114. percent: 99.4
  115. },
  116. {
  117. max: 80,
  118. percent: 99.6
  119. },
  120. {
  121. max: 90,
  122. percent: 99.8
  123. },
  124. {
  125. max: 1e5,
  126. percent: 100
  127. }]; !
  128. function(a) {
  129. var b,
  130. c = $("#layout"),
  131. d = $("#box"),
  132. e = ($(".page"), $("#box .hole")),
  133. f = $("#box .meizi"),
  134. g = ($("#box .kiss"), $(".count_down")),
  135. h = $(".score span"),
  136. i = [],
  137. j = [],
  138. k = 0,
  139. l = {
  140. title: shareData.tTitle,
  141. desc: shareData.tContent
  142. },
  143. m = {
  144. init: function() {
  145. this.inited || (this.initEvent(), this.initShareEvent()),
  146. this.inited = !0
  147. },
  148. load: function() {
  149. function a() {
  150. c++,
  151. b == c && (m.init(), d.switchPage("index"))
  152. }
  153. for (var b = Res.length, c = 0, d = this, e = 0; b > e; e++) {
  154. var f = new Image;
  155. f.onload = a,
  156. f.src = Res[e]
  157. }
  158. },
  159. renderUI: function() {
  160. var b,
  161. c,
  162. g,
  163. h,
  164. i = a.innerWidth - 20,
  165. j = a.innerHeight - 50;
  166. j / i > 1.2 ? (b = Math.min(i, 500), g = (b - 12) / 3, h = 1.2 * g, c = 3 * h + 12) : (c = Math.min(j, 500), b = c / 1.2, g = (b - 12) / 3, h = 1.2 * g),
  167. d.width(b).height(c),
  168. e.width(g).height(h),
  169. f.width(g).height(h)
  170. },
  171. initEvent: function() {
  172. var a = "ontouchstart" in document.documentElement ? "touchend": "click";
  173. d.on(a, ".hole>div", _.bind(this.checkTap, this)),
  174. c.on(a, ".js_start_game", _.bind(this.start, this)),
  175. c.on(a, ".js_pause_game", _.bind(this.pause, this)),
  176. c.on(a, ".js_game_again", _.bind(this.again, this)),
  177. c.on(a, ".js_game_continue", _.bind(this.resume, this))
  178. },
  179. start: function() {
  180. this.reset(),
  181. console.log(">> start"),
  182. h.text(0),
  183. g.text(Config.allTime / 1e3),
  184. this.switchPage("game"),
  185. this.renderUI(),
  186. i = this.initThree(),
  187. console.log(i);
  188. for (var a = 0; 9 > a; a++) i[a] > 0 ? this.addMeizi(a) : j.push(!1);
  189. this.tick()
  190. },
  191. initThree: function() {
  192. for (var a = [], b = 0, c = 9; c > b; b++) a.push(3 > b ? Config.liveTimeStart: 0);
  193. return _.shuffle(a)
  194. },
  195. tick: function(b) {
  196. function c(b) {
  197. return e = e || b,
  198. b = Date.now(),
  199. f = b - e,
  200. f >= k && (d(f), e = b),
  201. l._gameover ? void(h && a.cancelAnimationFrame(h)) : l._pause ? void(h && a.cancelAnimationFrame(h)) : void(h = a.requestAnimationFrame(c))
  202. }
  203. function d(a) {
  204. var b = Date.now();
  205. if (l.time = b - m, l.time >= Config.allTime) return void l.gameOver("timeout");
  206. l.time < 6e3 && g.addClass("danger");
  207. for (var c = 0; 9 > c; c++) {
  208. var d = i[c] - a;
  209. d > 0 ? i[c] = d: j[c] && (l.removeMeizi(c), l.addMeizi())
  210. }
  211. g.text(Math.round((Config.allTime - l.time) / 1e3))
  212. }
  213. var e,
  214. f,
  215. h,
  216. k = Config.interval,
  217. l = this,
  218. m = Date.now();
  219. console.log("startTime", m),
  220. "resume" == b && (m -= l.time);
  221. var e = Date.now();
  222. h = a.requestAnimationFrame(c)
  223. },
  224. resume: function() {
  225. console.log(">> resume"),
  226. this._pause = !1,
  227. this.switchPage("game"),
  228. this.tick("resume")
  229. },
  230. pause: function() {
  231. console.log(">> pause"),
  232. this._pause = !0,
  233. this.switchPage("game_pause")
  234. },
  235. checkTap: function(a) {
  236. if (!this._gameover) {
  237. var b = this,
  238. c = $(a.currentTarget),
  239. d = c.data(),
  240. e = d.id,
  241. f = d.value;
  242. j[e] && (k = f, f ? (this.kiss(e,
  243. function() {
  244. b.removeMeizi(e)
  245. }), this.addMeizi(), this.setScore()) : this.gameOver("suicide"))
  246. }
  247. },
  248. setScore: function() {
  249. this.score += 1,
  250. h.text(this.score)
  251. },
  252. again: function() {
  253. console.log(">> again"),
  254. this.start(),
  255. this.switchPage("game")
  256. },
  257. gameOver: function(a) {
  258. console.log(">> gameover");
  259. var b = this;
  260. this._gameover = !0,
  261. b.switchPage("gameover"); {
  262. var c,
  263. d,
  264. e,
  265. g = this.score,
  266. h = this.filterText(g, beatData).percent;
  267. g > 0 ? "我一分钟亲了" + b.score + "个showgirl!肯定比你多,不信你试试?": shareData.tTitle
  268. }
  269. "timeout" == a ? (c = this.filterText(g, timeoutData), d = c.desc.replace(/#score#/, g), e = "恭喜你将她领回家~", l.title = "我亲到" + g + "个showgirl,击败了全国" + h + "%的勇士,征服一个领回家,开心过七夕咯~!") : (c = this.filterText(g, suicideData), d = c.desc, e = "恭喜你将他领回家~", l.title = g > 0 ? "万千showgirl丛中过,偏偏眼瞎亲如花!我只击败了全国" + h + "%的勇士……你来试试?": "很遗憾!我没有亲到Showgirl,是全国唯一垫底的勇士!只有如花和我回家!"),
  270. l.desc = "我亲到" + g + "个showgirl!看看你能亲到几个?";
  271. var i = $("#tpl_gameover").html(),
  272. j = _.template(i, {
  273. score: this.score,
  274. desc: d,
  275. img: Res[k],
  276. name: this.filterText(g, rankData).name,
  277. doMore: "再多亲" + this.random(4, 2) + "个就能多击败" + this.random(5, 2) + "%的玩家,加油哦~",
  278. congratulation: e,
  279. percent: h
  280. });
  281. console.log(l),
  282. $("#gameover").html(j),
  283. f.removeClass()
  284. },
  285. filterText: function(a, b) {
  286. var c = _.filter(b,
  287. function(b) {
  288. return a <= b.max
  289. });
  290. return c[0]
  291. },
  292. reset: function() {
  293. i = [],
  294. j = [],
  295. this.time = Config.allTime,
  296. this.score = 0,
  297. this._gameover = null,
  298. this._pause = !1,
  299. b = Date.now()
  300. },
  301. switchPage: function(a) {
  302. a && ($(".page").addClass("hide"), $("#" + a).addClass("show").removeClass("hide"))
  303. },
  304. random: function(a, b) {
  305. return Math.floor(Math.random() * (a - b + 1)) + b
  306. },
  307. randomSurplusOnly: function() {
  308. function a() {
  309. var c = 8,
  310. d = 0,
  311. e = Math.floor(Math.random() * (c - d + 1)) + d;
  312. return b[e] ? a() : e
  313. }
  314. var b = _.clone(j);
  315. return a()
  316. },
  317. removeMeizi: function(a) {
  318. i[a] = 0,
  319. j[a] = !1,
  320. $(f[a]).removeClass()
  321. },
  322. addMeizi: function(a) {
  323. var a = _.isUndefined(a) ? this.randomSurplusOnly() : a,
  324. b = this.random(Config.meiziLen - 1, 0);
  325. j[a] = !0,
  326. i[a] = this.getliveTime(),
  327. $(f[a]).addClass("meizi_" + b).addClass("meizi").data("value", b)
  328. },
  329. initShareEvent: function() {
  330. var a = this;
  331. document.addEventListener("WeixinJSBridgeReady",
  332. function() {
  333. WeixinJSBridge && WeixinJSBridge.call("hideToolbar"),
  334. WeixinJSBridge && (WeixinJSBridge.on("menu:share:appmessage",
  335. function() {
  336. a.score > 0 ? "我一分钟亲了" + a.score + "个showgirl!肯定比你多,不信你试试?": shareData.tTitle;
  337. WeixinJSBridge.invoke("sendAppMessage", {
  338. img_url: shareData.imgUrl,
  339. link: shareData.timeLineLink,
  340. desc: l.desc,
  341. title: l.title
  342. },
  343. function() {document.location.href = "http://game.ikongzhong.cn/";})
  344. }), WeixinJSBridge.on("menu:share:timeline",
  345. function() {
  346. var a = {
  347. img_url: shareData.imgUrl,
  348. img_width: "640",
  349. img_height: "640",
  350. link: shareData.timeLineLink,
  351. desc: l.desc,
  352. title: l.title
  353. };
  354. WeixinJSBridge.invoke("shareTimeline", a,
  355. function() {document.location.href = "http://game.ikongzhong.cn/";})
  356. }))
  357. },
  358. !1)
  359. },
  360. kiss: function(a, b) {
  361. var c = $(f[a]),
  362. d = '<img src="http://game.ikongzhong.cn/games/memeda/img/460.png" />';
  363. c.html(d),
  364. c.find("img").fadeOut(300, b)
  365. },
  366. getliveTime: function() {
  367. var a = (Config.liveTimeStart - Config.liveTimeEnd) / Config.allTime;
  368. return Config.liveTimeStart - this.time * a
  369. }
  370. };
  371. m.load()
  372. } (window);