Este es otro de los post reencauchados de mi antiguo blog.
Se trata de un tetris programado en python, son tan sólo 15 líneas de código, cada línea no contiene más de 80 caracteres:
import random,pygame;R=range;L=len;W=10;Q=H=20;P=pygame;G=255;v=lambda b:['0'*W
]*(H-L(b))+b;a=p=x=y=c=d=0;D=P.display;T=P.USEREVENT;m=lambda i,j:j-y in R(L(p)
)and i-x in R(L(p[0]))and'0'!=p[j-y][i-x]and`d+1`or b[j][i];S=D.set_mode((W*Q,H
*Q));k=lambda p,x,y:1-max(p[i][j]!='0'and(y+i>=H or x+j<0or x+j>=W or’0?!=b[i+y
][j+x])for j in R(L(p[0]))for i in R(L(p)));n=E=b=v([]);P.time.set_timer(T,100)
exec(”while E!=P.QUIT:\n E=P.event.wait().type;K=P.key.get_pressed()\n if n:d=”
“random.randrange(7);q=’111?;p=[[’1?*4],[’010?,q],[’110?,’011?],[’011?,’110?],”
“[q,’100?],[’11?,’11?],[q,’001?]][d];x=W/2-L(p[0])/2;y=n=0\n if E==T:\n [P.dr”
“aw.rect(S,[(h,g,f)for f in(0,G)for g in(0,G)for h in(0,G)][int(m(i/H,i%H))],(”
“(i/H*Q,i%H*Q),(Q,Q)))for i in R(W*H)];t='’.join;z=[t([p[L(p)-1-i][j]for i in ”
“R(L(p))])for j in R(L(p[0]))];p,x,y=[p,z][K[P.K_UP]*k(z,x,y)],x-(K[P.K_LEFT]*”
“k(p,x-1,y))+(K[P.K_RIGHT]*k(p,x+1,y)),y+(K[P.K_DOWN]*k(p,x,y+1));B=[t([m(i,j)”
“for i in R(W)])for j in R(H)];e=sum(r.find(’0?)<0for r in B);D.flip();c+=1\n "
" if c%5<1:\n if k(p,x,y+1)<1:\n if y<1:break\n a+=e and 2**e;n=b=v([r"
" for r in B if~r.find('0')])\n else:y+=1\n");print 'GAME OVER: score %i'%a
Y gracias a Anieto me encuentro con este otro tetris es en Javascript, en más o menos 8 líneas 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>



Hace mucho que no juego tetris, depronto asi hasta em den ganas xD
↵ ResponderSerá reencauchado, sin embargo, recordar es volver a vivir.
↵ ResponderPD:Si estan interesados en hacer intercambio de enlaces (tecnologia, informatica, relacionados)contactame en link.exchange.mariana@gmail.com