问题标题: c++走迷宫小游戏

0
0
陶怡然
陶怡然
修练者
修练者

一个c++走迷宫小游戏

 

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int main(){
    cout<<"◆_ _ ◇_ _ ◆_ _ ◇_ _ ◆_ _ ◇_ _◆"<<endl; 

 

    cout<<"◆_ _ ◇_ _ ◆_ _ ◇_ _ ◆_ _ ◇_ _◆"<<endl; 
    
     
    
    cout<<"‖× game ×‖※  走   ※‖×play ×‖"<<endl;
    
     
    
    cout<<"▓☆start! ☆▓★迷宫 ※▓☆now!☆▓"<<endl; 
    
     
    
    cout<<"◤————— ▲———— ▲———— ◥"<<endl;
    cout<<"              wasd控制               \n";
    char cat=_getch();
    char c[25][25]={
        "#######",
        "#@    #",
        "# ### #",
        "# #   #",
        "# ### #",
        "#   #$#",
        "#######",
    };
    int x=1,y=1;
    system("cls");
    for(int i=0;i<=6;i++){
        for(int j=0;j<=6;j++){
            cout<<c[i][j];
        }
        cout<<"\n";
    }
    while(1){
        char ca=_getch();
        int nx,ny;
        if(ca=='w'){
            nx=x-1,ny=y;
        }else if(ca=='a'){
            nx=x+1,ny=y;
        }else if(ca=='s'){
            nx=x,ny=y-1;
        }else if(ca=='d'){
            nx=x,ny=y+1;
        }
        if(nx>=0&&nx<=6&&ny>=0&&ny<=6){
            if(c[nx][ny]=='$'){
                break;
            }else if(c[nx][ny]!='#'){
                c[x][y]=' ';
                x=nx;
                y=ny;
                c[x][y]='@';
            }
        }
        system("cls");
        for(int i=0;i<=6;i++){
            for(int j=0;j<=6;j++){
                cout<<c[i][j];
            }
            cout<<"\n";
        }
    }
    system("cls");
    cout<<"开始下一关?\n";
    cat=_getch();
    char c1[55][55]={
        "###########",
        "#@        #",
        "# ####### #",
        "# #     # #",
        "# # ##### #",
        "# # #   # #",
        "# # ### # #",
        "#       # #",
        "###### ####",
        "#         $",
        "###########",
    };
    x=1,y=1;
    system("cls");
    for(int i=0;i<=10;i++){
        for(int j=0;j<=10;j++){
            cout<<c1[i][j];
        }
        cout<<"\n";
    }
    while(1){
        char ca=_getch();
        int nx,ny;
        if(ca=='w'){
            nx=x-1,ny=y;
        }else if(ca=='a'){
            nx=x+1,ny=y;
        }else if(ca=='s'){
            nx=x,ny=y-1;
        }else if(ca=='d'){
            nx=x,ny=y+1;
        }
        if(nx>=0&&nx<=10&&ny>=0&&ny<=10){
            if(c1[nx][ny]=='$'){
                break;
            }else if(c1[nx][ny]!='#'){
                c1[x][y]=' ';
                x=nx;
                y=ny;
                c1[x][y]='@';
            }
        }
        system("cls");
        for(int i=0;i<=10;i++){
            for(int j=0;j<=10;j++){
                cout<<c1[i][j];
            }
            cout<<"\n";
        }
    }
    system("cls");
    cout<<"开始下一关?\n";
    cat=_getch();
    char c2[55][55]={
        "#####################",
        "#@#   #   #   #   # #",
        "# # ### # # ### # # #",
        "#   #   # #   #   # #",
        "# ### ### ### ### # #",
        "# #   #   #   #   # #",
        "# # # # # # # # # # #",
        "#   # # # # # # #   #",
        "### # # # # # # # ###",
        "#   # # # # # # #   #",
        "# # # # # # # # # # #",
        "# #   #   #   #   # #",
        "# ### ### ### ### # #",
        "#   #   #   #   #   #",
        "# # ### # # ### # # #",
        "# #   #   #   #   # #",
        "# ### # ### # ### # #",
        "#   #   #   #   #   #",
        "# # # # # # # # # # #",
        "#   # # # # # # #   #",
        "### # # # # # # # ###",
        "#   # # # # # # #   $",
        "#####################",
    };
    x=1,y=1;
    system("cls");
    for(int i=0;i<=22;i++){
        for(int j=0;j<=20;j++){
            cout<<c2[i][j];
        }
        cout<<"\n";
    }
    while(1){
        char ca=_getch();
        int nx,ny;
        if(ca=='w'){
            nx=x-1,ny=y;
        }else if(ca=='a'){
            nx=x+1,ny=y;
        }else if(ca=='s'){
            nx=x,ny=y-1;
        }else if(ca=='d'){
            nx=x,ny=y+1;
        }
        if(nx>=0&&nx<=22&&ny>=0&&ny<=20){
            if(c2[nx][ny]=='$'){
                break;
            }else if(c2[nx][ny]!='#'){
                c2[x][y]=' ';
                x=nx;
                y=ny;
                c2[x][y]='@';
            }
        }
        system("cls");
        for(int i=0;i<=22;i++){
            for(int j=0;j<=20;j++){
                cout<<c2[i][j];
            }
            cout<<"\n";
        }
    }
    system("cls");
    cout<<"◆_ _ ◇_ _ ◆_ _ ◇_ _ ◆_ _ ◇_ _◆"<<endl; 

 

    cout<<"◆_ _ ◇_ _ ◆_ _ ◇_ _ ◆_ _ ◇_ _◆"<<endl; 
    
     
    
    cout<<"‖× game ×‖※  你   ※‖×play ×‖"<<endl;
    
     
    
    cout<<"▓☆start! ☆▓★赢了!※▓☆now!☆▓"<<endl; 
    
     
    
    cout<<"◤————— ▲———— ▲———— ◥"<<endl;
    system("pause");
    return 0;
}


1
1
蒋源
蒋源
新手光能
新手光能

那啥,你的方向好像做的有点问题

 

0
陶怡然
陶怡然
修练者
修练者

wasd=上下左右,按任意键开始下一关

我要回答