#include<dos.h>
#include<time.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
_AX=0x13;
geninterrupt(0x10);
clock_t T=clock();
srand(time(NULL));
printf("%c[3;28f Nivel=1",27);
char E,far*Q=(char far*)0xA0000000;
int A[][12]={0,0,1,1,1,1,0,0,0,0,0,0,
0,0,0,0,2,0,2,2,2,0,0,0,
0,0,0,3,0,0,0,3,3,3,0,0,
0,0,0,4,0,0,4,4,4,0,0,0,
0,0,0,5,5,0,5,5,0,0,0,0,
0,0,6,6,0,0,0,6,6,0,0,0,
0,0,0,7,7,0,0,7,7,0,0,0};
int B[]={6,2,10,7,3,0,11,8,4,1,9,5};
int N[]={1,2,11,12,13,14,22,23,24,25,34,35};
int e[49],i[275],C[12],D[12],Y[25];
int h,n,x,y,a=6,c=275,d=49,L=0,M=9;
while(c--) i[c]=c/11*2560+c%11*8+436;
while(d--) e[d]=d/7*320+d%7;
for(y=25;y--;Y[y]=0)
for(x=11;x--;)
if(y%24<1||x%10<1) for(h=i[11*y+x],d=49;d--;)
*(Q+h+e[d])=8;
Inicio:
printf("%c[5;28fLineas=%u",27,L);
for(n=0;n<12;n++)
if(C[n]=A[a][n])
if(!*(Q+i[h=N[n]+4])) for(d=49;d--;)
*(Q+i[h]+e[d])=C[n];
else while(1)
if(getch()==27) return 0;
a=rand()%7;
while(n--)
for(h=i[N[n]]+17402,d=49;d--;)
*(Q+h+e[d])=A[a][n];
x=c=4;
do{
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;35f%u",27,10-(M+=M<10));
if(E=='+') printf("%c[3;35f%u",27,10-(M-=M>1));
while(++n<12)
if(D[n]=C[n]) for(h=i[N[n]+c],d=49;d--;)
*(Q+h+e[d])=0;
if(E==77||E==75) x+=E-76;
else if(E!=72) x+=E=11;
else while(n--) D[n]=C[B[n]];
for(n=0;n<12;n++)
if(D[n]&&*(Q+i[N[n]+x])) break;
if(n<12) x=-1;
else if(c!=x) c=x;
else while(n--) C[n]=D[n];
for(n=12;n--;)
if(C[n]) for(h=i[N[n]+c],d=49;d--;)
*(Q+h+e[d])=C[n];
if(E==11) T=clock();
else x=c;
}while(x+1);
while(++n<12)
if(C[n]) Y[y=(N[n]+c)/11]++;
do while(Y[x=y]>8)
for(L++;x--;)
if(Y[x]+Y[x+1]){
Y[x]-=Y[x+1]=Y[x];
c=11*x+1;
for(n=9;n--;c++)
if(*(Q+i[c])+*(Q+i[c+11]))
for(h=x?*(Q+i[c]):0,d=49;d--;)
*(Q+i[c]+e[d])-=*(Q+i[c+11]+e[d])=h;
}
while(--y);
goto Inicio;
}