极致简陋的扫雷(ボドボドダ!)

#include 
#include 
#include 
#include 
using namespace std;
int check[103][103];
int movements[101][101];
char birthdaycake[101][101];
int n, gamemode, flag, x, y;
vector<int> temp;
void random_iterator(int n)
{
    for(int i = 1; i <= n; i++)
        temp.push_back(i);
    random_shuffle(temp.begin(), temp.end());
}
void set_mines(int c)
{
    int x, y;
    for(int i = 0; i < c; i++)
    {
        y = (temp[i] / n) +1;
        x = temp[i] -(y-1)*n;
        check[x][y] = 1;
        check[x-1][y]=-1;
        check[x-1][y+1]=-1;
        check[x-1][y-1]=-1;
        check[x+1][y]=-1;
        check[x+1][y+1]=-1;
        check[x+1][y-1]=-1;
        check[x][y+1]=-1;
        check[x][y-1]=-1;
    }
}
int check_around(int x,int y)
{
    int counte=0;
    if(check[x-1][y]==1)counte++;
    if(check[x-1][y+1]==1)counte++;
    if(check[x-1][y-1]==1)counte++;
    if(check[x+1][y]==1)counte++;
    if(check[x+1][y+1]==1)counte++;
    if(check[x+1][y-1]==1)counte++;
    if(check[x][y+1]==1)counte++;
    if(check[x][y-1]==1)counte++;
    return counte;
}
void setter(int x,int y)
{
    if(x<1||y<1||x>n||y>n||movements[x][y]||check[x][y]==1)return;
    movements[x][y]=1;
    int c;
    if(check[x][y]==-1){
        c=check_around(x,y);
        birthdaycake[x][y]='0'+c;
        return;
    }
    birthdaycake[x][y]=' ';
    setter(x-1,y);setter(x+1,y);setter(x,y-1);setter(x,y+1);
}
int main()
{
    while(1){
    cout << "the size of game board? ctrl+z to exit" << endl; //coded
    cin >> n; //by

    int counter=0,maxim=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)birthdaycake[i][j]='#';
    }
    random_iterator(n * n);
    memset(check, 0, sizeof(check));
    memset(movements,0,sizeof(movements));
    cout << "choose the gamemode you want(a positive number more than 5 but less than 10,note that 9 is hardest)" << endl; //cyc

    cin >> gamemode; //2020
    while(gamemode < 5 || gamemode > 9)
    {
        cout << "interesting attempt!However I predicted!Try again!" << endl;
        cin >> gamemode;
    }
    int z=n * n * gamemode * gamemode / 100;
    set_mines(z); //15
    cout << "play the game by adding number 1,2,3,and key in X-Y coordinate(EXAMPLE:1 1 2 means check (1,2) and 2 2 3 means mark (2,3) while 3 2 3 means canceling the mark at (2,3) you win when you have marked all mines)" << endl;
    while(counter!=z){
        cin>>flag>>x>>y;

        if(flag==2){
            if(maxim>=z);
            else{if(check[x][y]==1)counter++;
            cout<<"marked "<<x<<" "<<y<<endl;
            maxim++;}
        }
        else if(flag==3){
            if(check[x][y]==1)counter--;
            cout<<"unmarked"<<x<<" "<<y<<endl;
        }
        else if(flag==1){
            if(check[x][y]==1){
                cout<<"oops!GG"<<endl;
                break;
            }
            else{
                setter(x,y);
                for(int i=1;i<=n;i++){
                    for(int j=1;j<=n;j++)cout<<birthdaycake[i][j];
                    cout<<endl;
                }
            }
        }
    }
    if(counter==z)cout<<"congrAtulAtion!"<<endl;
    }
}

无聊了就一起来玩找bug吧极致简陋的扫雷(ボドボドダ!)_第1张图片

你可能感兴趣的:(oop,projects)