Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ! function() {
- "use strict";
- function o(o) {
- return 10 > o ? "0" + o : o
- }
- function e() {
- return Math.round((new Date).getTime() / 10)
- }
- function n(o) {
- o = o.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var e = new RegExp("[\\?&]" + o + "=([^&#]*)"),
- n = e.exec(location.search);
- return null === n ? "" : decodeURIComponent(n[1].replace(/\+/g, " "))
- }
- var t = function() {},
- i = ["assert", "clear", "count", "debug", "dir", "dirxml", "error", "exception", "group", "groupCollapsed", "groupEnd", "info", "log", "markTimeline", "profile", "profileEnd", "table", "time", "timeEnd", "timeStamp", "trace", "warn"];
- _.each(i, function(o) {
- console[o] || (console[o] = t)
- }), window.App = {}, App.viewport = function() {
- var o = window,
- e = "inner";
- return "innerWidth" in window || (e = "client", o = document.documentElement || document.body), {
- width: o[e + "Width"],
- height: o[e + "Height"]
- }
- }, App.isMobileBreakpoint = function() {
- return App.viewport().width < 496
- }, App.formatMiliseconds = function(e) {
- var n = Math.floor(e / 100),
- t = e - 100 * n;
- return o(n) + ":" + o(t)
- }, App.trackEvent = function(o, e) {
- console.log("TRACKING:", o, "-", e), ga("send", "event", o, "click", e)
- }, App.msTimer = function(o, n) {
- var t = e(),
- i = setInterval(function() {
- var r = e(),
- c = o - (r - t);
- 0 >= c && clearInterval(i), n(c)
- }, 10)
- };
- var r = n("ref");
- "" !== r && ga("send", "event", "pageview", "open", "ref", r), window.fbAsyncInit = function() {
- FB.init(), FB.Canvas.setSize()
- },
- function() {
- var o = document.createElement("script");
- o.async = !0, o.src = document.location.protocol + "//connect.facebook.net/en_US/all.js", document.getElementById("fb-root").appendChild(o)
- }()
- }(),
- function() {
- "use strict";
- $("#content-close_overlay").on("click", function() {
- history.back()
- })
- }(),
- function() {
- "use strict";
- function o() {
- var o = $.Deferred(),
- t = Phaser.AUTO;
- return monster.get("force_canvas") && (t = Phaser.CANVAS), I = new Phaser.Game(C, S, t, T, {
- preload: e,
- create: function() {
- n(o)
- },
- update: c
- }), d.game = I, o.done(function() {
- if (I.renderer && I.renderer.gl) {
- var o = I.renderer.gl,
- e = I.renderer.gl.getError();
- e !== o.NO_ERROR && e !== o.CONTEXT_LOST_WEBGL && (console.log("Detected webGL error. Set cookie and reload."), monster.set("force_canvas", "1"), location.reload())
- }
- }), o.promise()
- }
- function e() {
- I.load.image("background", ASSETS_PATH + "bundles/lenovoyogamodes/img/game-background.png"), I.load.image("block0", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block0.png"), I.load.image("block0-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block0-combo.png"), I.load.image("block1", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block1.png"), I.load.image("block1-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block1-combo.png"), I.load.image("block2", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block2.png"), I.load.image("block2-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block2-combo.png"), I.load.image("block3", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block3.png"), I.load.image("block3-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block3-combo.png"), I.load.image("block4", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block4.png"), I.load.image("block4-combo", ASSETS_PATH + "bundles/lenovoyogamodes/img/blocks/block4-combo.png")
- }
- function n(o) {
- var e = I.add.sprite(0, 0, "background");
- e.width = C, e.height = S, I.physics.startSystem(Phaser.Physics.ARCADE), I.stage.disableVisibilityChange = !0, x = I.add.group();
- var n = "ontouchstart" in window || navigator.msMaxTouchPoints || "onmsgesturechange" in window;
- n && $("#game-mobile-controls").addClass("active");
- var t = I.input.keyboard.createCursorKeys();
- ["left", "right", "down"].forEach(function(o) {
- t[o].onDown.add(function() {
- i(o)
- });
- var e = "";
- window.navigator.msPointerEnabled && (e = "MSPointerDown "), e += "touchstart", window.navigator.userAgent.match(/android/i) || (e += " click"), $(document).on(e, "#cursor-" + o, function(e) {
- return e.stopPropagation(), e.preventDefault(), event.handled === !0 ? !1 : (i(o), event.handled = !0, void 0)
- })
- });
- var r = Math.max(0, $(document).height() - App.viewport().height - $(".app-footer").outerHeight());
- $(window).scrollTop(r), o.resolve()
- }
- function t() {
- var o = G.shift(),
- e = -O.BLOCK_HEIGHT,
- n = Math.ceil(A / 2) * O.BLOCK_WIDTH,
- t = x.create(n, e, "block" + o);
- t.width = O.BLOCK_WIDTH - 1, t.height = O.BLOCK_WIDTH, t.type = o, t.id = ++P, t.name = "Block #" + t.id + " (type " + t.type + ")", I.physics.enable([t], Phaser.Physics.ARCADE), t.body.velocity.y = O.VELOCITY, H = t, console.info("spawned", t.name), G.length < 15 && v()
- }
- function i(o) {
- if (H) {
- var e, n;
- switch (o) {
- case "left":
- e = H.position.x - O.BLOCK_WIDTH, e = Math.max(e, 0), n = H.position.y;
- break;
- case "right":
- e = H.position.x + O.BLOCK_WIDTH, e = Math.min(e, C - O.BLOCK_WIDTH), n = H.position.y;
- break;
- case "down":
- e = H.position.x, n = H.position.y + O.BLOCK_HEIGHT, n = Math.min(n, S - O.BLOCK_HEIGHT);
- break;
- default:
- return
- }
- r(e, n) ? "down" === o && (n = p(n), r(e, n) || (H.position.y = n)) : (H.position.x = e, H.position.y = n)
- }
- }
- function r(o, e) {
- var n = !1;
- return $.each(M, function(t, i) {
- if (null !== i && M.hasOwnProperty(t)) {
- var r = o === i.position.x,
- c = e >= i.position.y - O.BLOCK_HEIGHT && e < i.position.y + O.BLOCK_HEIGHT;
- r && c && (n = !0)
- }
- }), n
- }
- function c() {
- I.physics.arcade.collide(x, x, function(o, e) {
- H === e && (o.position.x !== e.position.x && (e.position.x = o.position.x), a())
- }), H && H.position.y + H.height >= I.world.height - 1 && a()
- }
- function a() {
- if (H.body.immovable = !0, H.body.velocity.y = 0, H.position.y <= 0) return h(), void 0;
- var o = H.position.x,
- e = p(H.position.y);
- H.gridRow = e / O.BLOCK_HEIGHT, H.gridCol = o / O.BLOCK_WIDTH, D[H.gridRow][H.gridCol] = H, M[H.id] = H;
- var n = l();
- console.info("placed ", H.name, "at", H.gridCol + ":" + H.gridRow), k(H, n), H = null, n.length ? setTimeout(t, O.REMOVE_COMBO_DELAY) : t()
- }
- function l() {
- var o = [];
- _.each(D, function(e) {
- o = o.concat(s(e))
- });
- for (var e = 0; A > e; e++) {
- for (var n = [], t = 0; B > t; t++) n.push(D[t][e]);
- o = o.concat(s(n))
- }
- if (_.each(u(), function(e) {
- var n = [];
- _.each(e, function(o) {
- null !== D[o.y][o.x] ? n.push(D[o.y][o.x]) : n.push(null)
- }), o = o.concat(s(n))
- }), o.length) {
- o = _.uniq(o), E(), o.length && console.info(" => combos:", o), o.forEach(function(o) {
- g(o.length)
- }), o.forEach(f);
- var i = l();
- i.length && k(null, i)
- }
- return o
- }
- function s(o) {
- for (var e = [], n = !1, t = !1, i = !1, r = _.size(o), c = 0; r > c; c++) {
- var a = o[c],
- l = null === a,
- s = l ? null : a.type,
- u = s === t,
- d = 0 === s,
- p = 0 === t,
- f = parseInt(c, 10) === r - 1;
- if (n !== !1 || l)
- if (!l && (u || d || p)) n.push(a), p && (t = s), f && n.length >= O.BLOCKS_PER_COMBO && e.push(n);
- else {
- if (n.length >= O.BLOCKS_PER_COMBO) e.push(n);
- else if (0 === i && !l) {
- n = !1, t = !1, i = !1, c -= 2;
- continue
- }
- l ? (n = !1, t = !1) : (n = [a], t = s)
- } else n = [a], t = s;
- i = s
- }
- return e
- }
- function u() {
- for (var o = function(o, e, n) {
- return n.x < o && n.x >= 0 && n.y < e && n.y >= 0
- }, e = function(o) {
- return {
- x: o.x - 1,
- y: o.y + 1
- }
- }, n = function(o) {
- return {
- x: o.x + 1,
- y: o.y + 1
- }
- }, t = -1 * B + O.BLOCKS_PER_COMBO, i = A + B - O.BLOCKS_PER_COMBO, r = [], c = [], a = t; i > a; a++) {
- var l = {
- x: a,
- y: 0
- },
- s = e(l);
- for (o(A, B, l) && c.push(l); s.x >= 0 && s.y < B;) o(A, B, s) && c.unshift(s), s = e(s);
- r.push(c), c = [];
- var u = n(l);
- for (o(A, B, l) && c.push(l); u.y >= 0 && u.x < A;) o(A, B, u) && c.push(u), u = n(u);
- r.push(c), c = []
- }
- return r
- }
- function p(o) {
- return Math.floor((o + 1) / O.BLOCK_HEIGHT) * O.BLOCK_HEIGHT
- }
- function f(o) {
- o.forEach(function(o) {
- o.loadTexture("block" + o.type + "-combo"), setTimeout(function() {
- o.kill()
- }, O.REMOVE_COMBO_DELAY), D[o.gridRow][o.gridCol] = null, M[o.id] = null;
- for (var e = o.gridRow - 1; e >= 0; e--)
- if (null !== D[e][o.gridCol]) {
- var n = D[e][o.gridCol];
- n.position.y += O.BLOCK_HEIGHT, n.gridRow += 1, D[e][o.gridCol] = null, D[n.gridRow][o.gridCol] = n
- }
- })
- }
- function g(o) {
- var e;
- switch (o) {
- case 4:
- e = 2.5;
- break;
- case 5:
- e = 5;
- break;
- default:
- e = 1
- }
- K += O.SCORE_MULTIPLIER_BASE * e, R += O.SCORE_MULTIPLIER_BASE * e, $("#game_play_score").val(K), $("#score-counter").text(R)
- }
- function h() {
- $("#game canvas").hide(), $("#game-loading").show(), I.destroy(), console.info("GAME OVER (" + K + ")"), window._fbq.push(["track", "6020907107647", {
- value: "0.00",
- currency: "GBP"
- }]), $.when.apply(this, q).always(function() {
- $("#game-form").submit()
- })
- }
- function m() {
- var o = 100 * O.TIME_LIMIT;
- App.msTimer(o, function(o) {
- $("#time-left").text(App.formatMiliseconds(o)), 0 >= o && h()
- })
- }
- function v() {
- return $.ajax({
- url: "play/get-elements",
- dataType: "json",
- cache: !1
- }).then(function(o) {
- L = o.key, $("#game_play_key").val(L), G = G.concat(o.elements)
- }).fail(function(o) {
- alert("[getElems] server error (" + o.statusText + "): " + o.responseText), location.reload()
- })
- }
- function b() {
- return $.post("play/start", {
- key: L
- }).fail(function(o) {
- alert("[start] server error (" + o.statusText + "): " + o.responseText), location.reload()
- })
- }
- function k(o, e) {
- var n = {
- key: L
- };
- null !== o && (n.element = {
- type: o.type,
- pos: {
- col: o.gridCol,
- row: o.gridRow
- }
- }), n.groups = e.map(function(o) {
- return o.map(function(o) {
- return {
- type: o.type,
- pos: {
- col: o.gridCol,
- row: o.gridRow
- }
- }
- })
- });
- var t = $.post("play/update", n);
- q.push(t), t.fail(function(o) {
- alert("[update] server error (" + o.statusText + "): " + o.responseText), location.reload()
- })
- }
- function w() {
- $("#game-loading").hide(), $("#game .canvas-wrapper").css({
- visibility: "visible"
- }), $("#countdown").show();
- var o = $.Deferred(),
- e = 5,
- n = setInterval(function() {
- e -= 1, $("#countdown .counter").text(e), 0 === e && ($("#countdown").hide(), o.resolve(), clearInterval(n))
- }, 1e3);
- return o.promise()
- }
- function y(o) {
- App.viewport().width > 495 && $("body").css({
- backgroundImage: "url(" + ASSETS_PATH + "bundles/lenovoyogamodes/img/game-bodybackground.png)",
- backgroundSize: "auto " + (o - 50) + "px"
- })
- }
- function E() {
- _.each(D, function(o, e) {
- var n = "row " + e + ": ";
- _.each(o, function(o) {
- n += "|" + (o ? o.type : "-")
- }), console.log(n + "|")
- })
- }
- if (0 !== $("#game").length) {
- var T = $("#game .canvas-wrapper")[0],
- A = 6,
- B = 8,
- C = Math.floor(T.offsetWidth / A) * A,
- S = B / A * C;
- T.style.height = S, y(S);
- var O = {
- BLOCK_WIDTH: Math.floor(C / 6),
- BLOCK_HEIGHT: Math.floor(S / 8),
- VELOCITY: parseInt(GAMECONFIG.velocity || "50", 10),
- BLOCKS_PER_COMBO: 3,
- SCORE_MULTIPLIER_BASE: 10,
- REMOVE_COMBO_DELAY: 500,
- TIME_LIMIT: parseInt($("#time-left").attr("data-time"), 10)
- };
- console.info("init - world", C, S, "blocks:", O.BLOCK_WIDTH, O.BLOCK_HEIGHT);
- for (var I, x, H, L, P = 0, M = {}, R = parseInt($("#score-counter").text(), 10) || 0, K = 0, G = [], q = [], D = {}, W = 0; B > W; W++) {
- D[W] = {};
- for (var V = 0; A > V; V++) D[W][V] = null
- }
- v().then(o).then(w).then(m).then(b).then(t), window.d = {
- blocksGroup: x,
- activeBlock: H,
- placedBlocks: M,
- grid: D
- }, window.d.logGrid = E
- }
- }(),
- function() {
- "use strict";
- $("#howto-slider").length && ($("#howto-slider").bxSlider({
- adaptiveHeight: !0,
- infiniteLoop: !1,
- hideControlOnEnd: !0,
- touchEnabled: !0
- }), $("#howto-slider li:first img:first").trigger("load"))
- }(),
- function() {
- "use strict";
- if ($("#view-index").length) {
- if (self !== top) {
- var o = $("#auth-button").attr("href");
- $("#auth-button").attr("href", o + "?redirect_url=lym_canvas")
- }
- $("#auth-button").on("click", function() {
- App.trackEvent("Start Screen", "Button1 (let´s go) click")
- })
- }
- }(),
- function() {
- "use strict";
- $("#view-intro").length && ($("#intro-newbie-play-button").on("click", function() {
- App.trackEvent("Intro screen new user", "Button2 (let´s go) click"), window._fbq.push(["track", "6020907068647", {
- value: "0.00",
- currency: "GBP"
- }]), window._fbq.push(["track", "6020907052047", {
- value: "0.00",
- currency: "GBP"
- }])
- }), $("#intro-returnee-play-button").on("click", function() {
- App.trackEvent("Intro screen returning user", "Button3 (let´s go) click"), window._fbq.push(["track", "6020907068647", {
- value: "0.00",
- currency: "GBP"
- }]), window._fbq.push(["track", "6020907052047", {
- value: "0.00",
- currency: "GBP"
- }])
- }))
- }(),
- function() {
- "use strict";
- if ($("#view-question").length) {
- var o = 100 * parseInt($("#time-left").attr("data-time"), 10);
- App.msTimer(o, function(o) {
- $("#time-left").text(App.formatMiliseconds(o)), 0 >= o && $("#question-form").submit()
- }), $(".question-lvl-1 #game_question_save").on("click", function() {
- App.trackEvent("Bonus question level 1 play screen", "Button5 (submit) click")
- }), $(".question-lvl-2 #game_question_save").on("click", function() {
- App.trackEvent("Bonus question level 2 play screen", "Button7 (submit) click")
- })
- }
- }(),
- function() {
- "use strict";
- $("#questionIntro-lvl-1, #questionIntro-lvl-2").length && (App.isMobileBreakpoint() && $("#questionIntro-visual-mobile").slickWrap(), $("#questionIntro-lvl-1 .question-link").on("click", function() {
- App.trackEvent("Bonus question level 1 intro screen", "Button4 (let´s go) click")
- }), $("#questionIntro-lvl-2 .question-link").on("click", function() {
- App.trackEvent("Bonus question level 2 intro screen", "Button6 (let´s go) click")
- }))
- }(),
- function() {
- "use strict";
- $("#registration-form").on("submit", function(o) {
- $("#registration-terms").prop("checked") || ($("#terms-row").addClass("has-error"), o.preventDefault())
- })
- }(),
- function() {
- "use strict";
- if ($("#view-success").length) {
- $("#success-facebook-link, #success-twitter-link").on("click", function(o) {
- o.preventDefault();
- var e = window.open($(this).attr("href"), "", "scrollbars=1,width=684,height=450");
- window.focus && e.focus()
- });
- var o = navigator.userAgent.match(/Android|iPhone/i) && !navigator.userAgent.match(/iPod|iPad/i) ? !0 : !1;
- o || $("#success-whatsapp").hide(), $("#success-replay_button").on("click", function() {
- App.trackEvent("Threshold score achieved", "Button9 (submit) click")
- })
- }
- }(),
- function() {
- "use strict";
- $("#successTreshold-replay_button").on("click", function() {
- App.trackEvent("Threshold score failed", "Button8 (play again) click")
- })
- }(),
- function() {
- "use strict";
- $("#view-win").length && $('#win-text a[href*="lenovo.com"]').on("click", function() {
- App.trackEvent("Win Screen", "Textlink (lenovo) click")
- })
- }();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement