问题标题: 迷宫

2
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;
}
int main(){
    int level=1;
    bool win=1;
    char a;
    int b=1,c=1,d;
    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){
            cout<<"你赢了";
            return 0;
        }
        if(level==1)     nw(b,c,win);
        if(level==2)     nc(b,c,win);
        if(level==3)     nl(b,c,win);
    }
    return 0;
}//
 


0
已采纳
石峻帆
石峻帆
新手光能
新手光能

我有个方法,可以让你的清屏不闪屏

小建议:如果下一步碰到墙壁,就不移动

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

在这里声明一下,游戏里面的横线是下划线,小心一点。

我要回答