Un tetris en unas lineas de HTML/Javascript

Pues en esta web he visto un tetris que presume de entrar en 565bytes de código:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<body onKeyDown=K=event.keyCode><script>X=[Z=[B=A=12]];h=e=K=t=P=0;function Y()
{C=[d=K-38];c=0;for(i=4;i--*K;K-13?c+=!Z[h+p+d]:c-=!Z[h+(C[i]=p*A-Math.round(p/
A)*145)])p=B[i];!t|c+4?c-4?0:h+=d:B=C;for(f=K=i=0;i<4;f+=Z[A+p])X[p=h+B[i++]]=1
if(e=!e){if(f|B){for(l=228;i--;)Z[h+B[i]]=k=1;for(B=[[-7,-20,6,17,-9,3,6][t=++t
%7]-4,0,1,t-6?-A:-1];l--;h=5)if(l%A)l-=l%A*!Z[l];else for(P+=k++,j=l+=A;--j>A;)
Z[j]=Z[j-A]}h+=A}for(i=S="";i<240;X[i]=Z[i]|=++i%A<2|i>228)i%A?0:S+="<br>",S+=X
[i]?"■":"_";document.body.innerHTML=S+P;Z[5]||setTimeout(Y,99-P)}Y()</script>
</body>
</html>


Aquí el código más comprensible :P


<body onKeyDown=K=event.keyCode><pre><script>

function Y(){
   Z[11]=P;
   E=B[t];
   f=0;
   if(K)
     if(K!=32){
       d=K-37?1:-1
       for(i=0;i<4;i++)
         f+=Z[h+E[i]+d]==S;
       f?0:h+=d;
     }else{
       C=[];
       for(i=0;i<4;i++){
         p=E[i];
         v=Math.round(p/12);
         w=p-v*12;
         C[i]=w*12-v;
         if(Z[h+C[i]]==S)f=1;
       }
       t*!f?E=B[t]=C:0;
     }
   K=0;

   for(f=i=0;i<4;i++){
     f+=Z[12+(p=h+E[i])]==S;
     Z[240+p]=S
   }
   if(f){
     for(i=0;i<4;i++)Z[h+E[i]]=S;
     t=++t%7;
     h=17
   }else h+=12;

   for(k=1,i=19;i--;){

     for(j=11;--j&&Z[i*12+j]==S;);
     if(!j){
       P+=k++;
       for(j=++i*12;j>2*12;)Z[j]=Z[j---12]
   }
}

   for(i=240;i--;){
     D.all(6+i).innerHTML=Z[240+i];
     Z[240+i]=Z[i]
   }
   Z[5]!=S?setTimeout(Y,99):0;
}

B=[[-11],[-24],[2],[13],[-13],[-1],[2,-1]];

for(i=0;i<7;i++)B[i].push(0,1,-12);
D=document;

h=17;
Z=[];
for(K=t=P=i=0;i<240;){
  D.write(i%12?"":"\n","<b></b>");
  Z[240+i]=Z[i]=++i%12<2||i>228?S="□":" ";
}

Y();
</script>


Y aquí una pequeña prueba que he visto en este blog: [Tetris]

1 comentarios:

Arkangel dijo...

Acojonanting!