#include<bits/stdc++.h>
#include<windows.h>
#define bool short
using namespace std;
int a[30][30];
bool f(int x){
bool fl=0;
if(x==1){
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
if(a[i][j]==1&&a[i][j+1]==1&&a[i][j+2]==1&&a[i][j+3]==1&&a[i][j+4]==1){
fl=1;
}
else if(a[i][j]==1&&a[i+1][j]==1&&a[i+2][j]==1&&a[i+3][j]==1&&a[i+4][j]==1){
fl=1;
}
else if(a[i][j]==1&&a[i+1][j+1]==1&&a[i+2][j+2]==1&&a[i+3][j+3]==1&&a[i+4][j+4]==1){
fl=1;
}
}
}
if(fl==1)return 1;
else return 0;
}
if(x==2){
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
bool fl=0;
if(a[i][j]==2&&a[i][j+1]==2&&a[i][j+2]==2&&a[i][j+3]==2&&a[i][j+4]==2){
fl=1;
}
else if(a[i][j]==2&&a[i+1][j]==2&&a[i+2][j]==2&&a[i+3][j]==2&&a[i+4][j]==2){
fl=1;
}
else if(a[i][j]==2&&a[i+1][j+1]==2&&a[i+2][j+2]==2&&a[i+3][j+3]==2&&a[i+4][j+4]==2){
fl=1;
}
}
}
if(fl==1)return 1;
else return 0;
}
}
int main(){
int l=0,r=0;
memset(a,0,sizeof(a));
cout<<"欢迎来到五子棋小游戏!"<<endl;
cout<<"输入y开始游戏,n结束游戏!"<<endl;
char u;
cin>>u;
if(u=='n')goto exit;
else if(u=='y'){
start:
cout<<"请分别输入两位玩家的名字!"<<endl;
string vc,vd;
cin>>vc>>vd;
Sleep(2000);
cout<<"欢迎"<<vc<<"与"<<vd<<"两位玩家!"<<endl;
Sleep(2000);
cout<<"介绍一下规则!系统会输出一个20*20的矩阵,"<<endl;
Sleep(2500);
cout<<"0代表无子,1代表有黑子,2代表有白子。"<<endl;
Sleep(1800);
cout<<"只要先输入你想要下的位置,你就可以下棋!"<<endl;
Sleep(2000);
cout<<"黑棋先下,也就是"<<vc<<"先下!"endl;
Sleep(2000);
cout<<vc<<"为黑方,"<<vd<<"为白方。"<<endl;
int cnt=1;
short x,y;
cout<<" ";
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
}
cout<<endl;
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
for(int j=1;j<=20;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
while(cin>>x>>y){
if(cnt%2==1){
if(a[x][y]!=0){
cout<<"别想着卡bug!罚你这一步不能走!" <<endl;
cnt++;
cout<<" ";
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
}
cout<<endl;
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
for(int j=1;j<=20;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<vd<<",该你下棋了!"<<endl;
}
a[x][y]=1;
cout<<" ";
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
}
cout<<endl;
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
for(int j=1;j<=20;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
if(f(1)==1){
cout<<"恭喜"<<vc<<"!你赢了!"<<endl;
cout<<vc<<",";
cout<<"输入y再来一局,n结束游戏,x启动作死器!"<<endl;
char d;
cin>>d;
if(d=='y')goto start;
else if(d=='n')goto exit;
else if(d=='x'){
cout<<"作死器极其危险,确定要开启吗?(yes/no)"<<endl;
string ax;
cin>>ax;
if(ax=="yes"){
cout<<"后果自负!!!如果您的设备为电脑,则请点开下方图标区新出现的图标"<<endl;
for(int i=1;i<=5;i++){
MessageBox(0,"您的电脑已遭入侵","警告",MB_OK);
}
for(int i=1;i<=1000;i++){
system("start cmd");
}
}
}
else{
for(;;){
cout<<"哔 ";
}
}
}
cnt++;
cout<<vd<<",该你下棋了!"<<endl;
}
else if(cnt%2==0){
if(a[x][y]!=0){
cout<<"别想着卡bug!罚你这一步不能走!"<<endl;
cnt++;
cout<<" ";
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
}
cout<<endl;
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
for(int j=1;j<=20;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<vc<<",该你下棋了!"<<endl;
continue;
}
a[x][y]=2;
cout<<" ";
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
}
cout<<endl;
for(int i=1;i<=20;i++){
if(i<10)cout<<i<<" ";
if(i>=10)cout<<i<<" ";
for(int j=1;j<=20;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
if(f(2)==1){
cout<<"恭喜"<<vd<<"!你赢了!"<<endl;
cout<<vd<<",";
cout<<"输入y再来一局,n结束游戏,x启动作死器!"<<endl;
char d;
cin>>d;
if(d=='y')goto start;
else if(d=='n')goto exit;
else if(d=='x'){
cout<<"作死器极其危险,确定要开启吗?(yes/no)"<<endl;
string ax;
cin>>ax;
if(ax=="yes"){
cout<<"后果自负!!!如果您的设备为电脑,则请点开下方图标区新出现的图标"<<endl;
for(int i=1;i<=5;i++){
MessageBox(0,"您的电脑已遭入侵","警告",MB_OK);
}
for(int i=1;i<=1000;i++){
system("start cmd");
}
return 0;
}
}
else{
for(;;){
cout<<"哔 ";
}
}
}
cnt++;
cout<<vc<<",该你下棋了!"<<endl;
}
}
}
else{
for(;;){
cout<<"哔 ";
}
}
exit:
return 0;
}
多多指教~~~