#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
clock_t T;
srand(time(NULL));
textmode(C40);
_setcursortype(_NOCURSOR);
char far*p=(char far*) 0xB8000000L;
char E,A[][12]={"000000111100",
"000020222000",
"000300033300",
"000400444000",
"000055055000",
"006600066000",
"000770077000"};
int B[]={6,2,10,7,3,0,11,8,4,1,9,5};
int N[]={2,4,80,82,84,86,160,162,164,166,242,244};
int C[12],D[12],Y[25],I[25];
int a,c,d,n,x,y,z=6,M=9,L=0;
printf("%c[3;29f Nivel=1",27);
for(y=25;y--;)
for(I[y]=80*y+31,Y[y]=x=0;x<11;x++)
if(!y||y>23||!x||x>9){*(p+I[y]+2*x-2)=8;
*(p+I[y]+2*x-3)=219;
}
else *(p+I[y]+2*x-2)=0;
Inicio:
a=z;
z=rand()%7;
for(n=12;n--;)
*(p+N[n]+621)=(A[z][n]-48)<<4;
printf("%c[5;29fLineas=%u",27,L);
c=117;
for(n=12;n--;)
if(C[n]=A[a][n]-48)
if(!*(p+N[n]+c)) *(p+N[n]+c)=C[n]<<=4;
else while(1) if(getch()==27) return 0;
T=clock();
while(n<0){while(E=kbhit()) getch();
do if(kbhit()) E=getch();
while(!E&&clock()-T<M);
if(E==27&&getch()==27) return 0;
if(E=='-') printf("%c[3;36f%u",27,10-(M+=M<10));
if(E=='+') printf("%c[3;36f%u",27,10-(M-=M>1));
while(++n<12)
if(C[n]) *(p+N[n]+c)=0;
if(E==72){while(n--)
if((D[n]=C[B[n]])&&*(p+N[n]+c)) break;
if(n<0)
for(n=12;n--;)
if(C[n]=D[n]) *(p+N[n]+c)=C[n];
}
else{if(E==77||E==75) d=c-2*(76-E);
else d=c+(E=80);
while(n--)
if(C[n]&&*(p+N[n]+d)) break;
if(n<0)
for(c=d,n=12;n--;)
if(C[n]) *(p+N[n]+c)=C[n];
}
if(n>=0)
for(n=0;n<12;n++)
if(C[n]) *(p+N[n]+c)=C[n];
if(E==80) T=clock();
else n=-1;
}
for(y=c/80;y<c/80+4;y++)
if(y>23) break;
else for(Y[y]=n=x=0;x<17;x+=2)
if(*(p+I[y]+x))
if(++n>8)
for(L++,Y[y]=x=0;x<17;x+=2)
*(p+I[y]+x)=0;
else Y[y]=1;
while(--y)
if(!Y[d=y])
while(--d)
if(Y[n=d])
for(Y[y]=d=1,Y[n]=x=0;x<17;x+=2)
*(p+I[n]+x)-=*(p+I[y]+x)=*(p+I[n]+x);
goto Inicio;
}