【 tulaoshi.com - 编程语言 】
这个方块写得很简单,我只保留了一部分功能,但能运行,初学编程,不足之处请原谅,不明白之处可以发邮件给我。#includegraphics.h
#includestdio.h
#includedos.h
#includebios.h
#define TIMEINT 5
#define X x-10
#define d 20
#define up 72
#define left 75
#define right 77
#define enter 2
#define esc 1
int x,y,boxshape,boxdir,start=1;//方块横纵坐标,方块外形,方块方向
int board[22][12];//桌面
int fq[7][4][9]={
{{-2,0,-1,0,0,0,0,1,1},
{0,-1,0,0,-1,1,0,1,2},
{-2,0,-2,1,-1,1,0,1,3},
{-1,-1,-1,0,-1,1,0,-1,0}},
{{-1,-1,-1,0,0,0,0,1,1},
{-1,0,-2,1,-1,1,0,0,2},
{-1,-1,-1,0,0,0,0,1,3},
{-1,0,-2,1,-1,1,0,0,0}},
{{-2,0,-2,1,-1,0,0,0,1},
{-1,-1,0,-1,0,0,0,1,2},
{0,0,-2,1,-1,1,0,1,3},
{-1,-1,-1,0,-1,1,0,1,0}},
{{0,-1,-1,0,0,0,0,1,1},
{-1,0,-2,1,-1,1,0,1,2},
{-1,-1,-1,0,-1,1,0,0,3},
{-2,0,-1,0,-1,1,0,0,0}},
{{-1,0,-1,1,0,0,0,1,1},
{-1,0,-1,1,0,0,0,1,1},
{-1,0,-1,1,0,0,0,1,1},
{-1,0,-1,1,0,0,0,1,1}},
{{-3,0,-2,0,-1,0,0,0,1},
{-1,-1,-1,0,-1,1,-1,2,2},
{-3,0,-2,0,-1,0,0,0,1},
{-1,-1,-1,0,-1,1,-1,2,2}},
{{0,-1,-1,0,-1,1,0,0},
{-2,0,-1,0,-1,1,0,1},
{0,-1,-1,0,-1,1,0,0},
{-2,0,-1,0,-1,1,0,1}},};
int collison();
void init();
void drawbox();
void clearoldbox();
int timeCome();
int get_key();
main()
{
int gdrive=VGA,gmode=VGAHI,errorcode;
int i,j,flag,k,m,key;
initgraph(&gdrive,&gmode,"d:c");
errorcode=graphresult();
if(errorcode!=0)
{printf("the graph error:%s",grapherrormsg(errorcode));
printf("press any key to halt");
getch();
exit(1);
}
for(i=0;i22;i++)
board[i][0]=board[i][11]=1;
for(j=0;j12;j++)
board[21][j]=1;
for(i=1;i=20;i++)
for(j=1;j=10;j++)
board[i][j]=0;
init();
while(1)
{
if(start==1){x=15;y=4;boxshape=rand()%7;boxdir=0;drawbox();start=0;}
if(bioskey(1)!=0)
{key=get_key();
switch(key)
{case left: clearoldbox();
x=x-1;
if(collison())x=x+1;
else x=x;
drawbox();
break;
case right: clearoldbox();
x=x+1;
if(collison())x=x-1;
else x=x;
drawbox();
break;
case up: clearoldbox();
boxdir=(boxdir+1)%4;
if(collison())boxdir=(boxdir+3)%4;
else boxdir=boxdir;
drawbox();
break;
case esc:exit(0);
default :break;
}
}
if(timeCome())
{clearoldbox();
y=y+1;
if(collison())
{if(y4)y=y-1;
else {getch();exit(0);}
board[y+fq[boxshape][boxdir][0]-1][x+fq[boxshape][boxdir][1]-9]=1;
board[y+fq[boxshape][boxdir][2]-1][x+fq[boxshape][boxdir][3]-9]=1;
board[y+fq[boxshape][boxdir][4]-1][x+fq[boxshape][boxdir][5]-9]=1;
board[y+fq[boxshape][boxdir][6]-1][x+fq[boxshape][boxdir][7]-9]=1;
drawbox();
for(i=20;i4;i--)
{ flag=1;
for(j=1;j11;j++)
{flag=flag&&board[i][j];
/*if(board[i][j]==0)flag=1;else flag=flag;*