有哪位可以帮帮忙 用C语言 写以下代码的悔棋和暂停功能
#include<stdio.h>#include<graphics.h>/*图形图像文件*/
#define left 0x4b00 /*定义左键值*/
#define right 0x4d00
#define down 0x5000
#define up 0x4800
#define esc 0x011b
#define enter 0x1c0d /* 回车键值*/
#define space 0x3920/*暂停*/
#define move 20 /*设计偏移变量*/
#define JZ 4
#define JS 3
#define r 8 /*定义棋子的半径*/
#define N 19 /*定义数组的大小即棋盘为19*19*/
char box[N][N];/*定义数组,确定棋子的状态值*/
int x,y ;/*x轴和y轴坐标*/
int key ;/*获得按键的值*/
int flag=1 ;
void DrawQp(void);/*画棋盘函数*/
void drawcicle(int x,int y,int color);/*画棋
子*/
void ShowMessage(); /*显示轮到哪个玩家的信息*/
void change();/*改变行棋者*/
void who(int x,int y);/*根据不同行棋者画不同
颜色的圆*/
void MoveColor(int x,int y);
void gameplay(); /*人人对战*/
int win(int x,int y);/*判断哪个行棋者赢*/
void main()
{
int gdriver=DETECT,gmode;
clrscr();
initgraph(&gdriver,&gmode,"");
flag=1 ;
DrawQp();
do
{
x=0 ;
y=0 ;
who(x-1,y-1);
do
{
while(bioskey(1)==0);/*如果没有
键按下,则bioskey(1)函数将返回0*/
key=bioskey(0);/*获取从键盘按下
的键值*/
gameplay();/*根据获得的键值进行
下棋操作*/
}
while(key!=enter&&key!=esc);
}
while(key!=esc);
closegraph();
}
void DrawQp(void)
{
int x1,x2,y1,y2 ;
setbkcolor(LIGHTBLUE);
for(x1=1,y1=1,y2=N;x1<=N;x1++)
line((x1+JZ)*move,(y1+JS)*move,(x1+JZ)
*move,(y2+JS)*move);/*按照原先设置的偏移量来
画X轴*/
for(x1=1,y1=1,x2=N;y1<=N;y1++)
line((x1+JZ)*move,(y1+JS)*move,(x2+JZ)
*move,(y1+JS)*move);/*按照原先设置的偏移量来
画y轴*/
for(x1=1;x1<=N;x1++)
for(y1=1;y1<=N;y1++)
box[x1][y1]=0 ;/*使每一个落棋位置为空*/
ShowMessage();
}
void drawcircle(int x,int y,int color)
{
setcolor(color);
x=(x+JZ)*move ;
y=(y+JS)*move ;
setfillstyle(SOLID_FILL,color);
fillellipse(x,y,r,r);
circle(x,y,r);
}
void MoveColor(int x,int y)/*走了一步后恢复
原来格子的状态*/
{
setcolor(15);
if(y<=0||x<=0)/*如果x轴或者y轴不在棋盘上*/
setfillstyle(SOLID_FILL,BLUE);
else
{ if(x==1&&y==1)/*如果棋子从左上角移走,填充方式*/
{line((x+JZ)*move,(y+JS)*move,(x+JZ)*move+r,(y+JS)*move);
line((x+JZ)*move,(y+JS)*move,(x+JZ)*move,(y+JS)*move+r);
}
else
if(x==1&&y==18)/*如果棋子从左下角移走,填充方式*/
{line((x+JZ)*move,(y+JS)*move,(x+JZ)*move+r,(y+JS)*move);
line((x+JZ)*move,(y+JS)*move-r,(x+JZ)*move,(y+JS)*move);
}
else
if(x==18&&y==1)/*如果棋子从右上角移走,填充方式*/
{line((x+JZ)*move-r,(y+JS)*move,(x+JZ)*move,(y+JS)*move);
line((x+JZ)*move,(y+JS)*move,(x+JZ)*move,(y+JS)*move+r);
}
else
if(x==18&&y==18)/*如果棋子从右下角移走,填充方式*/
{line((x+JZ)*move-r,(y+JS)*move,(x+JZ)*move,(y+JS)*move);
line((x+JZ)*move,(y+JS)*move-r,(x+JZ)*move,(y+JS)*move);
}
else
if(x==1) /*如果棋子从左边线角移走,填充方式*/
{
line((x+JZ)*move,(y+JS)*move,(x+JZ)*move+r,(y+JS)*move);
line((x+JZ)*move,(y+JS)*move-r,(x+JZ)*move,(y+JS)*move+r);
}
else
if(x==18)/*如果棋子从右边线移走,填充方式*/
{
line((x+JZ)*move-r,(y+JS)*move,(x+JZ)*move,(y+JS)*move);
line((x+JZ)*move,(y+JS)*move-r,(x+JZ)*move,(y+JS)*move+r);
}
else
if(y==1)/*如果棋子从上边线移走,填充方式*/
{
line((x+JZ)*move-r,(y+JS)*move,(x+JZ)*move+r,(y+JS)*move);
line((x+JZ)*move,(y+JS)*move,(x+JZ)*move,(y+JS)*move+r);
}
else
if(y==18) /*如果棋子从下边线下角移走,填充方式*/
{
line((x+JZ)*move-r,(y+JS)*move,(x+JZ)*move+r,(y+JS)*move);
line((x+JZ)*move,(y+JS)*move-r,(x+JZ)*move,(y+JS)*move);
}
else /*其他填充方式*/
{
line((x+JZ)*move-r,(y+JS)*move,(x+JZ)*move+r,(y+JS)*move);
line((x+JZ)*move,(y+JS)*move-r,(x+JZ)*move,(y+JS)*move+r);
}
}
}
void gameplay()
{
int i ;
int j ;
int xa[5],ya[5];
switch(key)
{
case left:
if(x-1<0)
break ;
else
{
for(i=x-1,j=y;i>=1;i--)
if(box[i][j]==0)
{
drawcircle(x,y,LIGHTBLUE);
MoveColor(x,y);
break ;
}
if(i<1)break ;
x=i ;
who(x,y);
break ;
}
case right :
if(x+1>N)
break ;
else
{
for(i=x+1,j=y;i<=N;i++)
if(box[i][j]==0)
{
drawcircle(x,y,LIGHTBLUE);
MoveColor(x,y);
break ;
}
if(i>N)break ;
x=i ;
who(x,y);
break ;
}
case down :
if((y+1)>N)
break ;
else
{
for(i=x,j=y+1;j<=N;j++)
if(box[i][j]==0)
{
drawcircle(x,y,LIGHTBLUE);
MoveColor(x,y);
break ;
}
if(j>N)break ;
y=j ;
who(x,y);
break ;
}
case up :
if((y-1)<0)
break ;
else
{
for(i=x,j=y-1;j>=1;j--)
if(box[i][j]==0)
{
drawcircle(x,y,LIGHTBLUE);
MoveColor(x,y);
break ;
}
if(j<1)break ;
y=j ;
who(x,y);
break ;
}
case esc :
{closegraph();exit() ;}
case enter :
if(x>=1&&x<=N&&y>=1&&y<=N)
{
if(box[x][y]==0)
{
box[x][y]=flag ;
if(win(x,y)==1)
{
gotoxy(30,4);
if(flag==1)/*如果是玩家1赢*/
{
setbkcolor(LIGHTBLUE);
cleardevice();
printf("The White Win!");
settextstyle(0,0,2);
outtextxy(200,200,"press any key to begin!");
while(bioskey(1)==0);
main();
getch();
closegraph();
exit(0);
}
if(flag==2)/*如果是玩家2赢*/
{
setbkcolor(LIGHTBLUE);
cleardevice();
printf("The Black Win!");
settextstyle(0,0,2);
outtextxy(200,200,"press any key to begin!");
while(bioskey(1)==0);
main();
getch();
closegraph();
exit(0);
}
else
setbkcolor(LIGHTBLUE);
cleardevice();
settextstyle(0,0,6);
outtextxy(180,180,"tie");
settextstyle(0,0,2);
outtextxy(280,440,"press any key to begin");
while(bioskey(1)==0)
main();
}
change();
ShowMessage();
break ;
}
}
else
break ;
}
}
void change()
{
if(flag==1)
flag=2 ;
else
flag=1 ;
}
void who(int x,int y)
{
if(flag==1)
drawcircle(x,y,15);
if(flag==2)
drawcircle(x,y,8);
}
int win(int x,int y)
{
int j,k,n1,n2 ;
while(1)
{
n1=0 ;
n2=0 ;
/*水平向左数*/
for(j=x,k=y;j>=1;j--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*水平向右数*/
for(j=x,k=y;j<=N;j++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*垂直向上数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;k>=1;k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*垂直向下数*/
for(j=x,k=y;k<=N;k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*向左上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j>=1,k>=1;j--,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向右下方数*/
for(j=x,k=y;j<=N,k<=N;j++,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*向右上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j<=N,k>=1;j++,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向左下方数*/
for(j=x,k=y;j>=1,k<=N;j--,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
return(0);
break ;
}
}
/*显示行棋方函数*/
void ShowMessage()
{
setcolor(2);
settextstyle(1,0,1);
gotoxy(300,30);
outtextxy(300,30,"Flag1 and Flag2:move left ,right,up,down");/*显示玩家控制键*/
outtextxy(250,40,"enter to play,esc to exit,F2 to save,F3 to get");
/*轮到Player1行棋*/
if(flag==1)
{
setcolor(2);
settextstyle(1,0,1);
gotoxy(100,30);
/*覆盖原有的字迹*/
outtextxy(100,30,"It's turn to Player2 !");
setcolor(12);
settextstyle(1,0,1);
outtextxy(100,30,"It's turn to Player1 !");
}
/*轮到Player2行棋*/
if(flag==2)
{
setcolor(2);
settextstyle(1,0,1);
/*覆盖原有的字迹*/
outtextxy(100,30,"It's turn to Player1 !");
setcolor(12);
settextstyle(1,0,1);
gotoxy(100,20);
outtextxy(100,30,"It's turn to Player2 !");
}
}