|
|
@ -0,0 +1,470 @@
|
|
|
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
|
|
|
#include<string.h>
|
|
|
|
|
|
|
|
#include"计分板.c"
|
|
|
|
|
|
|
|
extern void jifenban();//调用另一个文件的计分板函数
|
|
|
|
|
|
|
|
void huanying();//欢迎界面
|
|
|
|
|
|
|
|
void printqipan();//打印棋盘
|
|
|
|
|
|
|
|
void initqipan();//初始化棋盘
|
|
|
|
|
|
|
|
void white();//白方下棋
|
|
|
|
|
|
|
|
void black();//黑方下棋
|
|
|
|
|
|
|
|
void startgame();//游戏开始主体
|
|
|
|
|
|
|
|
int panduan(int,int);//判断输赢函数
|
|
|
|
|
|
|
|
int win(); //显示谁赢
|
|
|
|
|
|
|
|
char p[19][19][4];//棋盘数组
|
|
|
|
|
|
|
|
int a,b,c,d,x,y,w,z,B,H;//B,H用来记录白黑棋手的赢局计分
|
|
|
|
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
int whowin;
|
|
|
|
|
|
|
|
int last;//棋盘剩余空位
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
|
|
|
|
huanying();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void startgame() //游戏主体函数
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
initqipan(); /*棋盘初始化*/
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
black();//进入黑方下棋函数
|
|
|
|
|
|
|
|
last--;//检测棋盘剩余空位
|
|
|
|
|
|
|
|
if(win()==1)//判断是否这一步下完就赢了
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
system("cls");//清理屏幕
|
|
|
|
|
|
|
|
//黑棋下完白棋下
|
|
|
|
|
|
|
|
white();//进入白方下棋函数
|
|
|
|
|
|
|
|
last--;//检测棋盘剩余空位
|
|
|
|
|
|
|
|
if(win()==1)//判断是否这一步下完就赢了
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
system("cls");//清理屏幕
|
|
|
|
|
|
|
|
if(last==0)
|
|
|
|
|
|
|
|
win();//平局进入胜利函数,显示谁赢
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" 您是否重新开始游戏?请输入:Y or N ");//询问用户是否再来一局
|
|
|
|
|
|
|
|
scanf("%s",&ch);
|
|
|
|
|
|
|
|
if(ch=='Y')//再来一局
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
startgame();//再次进入游戏函数,开始游戏
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ch=='N')//退出游戏
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printf(" ~游戏结束~");//结束游戏
|
|
|
|
|
|
|
|
jifenban();////////调用另一个文件的计分板函数/////////
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void black() //黑棋落子
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printqipan();
|
|
|
|
|
|
|
|
printf("\n 请黑方落子 \n");//请黑方下棋
|
|
|
|
|
|
|
|
printf(" 示例为“行坐标 空格 纵坐标”“2 3”表示下棋在行坐标为2,纵坐标为3处 \n");//提示用户下棋格式
|
|
|
|
|
|
|
|
printf(" ");
|
|
|
|
|
|
|
|
scanf("%d%d",&x,&y);
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(x>=0&&x<=18&&y>=0&&y<=18)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(p[x][y]," ")==0)//判断棋盘位置是否已有棋子
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x][y],"●");//没有则下黑棋
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
printf(" 您不能在此位置落子,请重新输入坐标:");//已有棋子则提示用户重新落子
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else printf(" 输入的坐标超过了棋盘范围");
|
|
|
|
|
|
|
|
scanf("%d%d",&x,&y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printqipan();
|
|
|
|
|
|
|
|
printf(" 请问少侠要悔棋吗?请输入:Y 悔棋 N不悔棋 ");//询问用户是否需要悔棋
|
|
|
|
|
|
|
|
scanf("%s",&ch);
|
|
|
|
|
|
|
|
if(ch=='Y')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
strcpy(p[x][y]," ");//悔棋则复原上一步棋盘
|
|
|
|
|
|
|
|
black();//进入黑棋下棋函数
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ch=='N')
|
|
|
|
|
|
|
|
return;//不悔棋则退出
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void white() //白旗落子
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printqipan();//进入打印棋盘函数
|
|
|
|
|
|
|
|
printf("\n 请白方落子 \n");//请白方落子
|
|
|
|
|
|
|
|
printf(" 示例为“行坐标 空格 纵坐标”“2 3”表示下棋在行坐标为2,纵坐标为3处 \n");//提示输入坐标格式
|
|
|
|
|
|
|
|
printf(" ");
|
|
|
|
|
|
|
|
scanf("%d%d",&x,&y);
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(x>=0&&x<=18&&y>=0&&y<=18)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(p[x][y]," ")==0)//判断棋盘位置是否已有棋子
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x][y],"○");//没有则下黑棋
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
printf(" 您不能在此位置落子,请重新输入坐标:");//已有棋子则提示用户重新落子
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else printf(" 输入的坐标超过了棋盘范围");
|
|
|
|
|
|
|
|
scanf("%d%d",&x,&y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printqipan();
|
|
|
|
|
|
|
|
printf(" 请问少侠要悔棋吗?请输入:Y 悔棋 N不悔棋 ");//询问是否悔棋
|
|
|
|
|
|
|
|
scanf("%s",&ch);
|
|
|
|
|
|
|
|
if(ch=='Y')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x][y]," ");//悔棋则复原
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
white();//悔棋的重新下棋
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ch=='N')//不悔棋则退出
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int win() ///////显示哪一方赢了
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int havewinner=0;
|
|
|
|
|
|
|
|
int whowin;
|
|
|
|
|
|
|
|
whowin=panduan(x,y); //////表示谁赢了 白方返回 1 黑方返回 2
|
|
|
|
|
|
|
|
if(whowin==1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
havewinner=1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf(" \n 白方胜利\n");
|
|
|
|
|
|
|
|
B++;//计分赢一局
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(whowin==2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
havewinner=1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf(" \n 黑方胜利\n");
|
|
|
|
|
|
|
|
H++;//计分赢一句
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(last==0&&havewinner==0)
|
|
|
|
|
|
|
|
printf("~本局平局~");//平局显示
|
|
|
|
|
|
|
|
return havewinner;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int panduan(int x,int y)/////////////判断函数
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char color[4];//保存下棋方的颜色
|
|
|
|
|
|
|
|
int count=1;//统计个数,针对的同一个线
|
|
|
|
|
|
|
|
int i=1;//水平和竖直方向上
|
|
|
|
|
|
|
|
int j=1;//和i同时用来代表斜方向上
|
|
|
|
|
|
|
|
int winner=0;//1代表白方,2代表黑方
|
|
|
|
|
|
|
|
strcpy(color,p[x][y]);
|
|
|
|
|
|
|
|
//水平的左边
|
|
|
|
|
|
|
|
while(strcmp(color,p[x][y-i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if(count==5)//首先count是5才能来判断谁赢了,不然连资格都没有
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(color,"○")==0)
|
|
|
|
|
|
|
|
winner=1;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
winner=2;
|
|
|
|
|
|
|
|
strcpy(p[x][y],"赢");
|
|
|
|
|
|
|
|
i=1;count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x][y-i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x][y-i],"赢");
|
|
|
|
|
|
|
|
i++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x][y+i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x][y+i],"赢");
|
|
|
|
|
|
|
|
i++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//水平的右边
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x][y+i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if(count==5)//首先count是5才能来判断谁赢了,不然连资格都没有
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(color,"○")==0)
|
|
|
|
|
|
|
|
winner=1;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
winner=2;
|
|
|
|
|
|
|
|
strcpy(p[x][y],"赢");
|
|
|
|
|
|
|
|
i=1;count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x][y+i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x][y+i],"赢");
|
|
|
|
|
|
|
|
i++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x][y-i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x][y-i],"赢");
|
|
|
|
|
|
|
|
i++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//解决垂直的方向
|
|
|
|
|
|
|
|
//垂直上方
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
count=1;//清理掉之前的数据
|
|
|
|
|
|
|
|
while(strcmp(color,p[x-i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if(count==5)//首先count是5才能来判断谁赢了,不然连资格都没有
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(color,"○")==0)
|
|
|
|
|
|
|
|
winner=1;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
winner=2;
|
|
|
|
|
|
|
|
strcpy(p[x][y],"赢");
|
|
|
|
|
|
|
|
i=1;count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x-i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<=5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x-i][y],"赢");
|
|
|
|
|
|
|
|
i++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x+i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<=5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x+i][y],"赢");
|
|
|
|
|
|
|
|
i++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//垂直下方
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x+i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if(count==5)//首先count是5才能来判断谁赢了,不然连资格都没有
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(color,"○")==0)
|
|
|
|
|
|
|
|
winner=1;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
winner=2;
|
|
|
|
|
|
|
|
strcpy(p[x][y],"赢");
|
|
|
|
|
|
|
|
i=1;count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x+i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<=5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x+i][y],"赢");
|
|
|
|
|
|
|
|
i++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x-i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<=5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x-i][y],"赢");
|
|
|
|
|
|
|
|
i++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//解决左上的斜线 上方
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
j=1;
|
|
|
|
|
|
|
|
count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x-i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if(count==5)//首先count是5才能来判断谁赢了,不然连资格都没有
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(color,"○")==0)
|
|
|
|
|
|
|
|
winner=1;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
winner=2;
|
|
|
|
|
|
|
|
strcpy(p[x][y],"赢");
|
|
|
|
|
|
|
|
i=1;j=1;count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x-i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x-i][y-j],"赢");
|
|
|
|
|
|
|
|
i++;j++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i=1;j=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x+i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x+i][y+j],"赢");
|
|
|
|
|
|
|
|
i++;j++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//解决左上的斜线 下方
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
j=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x+i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if(count==5)//首先count是5才能来判断谁赢了,不然连资格都没有
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(color,"○")==0)
|
|
|
|
|
|
|
|
winner=1;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
winner=2;
|
|
|
|
|
|
|
|
strcpy(p[x][y],"赢");
|
|
|
|
|
|
|
|
i=1;j=1;count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x+i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x+i][y+j],"赢");
|
|
|
|
|
|
|
|
i++;j++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i=1;j=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x-i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x-i][y-j],"赢");
|
|
|
|
|
|
|
|
i++;j++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//解决右上的斜线 上方
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
j=1;
|
|
|
|
|
|
|
|
count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x-i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if(count==5)//首先count是5才能来判断谁赢了,不然连资格都没有
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(color,"○")==0)
|
|
|
|
|
|
|
|
winner=1;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
winner=2;
|
|
|
|
|
|
|
|
strcpy(p[x][y],"赢");
|
|
|
|
|
|
|
|
i=1;j=1;count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x-i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x-i][y+j],"赢");
|
|
|
|
|
|
|
|
i++;j++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i=1;j=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x+i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x+i][y-j],"赢");
|
|
|
|
|
|
|
|
i++;j++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//解决右上的斜线 下方
|
|
|
|
|
|
|
|
i=1;
|
|
|
|
|
|
|
|
j=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x+i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if(count==5)//首先count是5才能来判断谁赢了,不然连资格都没有
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(color,"○")==0)
|
|
|
|
|
|
|
|
winner=1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
winner=2;
|
|
|
|
|
|
|
|
strcpy(p[x][y],"赢");
|
|
|
|
|
|
|
|
i=1;j=1;count=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x+i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x+i][y-j],"赢");
|
|
|
|
|
|
|
|
i++;j++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i=1;j=1;
|
|
|
|
|
|
|
|
while(strcmp(color,p[x-i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strcpy(p[x-i][y+j],"赢");
|
|
|
|
|
|
|
|
i++;j++;count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return winner;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void initqipan() /////////初始化棋盘
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i,j;
|
|
|
|
|
|
|
|
for(i=0;i<19;i++)
|
|
|
|
|
|
|
|
for(j=0;j<19;j++)
|
|
|
|
|
|
|
|
strcpy(p[i][j]," ");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void printqipan() /*打印棋盘*/
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i,j;
|
|
|
|
|
|
|
|
system("color e2");//更改屏幕为淡黄色,字体为绿色。
|
|
|
|
|
|
|
|
printf(" 欢迎来到湖工大王力宏五子棋\n");
|
|
|
|
|
|
|
|
printf(" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 \n");
|
|
|
|
|
|
|
|
printf(" ┌ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┬ —┐\n");
|
|
|
|
|
|
|
|
for(i=0,j=0;i<18;i++,j++){
|
|
|
|
|
|
|
|
printf(" %2d │ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│%2d\n",j,p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5],p[i][6],p[i][7],p[i][8],p[i][9],p[i][10],p[i][11],p[i][12],p[i][13],p[i][14],p[i][15],p[i][16],p[i][17],p[i][18],j);
|
|
|
|
|
|
|
|
printf(" ├ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┼ —┤\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" 18 │ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│ %s│18\n",p[18][0],p[18][1],p[18][2],p[18][3],p[18][4],p[18][5],p[18][6],p[18][7],p[18][8],p[18][9],p[18][10],p[18][11],p[18][12],p[18][13],p[18][14],p[18][15],p[18][16],p[18][17],p[18][18]);
|
|
|
|
|
|
|
|
printf(" └ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┴ —┘\n");
|
|
|
|
|
|
|
|
printf(" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 \n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void huanying() //欢迎界面
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char choice;
|
|
|
|
|
|
|
|
int i,j;
|
|
|
|
|
|
|
|
system("color e2"); //更改屏幕为浅黄色,字体为绿色。
|
|
|
|
|
|
|
|
printf("\n\n\n\n\n\n\n\n\n\n\n");
|
|
|
|
|
|
|
|
printf(" ●● ●● ●●●●● ●●●●● ●●●●●●●●●●●\n");/*欢迎界面*/
|
|
|
|
|
|
|
|
for(i=0;i<5;i++)
|
|
|
|
|
|
|
|
printf(" ●● ●● ●● ●● ●●\n");
|
|
|
|
|
|
|
|
printf(" ●●●●●●●●●●● ●● ●● ●●\n");
|
|
|
|
|
|
|
|
for(i=0;i<3;i++)
|
|
|
|
|
|
|
|
printf(" ●● ●● ●● ●● ●●\n");
|
|
|
|
|
|
|
|
printf(" ●● ●● ●●●●●●● ●●\n");
|
|
|
|
|
|
|
|
printf(" ●● ●● ●●●●●● ●●\n\n");
|
|
|
|
|
|
|
|
printf(" 欢迎来到湖南工业大学五子棋游戏\n\n");
|
|
|
|
|
|
|
|
printf(" 五子棋的简介:两个人一起玩的游戏。谁率先在棋盘上连成连续五个线型\n");/*游戏简介*/
|
|
|
|
|
|
|
|
printf(" 的同色棋子,谁就赢得比赛,线型包括直线型和斜45°线型。\n\n");
|
|
|
|
|
|
|
|
printf(" *******************************小艺、小羊联合出品***********************************\n");
|
|
|
|
|
|
|
|
printf(" 【寒 星 溪 月 疏 星 首,花 残 二 月 并 白 莲。】\n");
|
|
|
|
|
|
|
|
printf(" 【雨 月 金 星 追 黑 玉,松 丘 新 宵 瑞 山 腥。】\n");
|
|
|
|
|
|
|
|
printf(" 【星 月 长 峡 恒 水 流,白 莲 垂 俏 云 浦 岚。】\n");
|
|
|
|
|
|
|
|
printf(" 【黑 玉 银 月 倚 明 星,斜 月 明 月 堪 称 朋。】\n");
|
|
|
|
|
|
|
|
printf(" 【二 十 六 局 先 弃 二,直 指 游 星 斜 彗 星。】\n\n");
|
|
|
|
|
|
|
|
printf(" ---这首诗,送给少侠。。。\n\n");/*一首关于五子棋的诗,送给游戏者。*/
|
|
|
|
|
|
|
|
printf(" 少侠,请来一局吧。\n\n");
|
|
|
|
|
|
|
|
printf(" 人人对战\n\n");
|
|
|
|
|
|
|
|
printf(" 少侠,请开始您的游戏:1.开始游戏 2.退出游戏\n\n 您的选择是:");/*让用户选择游戏的开始或者退出游戏*/
|
|
|
|
|
|
|
|
scanf("%s",&choice);
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
|
|
|
|
if(choice=='1'||choice=='2')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(choice=='1')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
startgame(); ////////开始游戏
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(choice=='2')
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
printf(" 输入错误,少侠请重试哦。。。");/*用户不规范输入的提示并要求用户重新输入*/
|
|
|
|
|
|
|
|
scanf("%s",&choice);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|