This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
jsame4k.html
1 lines (1 loc) · 4 KB
/
jsame4k.html
1
<!DOCTYPE html><html><title>JSame4k</title><style type="text/css">body{background-color:#fff;color:#999;margin:0}#w{display:table;position:absolute;height:100%;width:100%}#c{display:table-cell;vertical-align:middle}#j{box-shadow:0 0 30px 0 rgba(0,0,0,0.75);display:block;height:418px;margin:0 auto;width:528px}p{bottom:0;font-family:sans-serif;font-size:12px;left:0;position:fixed;text-align:center;width:100%}</style><p>JSame4k | © 2014 Gabor Bata</p><div id="w"><div id="c"><canvas id="j" width="528" height="418"></canvas></div></div><script>!function(){function t(t){var e=m.getBoundingClientRect();return{x:m.width/e.width*(t.clientX-e.left),y:m.height/e.height*(t.clientY-e.top)}}function e(t){for(var e=1;e<arguments.length;e++)t=t.replace(/%s/,arguments[e]);return t}function n(t){return[t>>16,t>>8&255,255&t]}function r(t){return t=(t[0]<<16|t[1]<<8|t[2]).toString(16),"#"+(Array(7-t.length).join("0")+t)}function i(t){var e=t[0],n=t[1];t=t[2];var r=~~(1/(1-k));return 0==e&&0==n&&0==t?[r,r,r]:(e>0&&r>e&&(e=r),n>0&&r>n&&(n=r),t>0&&r>t&&(t=r),[Math.min(~~(e/k),255),Math.min(~~(n/k),255),Math.min(~~(t/k),255)])}function o(){g=Array(2*j.length-1);for(var t=0;t<j.length;t++)g[t]=f(n(j[t]),!0),g[2*j.length-2-t]=f(n(j[t]),!1)}function f(t,e){var n=document.createElement("canvas");n.width=b,n.height=b;var o=n.getContext("2d"),f=e?i(t):t,l=i(f),a=[~~(f[0]*k),~~(f[1]*k),~~(f[2]*k)];o.fillStyle=r(a),o.fillRect(0,0,b,b),o.fillStyle=r(f),o.fillRect(0,0,b-1,b-1),o.fillStyle=r(l),o.fillRect(1,1,b-3,b-3);var u=o.createLinearGradient(2,2,b-4,b-4);return u.addColorStop(0,r(f)),u.addColorStop(1,r(l)),o.fillStyle=u,o.fillRect(2,2,b-4,b-4),e&&(o.fillStyle=r(a),o.fillRect(8,8,b-16,b-16)),n}function l(){S.fillStyle="#262c4b",S.fillRect(0,0,C*b+2*G,M*b+2*G),S.fillStyle="#484d50",S.fillRect(0,M*b+2*G,C*b+2*G,A),S.font="bold 12px sans-serif",x[1]=E>1?e("Marked: %s (%s points)",E,E*E-4*E+4):w?"":"Game Over!",x[2]=e("Score: %s",p);for(var t=0;t<x.length;t++)S.fillStyle="#62696a",S.fillRect(~~((C*b+2*G)/3)*t+1,M*b+2*G+1,~~((C*b+2*G)/3)-2,A-2),S.fillStyle="#fff",S.fillText(x[t],~~((C*b+2*G)/6)*(2*t+1)-~~(S.measureText(x[t]).width/2),M*b+2*G+~~(A/2)+4);for(t=0;C>t;t++)for(var n=0;M>n;n++)S.drawImage(g[s[C*n+t]+T],t*b+G,n*b+G)}function a(){p=E=0,L=!1,w=!0;for(var t=0;t<s.length;t++)s[t]=~~(Math.random()*T+1)}function u(t,e){return 0>t||0>e||t>C-1||e>M-1?0:s[C*e+t]}function c(t,e){return 0>u(t,e)?-1*u(t,e):u(t,e)}function d(t,e,n){return 0>u(t,e)||n!=c(t,e)||0==u(t,e)?0:(n=1,s[C*e+t]=-1*c(t,e),n+=d(t-1,e,c(t,e)),n+=d(t,e-1,c(t,e)),n+=d(t+1,e,c(t,e)),n+d(t,e+1,c(t,e)))}function v(){for(var t=0;t<s.length;t++)s[t]=0>s[t]?-1*s[t]:s[t]}function y(t,e,n,r){t=C*e+t,n=C*r+n,r=s[t],s[t]=s[n],s[n]=r}function h(e,n){var r=t(e),i=r.x<G?-1:~~((r.x-G)/b),r=r.y<G?-1:~~((r.y-G)/b);(!(R.x==i&&R.y==r||0>u(i,r))||n)&&((0!=u(i,r)||0!=u(R.x,R.y))&&(v(),E=d(i,r,c(i,r)),l()),R.x=i,R.y=r)}var g,s,x,m,S,w,R,p,E,L,C=20,M=15,b=26,A=20,G=4,j=[9522747,8094582,4022919,11503186,2501707],k=.7,T=j.length-1;!function(){m=window.j,S=m.getContext("2d"),o(),s=Array(C*M),R={x:-1,y:-1},x=["New Game","",""],a(),l(),m.addEventListener("mousedown",function(e){var n,r,i,o=t(e);0<o.x&&o.x<~~((C*b+2*G)/3)-1&&o.y>M*b+2*G&&o.y<M*b+2*G+A-1&&(a(),w=!0,E=0,l());var f=o.x<G?-1:~~((o.x-G)/b),v=o.y<G?-1:~~((o.y-G)/b);for(r=n=0;r<s.length;r++)0>s[r]&&n++;if(n>=2){for(r=0;r<s.length;r++)0>s[r]&&(s[r]=0);for(i=0;C>i;i++)for(e=!0;e;)for(e=!1,o=1;M>o;o++)0==u(i,o)&&0!=u(i,o-1)&&(y(i,o,i,o-1),e=!0);for(e=!0;e;)for(e=!1,i=1;C>i;i++)if(0==u(i-1,M-1)&&0!=u(i,M-1)){for(o=0;M>o;o++)y(i,o,i-1,o);e=!0}for(p+=n*n-4*n+4,e=!0,r=n=0;C>r;r++)for(i=0;M>i;i++)if(0!=u(r,i)&&(n++,o=c(r,i),c(r-1,i)==o||c(r,i-1)==o||c(r+1,i)==o||c(r,i+1)==o)){e=!1;break}0!=n||L||(L=!0,p+=1e3),E=0,e||(E=d(f,v,c(f,v))),e&&w&&(w=!1,E=0),l()}}),m.addEventListener("mouseup",function(t){h(t,!0)}),m.addEventListener("mousemove",function(t){h(t,!1)}),m.addEventListener("mouseover",function(t){h(t,!1)}),m.addEventListener("mouseout",function(e){var n=t(e);e=n.x<G?-1:~~((n.x-G)/b),n=n.y<G?-1:~~((n.y-G)/b),v(),E=0,l(),R.x=e,R.y=n})}()}();</script></html>