五子棋_c++版

hanxuyao / 2023-08-11 / 原文

#include <bits/stdc++.h>
using namespace std;
int lie=16,hang=16,lie_shu,hang_shu;
int black_flag[16][16];
bool black=true;
int all[16][16];
void f5(){
    system("cls");
    for(int j=0;j<=hang;j++){
        cout<<setw(3)<<j;
    }
    
    cout<<endl;
    for(int i=0;i<lie;i++)
    {    
        cout<<setw(3)<<i+1;
        for(int j=0;j<hang;j++)
        {
            
            if(black_flag[i][j]==0){
                cout<<setw(3)<<".";
            }else if(black_flag[i][j]==1){
                cout<<setw(3)<<"";
            }else if(black_flag[i][j]==2){
                cout<<setw(3)<<"";
            }
             
        }
        
        cout<<endl;
    }    
    
}
int main(){
    int x,y;
    while(true)
    {
        f5();
        
        if(black==true){
            cout<<"黑棋请下:"<<endl;
        
            cin>>x>>y;
            if(x<=lie&&y<=hang){
                if(black_flag[x-1][y-1]!=0){
                continue;
            }    
            black_flag[x-1][y-1]=1;
                black=false;
            }
            
        }else{
            cout<<"白棋请下:"<<endl;
            
            cin>>x>>y;
            if(x<=lie&&y<=hang){
            if(black_flag[x-1][y-1]!=0){
                continue;
            }    
            black_flag[x-1][y-1]=2;
            black=true;
            }
        }
    //    Sleep(1000);
    }
    return 0;
}