-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathlupiremobile.min.js
1 lines (1 loc) · 9.87 KB
/
lupiremobile.min.js
1
javascript:krazete:function choose(e){return e[Math.floor(Math.random()*e.length)]}function newHex(e,t){void 0===e&&(e=0),void 0===t&&(t=16);for(var s=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],o="#",n=0;n<6;n++)o+=choose(s.slice(e,t));return o}function newByte(e,t,s){void 0===t&&(t=0),void 0===s&&(s=256);for(var o=[],n=0;n<256;n++)o.push(n);for(var r="rgba(",n=0;n<3;n++)r+=choose(o.slice(t,s))+",";return r+=e+")"}function newBlock(e){for(var t=[0,1,2,2,3,3,3,3,4,4,5,5],s=[],o=0;o<blocks.length;o++)for(var n=0;n<e[t[o]];n++)s.push(blocks[o]);return choose(s)}var compass,edges,goal,ball,blocks=[full={img:1,goto:[0,1,2,3]},empty={img:0,goto:[2,3,0,1]},bslash={img:1,goto:[1,0,3,2]},slash={img:0,goto:[3,2,1,0]},cornertr={img:[1,1,0,0],goto:[0,1,3,2]},cornerbr={img:[1,0,0,1],goto:[0,2,1,3]},cornerbl={img:[0,0,1,1],goto:[1,0,2,3]},cornertl={img:[0,1,1,0],goto:[3,1,2,0]},vpipe={img:[1,0,1,0],goto:[0,3,2,1]},hpipe={img:[0,1,0,1],goto:[2,1,0,3]},ccw={img:1,goto:[1,2,3,0]},cw={img:0,goto:[3,0,1,2]}],spinster=document.createElement("style"),span=(spinster.textContent="@keyframes cwise{ from{transform:rotate(0deg);-webkit-transform:rotate(0deg);} to{transform:rotate(360deg);-webkit-transform:rotate(360deg);} }",spinster.textContent+="@keyframes ccwise{ from{transform:rotate(360deg);-webkit-transform:rotate(360deg);} to{transform:rotate(0deg);-webkit-transform:rotate(0deg);} }",document.body.appendChild(spinster),3),distribution=[0,2,1,0,0,0],VMIN=innerWidth<innerHeight?innerWidth:innerHeight,zoom=3*VMIN/4,unit=zoom/span,speed=.1,game=document.createElement("div"),corners=(game.style.position="fixed",game.style.top="50%25",game.style.left="50%25",game.style.transform="translate(-50%25,-50%25)",game.style.webkitTransform="translate(-50%25,-50%25)",game.style.transition=speed+"s opacity",game.style.zIndex="9999",document.getElementsByClassName("cornerBox")),inners=document.getElementsByClassName("innerBox"),rawEdges=document.getElementsByClassName("edgeBox"),lvl=1,pts=0,hp=15,board=document.createElement("div"),tab=(board.style.background="white",board.style.textAlign="center",board.style.position="fixed",board.style.bottom=0,board.style.left="50%25",board.style.transform="translateX(-50%25)",board.style.webkitTransform="translateX(-50%25)",board.style.transition=speed+"s opacity",board.style.border="1px solid black",board.style.padding="5px",board.style.borderRadius="5px",board.style.zIndex="9999",document.body.appendChild(board)," | ");function newGame(e,t,s,o){if(distribution=t=void 0===t?distribution:t,unit=(zoom=s=void 0===s?zoom:s)/(span=e=void 0===e?span:e),speed=o=void 0===o?speed:o,board.style.opacity=1,board.textContent="Lives: "+hp+tab+"Points: "+pts+tab+"Level: "+(span-2)+tab+"Sublevel: "+lvl+"/"+(span-2),0==hp||2==span)return hide(),disable(),ball.remove(),board.innerText+="\nGAME OVER",0;for(;game.lastChild;)game.removeChild(game.lastChild);for(game.remove(),game.style.background=newByte(.75,64,192),game.style.height=zoom+"px",game.style.width=zoom+"px",game.style.borderRadius=.5*unit+"px",game.style.opacity=1,document.body.appendChild(game),compass=newBoard(),edges=[],i=0;i<rawEdges.length;i++)rawEdges[i].end=newPath(rawEdges[i].x,rawEdges[i].y),edges.push(rawEdges[i]);edges.sort(function(e,t){return e.end.steps-t.end.steps}),setTimeout(setUp,1e4*speed*(1+span/10))}function setUp(){goal=newGoal(),ball=newBall(goal.x,goal.y),hide(),enable()}function newBoard(){for(var e=newHex(0,8),t=[],s=[],o=0;o<span;o++){t[o]=[],s[o]=[];for(var n=0;n<span;n++){var r=document.createElement("div"),i=(r.style.height=unit+"px",r.style.width=unit+"px",r.style.position="absolute",r.style.top=o*unit+"px",r.style.left=n*unit+"px",r.style.boxSizing="border-box",r.style.boxShadow="inset 0 0 3px "+game.style.backgroundColor,game.appendChild(r),document.createElement("div")),r=(i.x=o,i.y=n,i.style.position="absolute",i.style.top=o*unit+"px",i.style.left=n*unit+"px",i.style.boxSizing="border-box",0==o&&0==n||0==o&&n==span-1||o==span-1&&n==span-1||o==span-1&&0==n?(r.remove(),t[o][n]=blocks[0],s[o][n]="X",i.className="cornerBox",i.style.transition=speed+"s border-radius",0==o&&0==n?(i.style.borderTopLeftRadius="50%25",i.addEventListener("mouseover",function(){this.style.borderTopLeftRadius="25%25"}),i.addEventListener("mouseout",function(){this.style.borderTopLeftRadius="50%25"}),i.addEventListener("click",newGame)):0==o&&n==span-1?((r=document.createElement("div")).style.background="white",r.style.height=.5*unit+"px",r.style.width=.1*unit+"px",r.style.borderRadius=100/3+"%25",r.style.position="absolute",r.style.top=.25*unit+"px",r.style.left=.45*unit+"px",r.style.transform="rotate(45deg)",r.style.webkitTransform="rotate(45deg)",i.appendChild(r),(r=r.cloneNode()).style.transform="rotate(-45deg)",r.style.webkitTransform="rotate(-45deg)",i.appendChild(r),i.style.borderTopRightRadius="50%25",i.addEventListener("mouseover",function(){this.style.borderTopRightRadius="25%25"}),i.addEventListener("mouseout",function(){this.style.borderTopRightRadius="50%25"}),i.addEventListener("click",function(){game.style.opacity=0,board.style.opacity=0,setTimeout(function(){game.remove(),board.remove()},100)})):o==span-1&&n==span-1?(i.style.borderBottomRightRadius="50%25",i.addEventListener("mouseover",function(){this.style.borderBottomRightRadius="25%25"}),i.addEventListener("mouseout",function(){this.style.borderBottomRightRadius="50%25"}),i.addEventListener("click",hide)):o==span-1&&0==n&&(i.style.borderBottomLeftRadius="50%25",i.addEventListener("mouseover",function(){this.style.borderBottomLeftRadius="25%25"}),i.addEventListener("mouseout",function(){this.style.borderBottomLeftRadius="50%25"}),i.addEventListener("click",show))):0==o||o==span-1||0==n||n==span-1?(0==o||o==span-1?(t[o][n]=blocks[8],s[o][n]=0==o?[3,3,3,3]:[1,1,1,1]):0!=n&&n!=span-1||(t[o][n]=blocks[9],s[o][n]=0==n?[0,0,0,0]:[2,2,2,2]),i.className="edgeBox",i.style.background="rgba(0,0,0,0.25)",i.style.transition=2*speed+"s background"):(t[o][n]=newBlock(distribution),s[o][n]=t[o][n].goto,i.className="innerBox",i.style.borderRadius=100/3+"%25",i.style.transition=2*speed+"s opacity"),t[o][n]),a="innerBox"==i.className?"white":e;r==full||r==empty?(i.style.background=r.img?a:"transparent",i.style.height=unit+"px",i.style.width=unit+"px"):r==bslash||r==slash?(i.style.background=a,i.style.left=(n+.4)*unit+"px",i.style.height=unit+"px",i.style.width=.2*unit+"px",i.style.transform="rotate("+[45,-45][r.img]+"deg)",i.style.webkitTransform="rotate("+[45,-45][r.img]+"deg)"):r==cornertr||r==cornerbr||r==cornerbl||r==cornertl?(i.style.height=unit+"px",i.style.width=unit+"px",i.style.borderRight=.5*unit+"px solid "+(r.img[0]?a:"transparent"),i.style.borderTop=.5*unit+"px solid "+(r.img[1]?a:"transparent"),i.style.borderLeft=.5*unit+"px solid "+(r.img[2]?a:"transparent"),i.style.borderBottom=.5*unit+"px solid "+(r.img[3]?a:"transparent")):r==vpipe||r==hpipe?(i.style.height=unit+"px",i.style.width=unit+"px",i.style.borderRight=.2*unit+"px solid "+(r.img[0]?a:"transparent"),i.style.borderTop=.2*unit+"px solid "+(r.img[1]?a:"transparent"),i.style.borderLeft=.2*unit+"px solid "+(r.img[2]?a:"transparent"),i.style.borderBottom=.2*unit+"px solid "+(r.img[3]?a:"transparent")):r==ccw||r==cw?(i.style.background=a,i.style.left=(n+.4)*unit+"px",i.style.height=unit+"px",i.style.width=.2*unit+"px",i.style.animation=["cwise","ccwise"][r.img]+" "+5*speed+"s infinite linear"):console.log("Error: Unknown block entered into display()."),game.appendChild(i)}}return s}function newPath(e,t,s,o){void 0===s&&(s=compass[e][t][0]),void 0===o&&(o=0);var s=compass[e][t][s],n=[[0,1],[-1,0],[0,-1],[1,0]];return e+=n[s][0],t+=n[s][1],0!=e&&e!=span-1&&0!=t&&t!=span-1?newPath(e,t,(s+2)%254,compass[e][t]==empty.goto?o+1:o+2):{x:e,y:t,steps:o}}function newBall(e,t){var s=document.createElement("div");return s.style.background="white",s.style.position="absolute",s.style.top=e*unit+"px",s.style.left=t*unit+"px",s.style.width=.4*unit+"px",s.style.height=.4*unit+"px",s.style.borderRadius="50%25",s.style.margin=.3*unit+"px",s.style.transition=speed+"s top, "+speed+"s left, "+speed+"s background",s.style.transitionTimingFunction="linear",s.style.pointerEvents="none",game.appendChild(s),s}function move(e,t,s,o,n){void 0===n&&(n=compass[s][o][0]),0<s&&s<span-1&&0<o&&o<span-1&&(getByXY(s,o).style.opacity=1);var r=compass[s][o][n],n=[[0,1],[-1,0],[0,-1],[1,0]];if(s+=n[r][0],o+=n[r][1],ball.style.top=unit*s+"px",ball.style.left=unit*o+"px",0!=s&&s!=span-1&&0!=o&&o!=span-1)setTimeout(function(){move(e,t,s,o,(r+2)%254)},1e3*speed);else{if(goal.end.x==e&&goal.end.y==t){for(var i=0;i<edges.length;i++)edges[i].style.background="rgba(0,128,0,0.5)";ball.style.background="green",pts+=goal.end.steps,lvl==span-2?(span++,lvl=1):lvl++}else{for(i=0;i<edges.length;i++)edges[i].style.background="rgba(128,0,0,0.5)";ball.style.background="red",hp--,3<span&&(1==lvl?lvl=--span-2:lvl--)}setTimeout(show,1e4*speed),setTimeout(newGame,2e4*speed)}}function getByXY(e,t){for(var s=0;s<inners.length;s++)if(inners[s].x==e&&inners[s].y==t)return inners[s]}function hide(){for(var e=0;e<inners.length;e++)inners[e].style.opacity=0}function show(){for(var e=0;e<inners.length;e++)inners[e].style.opacity=1}function newGoal(){for(var e={},t=0;t<edges.length;t++)null==e[edges[t].end.steps]?e[edges[t].end.steps]=[edges[t]]:e[edges[t].end.steps].push(edges[t]);return choose(e[(key=Object.keys(e))[key.length-1]])}function enable(){for(var e=0;e<edges.length;e++)edges[e].style.background="transparent",edges[e].addEventListener("mouseover",onmouseover),edges[e].addEventListener("mouseout",onmouseout),edges[e].addEventListener("click",guess)}function disable(){for(var e=0;e<edges.length;e++)edges[e].style.background="rgba(0,0,0,0.25)",edges[e].removeEventListener("mouseover",onmouseover),edges[e].removeEventListener("mouseout",onmouseout),edges[e].removeEventListener("click",guess)}function onmouseover(){this.style.background="rgba(0,0,0,0.25)"}function onmouseout(){this.style.background="transparent"}function guess(){disable(),move(this.x,this.y,goal.x,goal.y)}newGame();