#include<iostream>
#include <vector>
#include <windows.h>
using namespace std;
const int Max=19;
///该位置手否已被占用
bool PZ(vector<vector<int> > &aaa,int x,int y );
///判断胜方
bool SF(vector<vector<int> > &aaa,int b,int x,int y);
///设置字体颜色
void SetColor(unsigned short ForeColor=7,unsigned short BackGroundColor=0)
{
HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon,ForeColor|BackGroundColor);
}
void Show(vector<vector<int> > &aaa,int n,int Color)
{
system("cls");
///设置对应y的坐标
cout<<" ";
for(int i=0;i<n;i++)
if(i>17)
{
if(i%2==0) cout<<(i+2)/2;
else cout<<" ";
}else{
if(i%2==0)cout<<" "<<(i+2)/2;
else cout<<" ";
}
cout<<endl;
for(int i=0;i<n;i++)
{
///设置对应x的坐标
if(i>17)
{
if(i%2==0) cout<<(i+2)/2;
else cout<<" ";
}else{
if(i%2==0)cout<<" "<<(i+2)/2;
else cout<<" ";
}
///输出坐标
for(int j=0;j<n;j++)
{
switch(aaa.at(i).at(j))
{
case 0:cout<<" ";break;
case 2:cout<<"━";break;
case 3:cout<<"+";break;
case 4:cout<<"┷";break;
case 5:cout<<"┯";break;
case 6:cout<<"┠";break;
case 7:cout<<"┨";break;
case 9:cout<<"┃";break;
case 11:cout<<"┏";break;
case 12:cout<<"┓";break;
case 13:cout<<"┗";break;
case 14:cout<<"┛";break;
case 15: SetColor(15);cout<<"●";SetColor();break;///设置字体颜色
case 16:SetColor(12);cout<<"●";SetColor();break;///设置字体颜色
default:break;
}
} cout<<endl;
}
}
void ShowWelcomeA()
{
system("title 欢迎使用 五子棋");
cout<<" 欢迎使用五子棋 "<<endl;
cout<<"***********************************************"<<endl;
cout<<" \“1\” 双人对战 "<<endl;
cout<<" \“2\” 联机对战(IT民工正在狂敲代码中) "<<endl;
cout<<" \“3\” 查看对战记录(IT民工正在狂敲代码中) "<<endl;
cout<<" \“0\”退出游戏 "<<endl<<endl;
cout<<" --by:GodStaff "<<endl;
Sleep(1500);
//system("cls");
}
void SRDZ();
int main(void)
{
int n,s,c;
ShowWelcomeA();
cin>>c;
switch(c)
{
case 1:SRDZ();
break;
case 2:cout<<"(IT民工正在狂敲代码中)"<<endl;
break;
case 3:cout<<"(IT民工正在狂敲代码中)"<<endl;
break;
case 0:cout<<"正在退出。。。"<<endl;
break;
default:cout<<"输入出错,请重新选择:"<<endl;
break;
}
return 0;
}
void SRDZ()
{
int c,d,e,f,g,n,i=0,x,y,s;
bool b=1;
cout<<"请输入要创建N*N的格子:";
cin>>s;
n=(2*s-1);
vector<vector<int> > aaa(n,vector<int>(n));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
///上下边沿
if((i==0 || i==(n-1)) && (j%2))
aaa.at(i).at(j)=2;
else if(i==0 && j%2==0 )
aaa.at(i).at(j)=5;
else if(i==(n-1)&& j%2==0)
aaa.at(i).at(j)=4;
///左右边沿
if((j==0 || j==( n -1)) && (i%2==1))
aaa.at(i).at(j)=9;
else if(j==0 && i%2==0)
aaa.at(i).at(j)=6;
else if(j==( n -1) &&i%2==0)
aaa.at(i).at(j)=7;
///中间绘制
if((i != 0 && i!= (n-1) && j!=0&&j!= (n-1)))
{
if(i%2)
{
if(j%2) aaa.at(i).at(j)=0;
else aaa.at(i).at(j)=9;
}else{
if(j%2) aaa.at(i).at(j)=2;
else aaa.at(i).at(j)=3;
}
}
///四个角
if(i==0 && j==0)
aaa.at(i).at(j)=11;
if(i==0 && j== (n-1))
aaa.at(i).at(j)=12;
if(i== (n-1) && j==0)
aaa.at(i).at(j)=13;
if(i== (n-1) && j== (n-1))
aaa.at(i).at(j)=14;
}
cout<<" \"0\" 红方先手"<<endl<<" \"1\" 白方先手"<<endl<<"默认为白方先手"<<endl;
cout<<"请输入要红方或白方先下子:";cin>>b;
i=i+b;
while(1)
{
if(i%2)
{
Show(aaa,n,i);
cout<<"该白方下子:"<<" 已经下了"<< i-b <<"个子"<<endl;
loop1:
cin>>x>>y;
if(!PZ(aaa,2*x-2,2*y-2))
{
aaa.at(2*x-2).at(2*y-2)=15;///" ● ";
cout<<aaa.at(2*x-2).at(2*y-2);
}
else
{cout<<"该位置已被占用,请重新输入:";goto loop1;}
if(SF(aaa,15,x,y)) {Show(aaa,n,i);cout<<"白方胜利";Sleep(4000);break;}
}
else
{
Show(aaa,n,i);
cout<<"该红方下子:"<<" 已经下了"<< i-b <<"个子"<<endl;
loop2:
cin>>x>>y;
if(!PZ(aaa,2*x-2,2*y-2))
{aaa.at(2*x-2).at(2*y-2)=16;///" ● "
cout<<aaa.at(2*x-2).at(2*y-2);
}
else
{cout<<"该位置已被占用,请重新输入:";goto loop2;}
if(SF(aaa,16,x,y)) {Show(aaa,n,i);cout<<"红方胜利!!";Sleep(4000);break;}
}
i++;
}
cout<<"游戏结束!!"<<endl;
Sleep(10000);
}
///该位置手否已被占用
bool PZ(vector<vector<int> > &aaa,int x,int y )
{
if( aaa.at(x).at(y)==15 || aaa.at(x).at(y)==16)
return 1;
else return 0;
}
///判断胜方
bool SF(vector<vector<int> > &aaa,int b,int x,int y)
{
int i=1,j=1;
/// 1
while(1)
{
if(aaa.at(x+2*i).at(y+2*i)==b)
i++;
else break;
}
while(1)
{
if(aaa.at(x-2*j).at(y-2*j)==b)
j++;
else break;
}
if(i+j==6)
return 1;
i=1;j=1;
/// 2
while(1)
{
if(aaa.at(x+2*i).at(y)==b)
i++;
else break;
}
while(1)
{
if(aaa.at(x-2*j).at(y)==b)
j++;
else break;
}
if(i+j==6)
return 1;
i=1;j=1;
/// 3
while(1)
{
if(aaa.at(x).at(y+2*i)==b)
i++;
else break;
}
while(1)
{
if(aa
a.at(x).at(y-2*j)==b)
j++;
else break;
}
if(i+j==6)
return 1;
i=1;j=1;
/// 4
while(1)
{
if(aaa.at(x-2*i).at(y+2*i)==b)
i++;
else break;
}
while(1)
{
if(aaa.at(x+2*j).at(y-2*j)==b)
j++;
else break;
}
if(i+j==6)
return 1;
else return 0;
}