问题标题: 迷宫(更新1)

10
2
已解决
李家兴
李家兴
新手守护
新手守护

#include<iostream>
#include<string>
#include<conio.h>
#include<map>
#include<cmath>
#include<Windows.h>
#include<cstdlib>
using namespace std;
void nw(int &b,int &c,bool &win){
    char x[122][122]={
        {' ','_','_','_','_','_','_','_','_','_','_','_','_','_','_',' '},
        {'|',' ',' ',' ','|',' ','|',' ','|',' ',' ',' ',' ',' ',' ','|'},
        {'|',' ',' ',' ','|',' ','|',' ','|',' ','|',' ',' ',' ',' ','|'},
        {'|','_','_',' ','|',' ','|',' ',' ',' ','|','_','_',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ',' ',' ','|',' ','|','_','_','_',' ',' ','|','_',' ','|'},
        {'|','_','_','_','|',' ','|',' ',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ',' ',' ','|',' ','|','_','_','_',' ','_','|','_',' ','|'},
        {'|',' ','|',' ',' ',' ',' ',' ','|',' ',' ',' ',' ','|',' ','|'},
        {'|',' ','|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|','z','|'},
        {'|','_','|','_','_','_','|','_','_','_','_','_','_','|','_','|'},
    };
    if(!(x[b][c]=='_'||x[b][c]=='|')){
        x[b][c]='+';
    }else{
        b=1,c=1;
    }
    cout<<"第一关\n";
    if(x[b][c]=='z') b=200;
    for(int i=0;i<11;i++){//s
        for(int j=0;j<16;j++){//h
            cout<<x[i][j];
        }
        cout<<endl;
    }
    cout<<endl<<"位置:"<<b<<','<<c<<endl;
}
void nc(int &b,int &c,bool &win){
    char x[122][122]={
        {' ','_','_','_','_','_','_','_','_','_','_','_','_','_','_',' '},
        {'|',' ','|',' ','|',' ',' ',' ','|',' ',' ',' ',' ',' ',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ','|',' ','|',' ','|',' ',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ','|',' ','|','_','|',' ','_','|'},
        {'|',' ','|',' ',' ',' ','|',' ','|',' ',' ',' ','|',' ',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ','|','_',' ',' ','|','_',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ','|',' ','|',' ','|','_','_','_',' ','_','|','_',' ','|'},
        {'|',' ',' ',' ','|',' ','|',' ','|',' ',' ',' ',' ','|',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ',' ',' ',' ',' ',' ','|','z','|'},
        {'|','_','_','_','_','_','|','_','_','_','_','_','_','|','_','|'},
    };
    if(!(x[b][c]=='_'||x[b][c]=='|')){
        x[b][c]='+';
    }else{
        b=1,c=1;
    }
    cout<<"第二关\n";
    if(x[b][c]=='z') b=200;
    for(int i=0;i<11;i++){//s
        for(int j=0;j<16;j++){//h
            cout<<x[i][j];
        }
        cout<<endl;
    }
    cout<<endl<<"位置:"<<b<<','<<c<<endl;
}
void nl(int &b,int &c,bool &win){
    char x[122][122]={
        {' ','_','_','_','_','_','_','_','_','_','_','_','_','_','_',' '},
        {'|',' ',' ',' ',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ',' ',' ','|',' ','|',' ','|'},
        {'|','_','_','_','_','_',' ','|',' ','|',' ',' ',' ','_',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ','|','_','_','_',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ','_','_','_','_','_','|',' ','|','_',' ','|',' ',' ','|'},
        {'|',' ',' ','|',' ',' ',' ','|',' ','|',' ',' ','|',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ','|',' ','_','|',' ',' ','|'},
        {'|',' ',' ',' ',' ','|',' ',' ',' ','|',' ',' ','|',' ','z','|'},
        {'|','_','_','_','|','|','_','_','_','|','_','_','|','_','_','|'},
    };
    if(!(x[b][c]=='_'||x[b][c]=='|')){
        x[b][c]='+';
    }else{
        b=1,c=1;
    }
    cout<<"第三关\n";
    if(x[b][c]=='z') b=200;
    for(int i=0;i<11;i++){//s
        for(int j=0;j<16;j++){//h
            cout<<x[i][j];
        }
        cout<<endl;
    }
    cout<<endl<<"位置:"<<b<<','<<c<<endl;
}
void np(int &b,int &c,bool &win){
    char x[122][122]={
        {' ','_','_','_','_','_','_','_','_','_','_','_','_','_','_',' '},
        {'|',' ',' ',' ',' ',' ','|',' ',' ','|',' ','|',' ',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ','|','|',' ','|',' ','|',' ','|',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ','|',' ','|'},
        {'|',' ','_','_','_','_','_','|',' ','|','_','_','_',' ',' ','|'},
        {'|',' ',' ','|',' ',' ',' ','|',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ',' ','|','_',' ','_','|',' ','|','_',' ','|',' ',' ','|'},
        {'|',' ',' ','|',' ',' ',' ','|',' ','|',' ',' ','|',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ','|',' ','_','|',' ',' ','|'},
        {'|',' ',' ',' ',' ','|',' ','|',' ','|',' ',' ',' ',' ','z','|'},
        {'|','_','_','_','|','|','_','|','_','|','_','_','|','_','_','|'},
    };
    if(!(x[b][c]=='_'||x[b][c]=='|')){
        x[b][c]='+';
    }else{
        b=1,c=1;
    }
    cout<<"第四关\n";
    if(x[b][c]=='z') b=200;
    for(int i=0;i<11;i++){//s
        for(int j=0;j<16;j++){//h
            cout<<x[i][j];
        }
        cout<<endl;
    }
    cout<<endl<<"位置:"<<b<<','<<c<<endl;
}
int main(){
    int level=1;
    bool win=1;
    char a;
    int b=1,c=1,d;
    while(1){
        cout<<"选择关卡:\n";
        cout<<"_____  _____  _____  _____ \n";
        cout<<"|   |  |   |  |   |  |   | \n";
        cout<<"| 1 |  | 2 |  | 3 |  | 4 | \n";
        cout<<"|___|  |___|  |___|  |___| \n";
        cin>>level;
        while(1){
            a=getch();
            system("cls");
            if(b==200) return 0;
            if(a=='w'){
                b--;
            }
            if(a=='s'){
                b++;
            }
            if(a=='d'){
                c++;
            }
            if(a=='a'){
                c--;
            }
            if(a=='b'){
                break;
            }
            if(b==9&&c==14&&level==1){
                level++;
                b=1,c=1;
            }
            if(b==9&&c==14&&level==2){
                level++;
                b=1,c=1;
            }
            if(b==9&&c==14&&level==3){
                level++;
                b=1,c=1;
            }
            if(b==9&&c==14&&level==4){
                cout<<"你赢了";
                return 0;
            }
            if(level==1)     nw(b,c,win);
            if(level==2)     nc(b,c,win);
            if(level==3)     nl(b,c,win);
            if(level==4)     np(b,c,win);
        }
    }
    return 0;
}//
 


1
已采纳
查宣乔
查宣乔
新手守护
新手守护

更新了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

1
1
0
0
0
0
李家兴
李家兴
新手守护
新手守护

更新:

#include<iostream>
#include<string>
#include<conio.h>
#include<map>
#include<cmath>
#include<Windows.h>
#include<cstdlib>
using namespace std;
int defen=0;
void nw(int &b,int &c,bool &win){
    char x[122][122]={
        {' ','_','_','_','_','_','_','_','_','_','_','_','_','_','_',' '},
        {'|',' ',' ',' ','|',' ','|',' ','|',' ',' ',' ',' ',' ',' ','|'},
        {'|',' ',' ',' ','|',' ','|',' ','|',' ','|',' ',' ',' ',' ','|'},
        {'|','_','_',' ','|',' ','|',' ',' ',' ','|','_','_',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ',' ',' ','|',' ','|','_','_','_',' ',' ','|','_',' ','|'},
        {'|','_','_','_','|',' ','|',' ',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ',' ',' ','|',' ','|','_','_','_',' ','_','|','_',' ','|'},
        {'|',' ','|',' ',' ',' ',' ',' ','|',' ',' ',' ',' ','|',' ','|'},
        {'|',' ','|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|','z','|'},
        {'|','_','|','_','_','_','|','_','_','_','_','_','_','|','_','|'},
    };
    if(!(x[b][c]=='_'||x[b][c]=='|')){
        x[b][c]='Y';
    }else{
        b=1,c=1;
    }
    defen++;
    cout<<"第一关\n";
    for(int i=0;i<11;i++){//s
        for(int j=0;j<16;j++){//h
            cout<<x[i][j];
        }
        cout<<endl;
    }
    cout<<endl<<"位置:"<<b<<','<<c<<endl;
    cout<<"步数:"<<defen;
}
void nc(int &b,int &c,bool &win){
    char x[122][122]={
        {' ','_','_','_','_','_','_','_','_','_','_','_','_','_','_',' '},
        {'|',' ','|',' ','|',' ',' ',' ','|',' ',' ',' ',' ',' ',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ','|',' ','|',' ','|',' ',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ','|',' ','|','_','|',' ','_','|'},
        {'|',' ','|',' ',' ',' ','|',' ','|',' ',' ',' ','|',' ',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ','|','_',' ',' ','|','_',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ','|',' ','|',' ','|','_','_','_',' ','_','|','_',' ','|'},
        {'|',' ',' ',' ','|',' ','|',' ','|',' ',' ',' ',' ','|',' ','|'},
        {'|',' ','|',' ','|',' ','|',' ',' ',' ',' ',' ',' ','|','z','|'},
        {'|','_','_','_','_','_','|','_','_','_','_','_','_','|','_','|'},
    };
    if(!(x[b][c]=='_'||x[b][c]=='|')){
        x[b][c]='Y';
    }else if(x[b][c]=='1'){
        defen++;
        x[b][c]=' ';
    }else{
        b=1,c=1;
    }
        defen++;
    cout<<"第二关\n";
    if(x[b][c]=='z') b=200;
    for(int i=0;i<11;i++){//s
        for(int j=0;j<16;j++){//h
            cout<<x[i][j];
        }
        cout<<endl;
    }
    cout<<endl<<"位置:"<<b<<','<<c<<endl;
    cout<<"步数:"<<defen;
}
void nl(int &b,int &c,bool &win){
    char x[122][122]={
        {' ','_','_','_','_','_','_','_','_','_','_','_','_','_','_',' '},
        {'|',' ',' ',' ',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ',' ',' ','|',' ','|',' ','|'},
        {'|','_','_','_','_','_',' ','|',' ','|',' ',' ',' ','_',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ','|','_','_','_',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ','_','_','_','_','_','|',' ','|','_',' ','|',' ',' ','|'},
        {'|',' ',' ','|',' ',' ',' ','|',' ','|',' ',' ','|',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ','|',' ','_','|',' ',' ','|'},
        {'|',' ',' ',' ',' ','|',' ',' ',' ','|',' ',' ','|',' ','z','|'},
        {'|','_','_','_','|','|','_','_','_','|','_','_','|','_','_','|'},
    };
    if(!(x[b][c]=='_'||x[b][c]=='|')){
        x[b][c]='Y';
    }else if(x[b][c]=='1'){
        defen++;
        x[b][c]=' ';
    }else{
        b=1,c=1;
    }
        defen++;
    cout<<"第三关\n";
    if(x[b][c]=='z') b=200;
    for(int i=0;i<11;i++){//s
        for(int j=0;j<16;j++){//h
            cout<<x[i][j];
        }
        cout<<endl;
    }
    cout<<endl<<"位置:"<<b<<','<<c<<endl;
    cout<<"步数:"<<defen;
}
void np(int &b,int &c,bool &win){
    char x[122][122]={
        {' ','_','_','_','_','_','_','_','_','_','_','_','_','_','_',' '},
        {'|',' ',' ',' ',' ',' ','|',' ',' ','|',' ','|',' ',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ','|','|',' ','|',' ','|',' ','|',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ','|',' ','|'},
        {'|',' ','_','_','_','_','_','|',' ','|','_','_','_',' ',' ','|'},
        {'|',' ',' ','|',' ',' ',' ','|',' ',' ',' ',' ','|',' ',' ','|'},
        {'|',' ',' ','|','_',' ','_','|',' ','|','_',' ','|',' ',' ','|'},
        {'|',' ',' ','|',' ',' ',' ','|',' ','|',' ',' ','|',' ',' ','|'},
        {'|',' ',' ',' ',' ',' ',' ','|',' ','|',' ','_','|',' ',' ','|'},
        {'|',' ',' ',' ',' ','|',' ','|',' ','|',' ',' ',' ',' ','z','|'},
        {'|','_','_','_','|','|','_','|','_','|','_','_','|','_','_','|'},
    };
    if(!(x[b][c]=='_'||x[b][c]=='|')){
        x[b][c]='Y';
    }else if(x[b][c]=='1'){
        defen++;
        x[b][c]=' ';
    }else{
        b=1,c=1;
    }
        defen++;
    cout<<"第四关\n";
    if(x[b][c]=='z') b=200;
    for(int i=0;i<11;i++){//s
        for(int j=0;j<16;j++){//h
            cout<<x[i][j];
        }
        cout<<endl;
    }
    cout<<endl<<"位置:"<<b<<','<<c<<endl;
    cout<<"步数:"<<defen;
}
void ns(int &b,int &c,bool &win){
    char x[122][122]={
        {' ','_','_','_','_','_','_','_','_','_','_','_','_','_','_',' '},
        {'|',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ','|',' ','|','|'},
        {'|',' ',' ',' ','|',' ','|',' ','|',' ',' ',' ','|',' ','|','|'},
        {'|',' ','_','_','|',' ','|',' ','|',' ','|',' ','|',' ','|','|'},
        {'|',' ',' ','|','|',' ',' ',' ','|',' ','|',' ','|',' ','|','|'},
        {'|','_','|',' ','|','_','_','_','|',' ','|',' ','|',' ',' ','|'},
        {'|',' ',' ',' ','|',' ',' ',' ',' ',' ','|',' ','|',' ','|','|'},
        {'|',' ','|',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ','|'},
        {'|',' ','|','_','|','_','_','_','_','_','|','_','_','_','_','|'},
        {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','z','|'},
        {'|','_','_','_','_','_','_','_','_','_','_','_','_','_','_','|'},
    };
    if(!(x[b][c]=='_'||x[b][c]=='|')){
        x[b][c]='Y';
    }else if(x[b][c]=='1'){
        defen++;
        x[b][c]=' ';
    }else{
        b=1,c=1;
    }
        defen++;
    cout<<"第五关\n";
    if(x[b][c]=='z') b=200;
    for(int i=0;i<11;i++){//s
        for(int j=0;j<16;j++){//h
            cout<<x[i][j];
        }
        cout<<endl;
    }
    cout<<endl<<"位置:"<<b<<','<<c<<endl;
    cout<<"步数:"<<defen;
}
int main(){
    int level=1;
    bool win=1;
    char a;
    int b=1,c=1,d;
    while(1){
        cout<<"选择关卡(b键退出):\n";
        cout<<"_____  _____  _____  _____  _____ \n";
        cout<<"|   |  |   |  |   |  |   |  |   | \n";
        cout<<"| 1 |  | 2 |  | 3 |  | 4 |  | 5 | \n";
        cout<<"|___|  |___|  |___|  |___|  |___| \n";
        cin>>level;
        while(1){
            a=getch();
            system("cls");
            if(a=='w'){
                b--;
            }
            if(a=='s'){
                b++;
            }
            if(a=='d'){
                c++;
            }
            if(a=='a'){
                c--;
            }
            if(a=='b'){
                break;
            }
            if(b==9&&c==14&&level==1){
                level++;
                b=1,c=1;
            }
            if(b==9&&c==14&&level==2){
                level++;
                b=1,c=1;
            }
            if(b==9&&c==14&&level==3){
                level++;
                b=1,c=1;
            }
            if(b==9&&c==14&&level==4){
                level++;
                b=1,c=1;
            }
            if(b==9&&c==14&&level==5){
                level++;
                b=1,c=1;
            }
            if(level==1)     nw(b,c,win);
            if(level==2)     nc(b,c,win);
            if(level==3)     nl(b,c,win);
            if(level==4)     np(b,c,win);
            if(level==5)     ns(b,c,win);
        }
    }
    return 0;
}//
 

我要回答