第1个回答 2012-04-13
很多:
#include"dos.h"
#include"math.h"
#include"time.h"
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
int i,j,fx,fy,t,p,q,s,z;
int x[8][4]={ 0,0,0,0,
0,-2,-1,0,
0,0,1,2,
0,0,0,0,
0,-1,0,1,
0,0,1,1,
0,-1,0,1,
0,-1,0,1
};
int y[8][4]={ 0,0,0,0,
0,0,0,1,
0,1,0,0,
0,1,2,3,
0,0,1,0,
0,1,0,1,
0,1,1,0,
0,0,1,1
};
int m[25]={0};
display(int i,int t)
{
for(j=0;j<4;j++)
{
textcolor(i);
p=fx+x[i][j];
q=fy+y[i][j];
gotoxy(p,q); putch(t);
}
}
test()
{
char tmp[2];
s=0;
for(j=0;j<4;j++)
{
q=fy+y[i][j]; p=fx+x[i][j];
gettext(p,q,p,q,&tmp);
if(tmp[0]!=32) s=1;
}
}
turn()
{
for(j=1;j<=3;j++)
{
z=x[i][j]; x[i][j]=-y[i][j]; y[i][j]=z;
}
test();
if(s==1)
{
for(j=1;j<=3;j++)
{
z=y[i][j]; y[i][j]=x[i][j]; x[i][j]=z;
}
}
}
left()
{
int ox;
t=32; display(i,t);
ox=fx; fx--;
test();
if(s==1) fx=ox;
t=219; display(i,t);
}
right()
{
int ox;
t=32; display(i,t);
ox=fx; fx++;
test();
if(s==1) fx=ox;
t=219; display(i,t);
}
inkey()
{
int k;
if(kbhit())
{
k=getch();
if(k==27) exit(0);
if(k==0)
{
k=getch();
switch(k)
{
case 77: right(); delay(50); break;
case 75: left(); delay(50); break;
case 72: turn(); delay(50); break;
break;
}
}
}
}
full()
{
int fj=0;
char tmp[2];
for(j=0;j<=3;j++)
{
fj=fy+y[i][j];
m[fj]=0;
for(p=11;p<=26;p++)
{
gettext(p,fj,p,fj,&tmp);
if(tmp[0]!=32) m[fj]=m[fj]+1;
}
}
}
int main()
{
int z,mabo;
union REGS r;
textmode(C40);
system("cls");
r.x.ax=0x0100;
r.x.cx=0x2000;
int86(0x10,&r,&r);
randomize();
for(i=4;i<=23;i++)
{
gotoxy(10,i); putch(178);
gotoxy(27,i); putch(178);
}
for(i=10;i<=27;i++)
{
gotoxy(i,24); putch(178);
}
gone: i=rand()%7+1; fy=3;fx=18;
while(1)
{
inkey();
display(i,2); delay(32000); delay(32000); delay(18000);
display(i,32);
fy++;
test();
if(s==1)
{
fy--; display(i,2); full();
for(z=23;z>=4;z--)
{
gotoxy(30,z); printf("%d",m[z]);
}
goto gone;
}
}
getch();
}
2.
#include"dos.h"
#include"math.h"
#include"time.h"
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
int i,j,fx,fy,t,p,q,s,z;
int x[8][4]={ 0,0,0,0,
0,-2,-1,0,
0,0,1,2,
0,0,0,0,
0,-1,0,1,
0,0,1,1,
0,-1,0,1,
0,-1,0,1
};
int y[8][4]={ 0,0,0,0,
0,0,0,1,
0,1,0,0,
0,1,2,3,
0,0,1,0,
0,1,0,1,
0,1,1,0,
0,0,1,1
};
int m[25]={0};
display(int i,int t)
{
for(j=0;j<4;j++)
{
textcolor(i);
p=fx+x[i][j];
q=fy+y[i][j];
gotoxy(p,q); putch(t);
}
}
test()
{
char tmp[2];
s=0;
for(j=0;j<4;j++)
{
q=fy+y[i][j]; p=fx+x[i][j];
gettext(p,q,p,q,&tmp);
if(tmp[0]!=32) s=1;
}
}
turn()
{
for(j=1;j<=3;j++)
{
z=x[i][j]; x[i][j]=-y[i][j]; y[i][j]=z;
}
test();
if(s==1)
{
for(j=1;j<=3;j++)
{
z=y[i][j]; y[i][j]=x[i][j]; x[i][j]=z;
}
}
}
left()
{
int ox;
t=32; display(i,t);
ox=fx; fx--;
test();
if(s==1) fx=ox;
t=219; display(i,t);
}
right()
{
int ox;
t=32; display(i,t);
ox=fx; fx++;
test();
if(s==1) fx=ox;
t=219; display(i,t);
}
inkey()
{
int k;
if(kbhit())
{
k=getch();
if(k==27) exit(0);
if(k==0)
{
k=getch();
switch(k)
{
case 77: right(); delay(50); break;
case 75: left(); delay(50); break;
case 72: turn(); delay(50); break;
break;
}
}
}
}
full()
{
int fj=0;
char tmp[2];
for(j=0;j<=3;j++)
{
fj=fy+y[i][j];
m[fj]=0;
for(p=11;p<=26;p++)
{
gettext(p,fj,p,fj,&tmp);
if(tmp[0]!=32) m[fj]=m[fj]+1;
}
}
}
int main()
{
int z,mabo;
union REGS r;
textmode(C40);
system("cls");
r.x.ax=0x0100;
r.x.cx=0x2000;
int86(0x10,&r,&r);
randomize();
for(i=4;i<=23;i++)
{
gotoxy(10,i); putch(178);
gotoxy(27,i); putch(178);
}
for(i=10;i<=27;i++)
{
gotoxy(i,24); putch(178);
}
gone: i=rand()%7+1; fy=3;fx=18;
while(1)
{
inkey();
display(i,2); delay(32000); delay(32000);
display(i,32);
fy++;
test();
if(s==1)
{
fy--; display(i,2); full();
for(z=23;z>=4;z--)
{
gotoxy(30,z); printf("%d",m[z]);
}
goto gone;
}
}
getch();
}
(省略号)