五子棋的编程,谁能给改一下啊
#include<graphics.h>#define N 20
const int LINE_NUM=19;
/*define keyboard*/
#define up 0x4800
#define down 0x5000
#define left 0x4b00
#define right 0x4d00
#define esc 0x011b
#define enter 0x1c0d
#define A 0x1e61
#define S 0x1f73
#define D 0x2064
#define W 0x1177
#define space 0x3920
#define Y 0x1579
#define n 0x316e
int gamespeed=5000;
int i,j,key;
struct Solution
{
int x;
int y;/*x,y define the place of the curSolution*/
int yes[N][N];/* 0:no chess,1: white chess,2: Red chess*/
int will;/* 1: white chess is setting,2: Red chess is setting*/
int ok;/*1:white chess is winning,2: white chess is winning*/
}Solution;
void init(void) /*graph drive*/
{
int driver=DETECT,mode=0;
/* registerbgidriver(EGAVGA_driver); */
initgraph(&driver,&mode,"");
}
void drawqp(void)/*draw qi pan*/
{
setcolor(5);
for(i=50;i<=(N-1)*20+30;i+=20)
{
line(50,i,50+(19-1)*20,i);
line(i,50,i,50+(19-1)*20);
}
setcolor(11);
for(i=1;i<3;i++)
{
circle(50+(10-1)*20,50+(10-1)*20,i);
circle(50+(5-1)*20,50+(5-1)*20,i);
circle(50+(5-1)*20,50+(15-1)*20,i);
circle(50+(15-1)*20,50+(5-1)*20,i);
circle(50+(15-1)*20,50+(15-1)*20,i);
}
}
void titleMessage (void) /*input message*/
{
setcolor(15);
settextstyle(0,0,1);
outtextxy(50,20,"White Chess: Up Down Left Right Enter Black Chess: W S A D Space");
}
void place(void)/*画出当前光标的位置*/
{
line(Solution.x-10,Solution.y-10,Solution.x-7,Solution.y-10);
line(Solution.x-10,Solution.y-10,Solution.x-10,Solution.y-7);
line(Solution.x-10,Solution.y+10,Solution.x-10,Solution.y+7);
line(Solution.x-10,Solution.y+10,Solution.x-7,Solution.y+10);
line(Solution.x+10,Solution.y-10,Solution.x+10,Solution.y-7);
line(Solution.x+10,Solution.y-10,Solution.x+7,Solution.y-10);
line(Solution.x+10,Solution.y+10,Solution.x+7,Solution.y+10);
line(Solution.x+10,Solution.y+10,Solution.x+10,Solution.y+7);
}
void judge(void)/*judge the result*/
{
for(i=1;i<N;i++)
{
for(j=1;j<N;j++)
{
if(
((j+4)<N&&Solution.yes[i][j]!=0&&
Solution.yes[i][j]==Solution.yes[i][j+1]&&
Solution.yes[i][j+1]==Solution.yes[i][j+2]&&
Solution.yes[i][j+2]==Solution.yes[i][j+3]&&
Solution.yes[i][j+3]==Solution.yes[i][j+4])||
((i+4)<N&&Solution.yes[i][j]!=0&&
Solution.yes[i][j]==Solution.yes[i+1][j]&&
Solution.yes[i+1][j]==Solution.yes[i+2][j]&&
Solution.yes[i+2][j]==Solution.yes[i+3][j]&&
Solution.yes[i+3][j]==Solution.yes[i+4][j])||
((i+4)<N&&(j+4)<N&&Solution.yes[i][j]!=0&&
Solution.yes[i][j]==Solution.yes[i+1][j+1]&&
Solution.yes[i+1][j+1]==Solution.yes[i+2][j+2]&&
Solution.yes[i+2][j+2]==Solution.yes[i+3][j+3]&&
Solution.yes[i+3][j+3]==Solution.yes[i+4][j+4])||
((i+4)<N&&j>4&&Solution.yes[i][j]!=0&&
Solution.yes[i][j]==Solution.yes[i+1][j-1]&&
Solution.yes[i+1][j-1]==Solution.yes[i+2][j-2]&&
Solution.yes[i+2][j-2]==Solution.yes[i+3][j-3]&&
Solution.yes[i+3][j-3]==Solution.yes[i+4][j-4]))
{
if(Solution.yes[i][j]==1)
Solution.ok=1;
else
Solution.ok=2;
break;
}
}
if(Solution.ok!=0)
break;
}
}
void gameover(void)
{
setcolor(0);
settextstyle(0,0,1);
outtextxy(50,20,"White Chess: Up Down Left Right Enter Black Chess: W S A D Space");
if(Solution.ok==1)
{
outtextxy(488,119,"White");
}
else
{
outtextxy(488,119,"Red");
}
outtextxy(488,189," Chess");
outtextxy(488,259," Win");
outtextxy(488,329," !");
}
/*show the x and y coordinate*/
void ShowXY(void)
{
char str1[10],str2[10];
setfillstyle(SOLID_FILL,7);
bar(50,440,205,470);
setcolor(12);
settextstyle(0,0,2);
sprintf(str1,"X:%d",(Solution.x-30)/20);
sprintf(str2,"Y:%d",(Solution.y-30)/20);
outtextxy(60,450,str1);
outtextxy(135,450,str2);
}
void gameplay(void)
{
for(i=1;i<N;i++)/*initialize chessboard*/
for(j=1;j<N;j++)
Solution.yes[i][j]=0;
Solution.will=1; /* white chess first */
Solution.ok=0;/* result is not decided*/
Solution.x=50+(10-1)*20;/*230*/
Solution.y=50+(10-1)*20;/*initialize cursor ,the position is in the center of the chessboard*/
setcolor(15);
place();
while(1)
{
ShowXY();
key=bioskey(0);
if(key==esc)
break;
/*white chess key is moving*/
else if(key==up&&Solution.y>50&&Solution.will==1)/*50 the top*/
{
setcolor(0);
place();
Solution.y-=20;
}
else if(key==down&&Solution.y<(N-1)*20+30&&Solution.will==1)/*230 the bottow */
{
setcolor(0);
place();
Solution.y+=20;
}
else if(key==left&&Solution.x>50&&Solution.will==1)
{
setcolor(0);
place();
Solution.x-=20;
}
else if(key==right&&Solution.x<(N-1)*20+30&&Solution.will==1)
{
setcolor(0);
place();
Solution.x+=20;
}
/*red chess is moving*/
else if(key==W&&Solution.y>50&&Solution.will==2)
{
setcolor(0);
place();
Solution.y-=20;
}
else if(key==S&&Solution.y<(N-1)*20+30&&Solution.will==2)
{
setcolor(0);
place();
Solution.y+=20;
}
else if(key==A&&Solution.x>50&&Solution.will==2)
{
setcolor(0);
place();
Solution.x-=20;
}
else if(key==D&&Solution.x<(N-1)*20+30&&Solution.will==2)
{
setcolor(0);
place();
Solution.x+=20;
}
else if(key==space&&Solution.yes[(Solution.x-30)/20][(Solution.y-30)/20]==0&&Solution.will==2)
{
setcolor(13);
for(i=1;i<=9;i++)
{
circle(Solution.x,Solution.y,i);/* i is the radius*/
delay(10000);/* delay time 1 s */
}
Solution.yes[(Solution.x-30)/20][(Solution.y-30)/20]=2;
Solution.will=1;
judge();/* judge result*/
if(Solution.ok!=0)
{
gameover();
break;
}
}
else if(key==enter&&Solution.yes[(Solution.x-30)/20][(Solution.y-30)/20]==0&&Solution.will==1)
{
setcolor(15);
for(i=1;i<=9;i++)
{
circle(Solution.x,Solution.y,i);/* i is the radius, draw the concentric circles */
delay(10000);
}
Solution.yes[(Solution.x-30)/20][(Solution.y-30)/20]=1;
Solution.will=2;
judge();
if(Solution.ok!=0)
{
gameover();
break;
}
}
else
continue;
if(Solution.ok!=0)
break;
if(Solution.will==1)
setcolor(15);
else
setcolor(13);
place();
}/*endwhile(1)*/
}
main()
{
while(1)
{
init();
cleardevice();
titleMessage();
drawqp();
setfillstyle(SOLID_FILL,7);
gameplay();
setcolor(15);
settextstyle(0,0,2);
outtextxy(230,450,"Continue? (Y/N)");
while(1)
{
key=bioskey(0);
if(key==Y||key==n||key==esc)
break;
}
if(key==n||key==esc)
break;
}
closegraph();
}