小游戏 扫雷

#include<iostream>
#include<cstdlib>
#include <ctime>
#include<windows.h>
using namespace std;
int main(){
    srand(time(NULL));
    int hp=3,zgls=0,hdls=0,inls=0;
    char ez[10][10]={
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    };
    char ezdt[10][10]={
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    };
    char hd[10][20]={
    '#','#','#','#','#','#','#','#','#','#', 
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#', 
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    };
    char hddt[10][20]={
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#', 
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#',
    };
    char indt[20][20]={
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    };
    char in[20][20]={
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',
    };
    int a=-1;
    while(a!=0){
    system("cls");
    if(a==-1){
        system("color fd");
        cout<<"选择难度"<<endl<<"1.easy"<<endl<<"2.hard"<<endl<<"3.insane"<<endl<<"0.退出"<<endl;
        cin>>a;
    }
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            if(rand()%10==0){
                ezdt[i][j]='@';
                zgls++;
            }else{
                ezdt[i][j]='!';
            }
        }
    }
    for(int i=0;i<10;i++){
        for(int j=0;j<20;j++){
            if(rand()%5==0){
                hddt[i][j]='@';
                hdls++;
            }else{
                hddt[i][j]='!';
            }
        }
    }
    while(inls!=99){
        for(int i=0;i<20;i++){
            for(int j=0;j<20;j++){
                if(rand()%10==0&&inls!=99&&indt[i][j]!='@'){
                    indt[i][j]='@';
                    inls++;
                }else{
                    indt[i][j]='!';
                }
            }
        }
    }
    ezdt[0][0]='!';
    ezdt[1][0]='!';
    ezdt[0][1]='!';
    ezdt[1][0]='!';
    hddt[0][0]='!';
    hddt[1][0]='!';
    hddt[0][1]='!';
    hddt[1][0]='!';
    if(a==1){
        while(1==1){
            system("cls");
            cout<<"剩余雷数:"<<zgls<<" "<<"玩家血量:"<<hp<<endl; 
            cout<<"按0+坐标(xy)打开"<<endl<<"按1+坐标(xy)插旗"<<endl; 
            for(int i=0;i<10;i++){
                cout<<"|";
                for(int j=0;j<10;j++){
                    cout<<ez[i][j]<<"|"; 
                }
                cout<<endl<<"____________________"<<endl;
            }
            int z,x,y;
            cin>>z>>x>>y;
            x--;
            y--; 
            if(z==0&&ezdt[x][y]=='@'){
                cout<<"你踩雷了" ; 
                hp--;
                ez[x][y]='@';
                zgls--;
                Sleep(1000);
            }else if(z==0&&ezdt[x][y]=='!'){
                int ls=0;
                if(ezdt[x-1][y]=='@'){ls++;}
                if(ezdt[x+1][y]=='@'){ls++;}
                if(ezdt[x][y-1]=='@'){ls++;}
                if(ezdt[x][y+1]=='@'){ls++;}
                if(ezdt[x-1][y-1]=='@'){ls++;}
                if(ezdt[x+1][y+1]=='@'){ls++;}
                if(ezdt[x-1][y+1]=='@'){ls++;}
                if(ezdt[x+1][y-1]=='@'){ls++;}
                ez[x][y]=ls+48;
            }
            if(z==1&&ezdt[x][y]=='@'){
                ez[x][y]='P';
                zgls--;
            }else if(z==1&&ezdt[x][y]!='@'){
                cout<<"你标错了";
                hp--;
                Sleep(1000);
            }
            if(hp<=0){
                break;
            }
            if(zgls<=0){
                cout<<"你胜利了"; 
                break;
            }
        }
    }
    if(a==2){
        hp=5;
        while(1==1){
            system("cls");
            cout<<"剩余雷数:"<<hdls<<" "<<"玩家血量:"<<hp<<endl; 
            cout<<"按0+坐标(xy)打开"<<endl<<"按1+坐标(xy)插旗"<<endl; 
            cout<<"/|";
            cout<<endl;
            for(int i=1;i<11;i++){
                cout<<i<<"|";
                for(int j=0;j<20;j++){
                    cout<<hd[i-1][j]<<"|"; 
                }
                cout<<endl<<"__________________________________________"<<endl;
            }
            int z,x,y;
            cin>>z>>x>>y;
            x--;
            y--; 
            if(z==0&&hddt[x][y]=='@'){
                cout<<"你踩雷了" ; 
                hd[x][y]='@';
                hdls--;
                hp--;
                Sleep(1000);
            }else if(z==0&&hddt[x][y]=='!'){
                int ls=0;
                if(hddt[x-1][y]=='@'){ls++;}
                if(hddt[x+1][y]=='@'){ls++;}
                if(hddt[x][y-1]=='@'){ls++;}
                if(hddt[x][y+1]=='@'){ls++;}
                if(hddt[x-1][y-1]=='@'){ls++;}
                if(hddt[x+1][y+1]=='@'){ls++;}
                if(hddt[x-1][y+1]=='@'){ls++;}
                if(hddt[x+1][y-1]=='@'){ls++;}
                hd[x][y]=ls+48;
            }
            if(z==1&&hddt[x][y]=='@'){
                hd[x][y]='P';
                hdls--;
            }else if(z==1&&hddt[x][y]!='@'){
                cout<<"你标错了";
                hp--;
                Sleep(1000);
            }
            if(hp<=0){
                break;
            }
            if(hdls<=0){
                cout<<"你胜利了"; 
                Sleep(1000);
                break;
            }
        }
    }
    if(a==3){
        hp=6;
        while(1==1){
            system("cls");
            cout<<"剩余雷数:"<<inls<<" "<<"玩家血量:"<<hp<<endl; 
            cout<<"按0+坐标(xy)打开"<<endl<<"按1+坐标(xy)插旗"<<endl<<"TIP:请放大到全屏游玩!"<<endl; 
            for(int i=0;i<20;i++){
                cout<<"|";
                for(int j=0;j<20;j++){
                    cout<<in[i][j]<<"|"; 
                }
                cout<<endl<<"________________________________________"<<endl;
            }
            int z,x,y;
            cin>>z>>x>>y;
            x--;
            y--; 
            if(z==0&&indt[x][y]=='@'){
                cout<<"你踩雷了" ; 
                hp--;
                in[x][y]='@';
                zgls--;
                Sleep(1000);
            }else if(z==0&&indt[x][y]=='!'){
                int ls=0;
                if(indt[x-1][y]=='@'){ls++;}
                if(indt[x+1][y]=='@'){ls++;}
                if(indt[x][y-1]=='@'){ls++;}
                if(indt[x][y+1]=='@'){ls++;}
                if(indt[x-1][y-1]=='@'){ls++;}
                if(indt[x+1][y+1]=='@'){ls++;}
                if(indt[x-1][y+1]=='@'){ls++;}
                if(indt[x+1][y-1]=='@'){ls++;}
                in[x][y]=ls+48;
            }
            if(z==1&&indt[x][y]=='@'){
                in[x][y]='P';
                zgls--;
            }else if(z==1&&indt[x][y]!='@'){
                cout<<"你标错了";
                hp--;
                Sleep(1000);
            }
            if(hp<=0){
                break;
            }
            if(inls<=0){
                cout<<"你胜利了"; 
                break;
            }
        }
    }
    a=-1;
    cout<<endl<<"game over!";
    Sleep(3000);
    }
    return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值