标题:c++语言的绝对经典游戏,新手小白级别,相信是众多开发者最先的试炼
取消只看楼主
return_0
Rank: 8Rank: 8
来 自:五维空间
等 级:禁止访问
威 望:3
帖 子:512
专家分:838
注 册:2020-1-28
结帖率:100%
已结贴  问题点数:20 回复次数:5 
c++语言的绝对经典游戏,新手小白级别,相信是众多开发者最先的试炼
程序代码:
#include<iostream>
#include<conio.h>
#include<cmath>
#include<Windows.h>
#include<ctime>
#include<cstdlib>
#include<stack>
#include<string>
using namespace std;
int xk[1001];
int yk[1001];
int t[10010];
bool key[100];
char maps[100][12][12];
int step;
int allstep;
void pg(){
    cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
int clr;
int x;
int y; 
int xe;
int ye;
/*●■*/ 
void getmap(int level){
    pg();
    for(int i=0;i<12;++i){
        for(int j=0;j<12;++j){
            if(maps[level][i][j]=='w')cout<<"";
            if(maps[level][i][j]=='f')cout<<"";
            if(maps[level][i][j]=='e')cout<<"";
            if(maps[level][i][j]=='p')cout<<"";
            if(maps[level][i][j]=='.')cout<<""; 
        }
        cout<<"\n";
    }
    cout<<"Step count: "<<step<<"\n";
}
void setmap(int level){
    for(int i=0;i<12;++i){
        for(int j=0;j<12;++j){
            if(i==x&&j==y)maps[level][i][j]='p';
            else if(i==xe&&j==ye){
                maps[level][i][j]='e';
            }
            else if(i==xk[level]&&j==yk[level]){
                maps[level][i][j]='f';
            }
            else if(i==0||i==11||j==0||j==11){
                maps[level][i][j]='w';
            } 
            else maps[level][i][j]='.';
        }
    }
}
void new_(int level){
    for(int i=0;i<12;++i){
        for(int j=0;j<12;++j){
            if(i==x&&j==y)maps[level][i][j]='p';
            else if(i==xe&&j==ye){
                maps[level][i][j]='e';
            }
            else if(i==xk[level]&&j==yk[level]){
                maps[level][i][j]='f';
            }
        }
    }
}
void fillwall(int x1,int y1,int x2,int y2,int level){
    if(y1==y2){
        for(int i=x1;i<x2;i++){
            maps[level][i][y1]='w';
        }
    }
    if(x1==x2){
        for(int i=y1;i<y2;i++){
            maps[level][x1][i]='w';
        }
    }
}
void debug(int level){
    cout<<"\n";
    for(int i=0;i<12;++i){
        for(int j=0;j<12;++j){
            cout<<maps[level][i][j];
        }
        cout<<"\n";
    }
}
void putnum(int start , int end, int amt){
    for(int i=start;i<end;i++){
        t[i]=amt;
    }
}
void print(string s,bool flg,char a,int point){
    for(int i=0;i<s.length();++i){
        cout<<s[i];
        if(flg){
            system("color a0");
            system("color 0a");
        }
        Sleep(t[point]);
        point++;
    }
    cout<<a;
}
char see(){
    while(kbhit()){
        return getch();
    }
}
void fillbox(int as,int bs,int ae,int be,int n){
    int cx=as;
    int cy=be;
    int dx=ae;
    int dy=bs;
    fillwall(as,bs,cx,cy,n);
    fillwall(as,bs,dx,dy,n);
    fillwall(ae,be,cx,cy,n);
    fillwall(ae,be,dx,dy,n);
}
void fills(int a,int b,int c,int d,int n,char ch){
    for(int i=a;i<=c;i++){
        for(int j=b;j<=d;j++){
            maps[n][i][j]=ch;
        }
    }
}
void clears(){
    for(int i=0;i<100;++i){
        xk[i]=100;
        yk[i]=100;
    }
}
void fillair(int a,int b,int n){
    maps[n][a][b]='.';
}
void start(){
    allstep=0;
    clr=1;
//    load out all the maps
    for(int i=0;i<10000;i++)cout<<"\n";
//    map 1
    clears();
    key[1]=true;
    x=1;
    y=1;
    xe=1;
    ye=1;
    setmap(1);
//    map 2
    key[2]=true;
    setmap(2);
    fillwall(2,9,11,9,2);
    fillwall(1,7,10,7,2);
    fillwall(2,5,11,5,2);
    fillwall(1,3,10,3,2);
//    map 3
    setmap(3);
    key[3]=false;
    xk[3]=3;
    yk[3]=4;
    fillwall(5,5,5,5,3);
    fillbox(2,2,8,8,3);
    fillbox(4,4,6,6,3);
    fillbox(9,9,1,5,3);
    fillbox(7,2,7,4,3);
    fillwall(2,2,4,2,3);
//    map 4
    setmap(4);
    key[4]=false;
    xk[4]=5;
    yk[4]=5;
    fills(2,2,9,9,4,'w');
    fills(3,3,8,8,4,'.');
    fills(4,4,7,7,4,'w');
    fills(5,5,6,6,4,'.');
    fillair(5,2,4);
    fillair(6,7,4);
//    map 5
    setmap(5);
    key[5]=false;
    fills(1,4,8,10,5,'w');
    fills(1,5,7,10,5,'.');
    fills(1,6,6,10,5,'w');
    fills(1,7,5,10,5,'.');
    fills(1,8,4,10,5,'w');
    fills(1,9,3,10,5,'.');
    xk[5]=3;
    yk[5]=9;
    fills(2,9,2,9,5,'w');
    fillair(1,8,5);
    fillair(6,10,5);
    fillair(1,4,5);
    fills(2,1,2,2,5,'w');
    fills(4,2,4,3,5,'w');
    fills(6,1,6,2,5,'w');
    fills(8,3,8,4,5,'w');
//    map 6
    setmap(6);
    key[6]=false;
    xk[6]=8;
    yk[6]=9;
    fills(2,2,9,9,6,'w');
    fills(2,3,9,3,6,'.');
    fills(2,5,9,5,6,'.');
    fills(2,7,9,7,6,'.');
    fills(2,10,9,10,6,'w');
    fills(2,9,9,9,6,'.');
    fills(2,1,2,9,6,'w');
    fills(9,1,9,9,6,'w');
    fillair(2,1,6);
    fillair(8,2,6);
    fillair(3,4,6);
    fillair(8,6,6);
    fillair(3,8,6);
    fillair(9,1,6);
//    map 7
    setmap(7);
    key[7]=false;
    xk[7]=2;
    yk[7]=10;
    fills(1,2,10,9,7,'w');
    fills(2,1,10,1,7,'w');
    fills(1,10,9,10,7,'w');
    fills(2,1,6,1,7,'.');
    fills(6,2,6,3,7,'.');
    fills(1,3,5,3,7,'.');
    fills(3,4,3,5,7,'.');
    fills(1,4,1,6,7,'.');
    fills(2,6,2,8,7,'.');
    fills(1,8,1,9,7,'.');
    fills(3,8,3,9,7,'.');
    fills(2,10,3,10,7,'.');
    fillair(7,3,7);
    fills(8,1,8,3,7,'.');
    fillair(9,1,7);
    fills(10,1,10,8,7,'.');
    fills(5,5,9,5,7,'.');
    fillair(9,9,7);
    fills(5,6,5,10,7,'.');
    fills(6,10,7,10,7,'.');
    fills(5,7,7,7,7,'.');
    fills(8,7,8,10,7,'.');
    fillair(9,10,7);
    fills(8,9,8,9,7,'w');
}
int main(){
    again:
    start();
    int stage=1;
    if(clr==0||clr==1){
        system("color 0a");
    }
    else if(clr==2){
        system("color fc");
    }
    else if(clr==3){
        system("color 41");
    }
    else if(clr==4){
        system("color ce");
    }
    else if(clr==6){
        system("color 09");
    }
    else if(clr==7){
        system("color 21");
    }
    else if(clr==5){
        system("color f0");
    }
//    putnum(0,3,50);
//    putnum(3,7,200);
//    putnum(7,10,50);
    putnum(0,10,100);
    string s[100]={"===MAZE===","----------------------------------------","CLICK A TO START        CLICK B FOR INFO","CLICK C FOR SETTINGS     CLICK D TO QUIT","----------------------------------------"};//16,24,
    int pin=0;
    print(s[0],0,'\n',0);
    pin=0;
    putnum(0,10,50);
    c:
    putnum(0,160,10);
    for(int i=1;i<=4;++i){
        print(s[i],0,'\n',pin);
    }
    bool start=false;
    while(1){
        switch(see()){
            case 'a':
                start=true;
                break;
            case 'b':
                goto a;
                break;
            case 'c':
                goto b;
                break;
            case 'd':
                return 0;
            default:
                continue;
        }
        if(start==true)goto stt;
    }
    stt:
        step=1;
        if(stage==8){
            cout<<"CONGRATULATIONS, YOU FINISHED ALL THE LEVELS!\nYOU FINISH ALL THE LEVELS WITH "<<allstep<<" STEPS!\nCLICK 'A' TO TRY AGAIN\nCLICK 'B' TO QUIT.\n";
            Sleep(100);
            while(1){
                switch(see()){
                    case 'a':
                        goto again;
                    case 'b':
                        return 0;
                    default:
                        continue;
                }
            } 
        }
        pg();
        if(stage==3){
            cout<<"HINT:STEP ON THE CIRCLE FIRST, AND THEN GO TO THE END POINT\n";
        }
        x=1;
        y=1;
        xe=10;
        ye=10;
        new_(stage); 
        getmap(stage);
        while(1){
//            getmap(stage);
            switch(see()){
                case 'w':
                    if(maps[stage][x-1][y]!='w'){
                        maps[stage][x-1][y]=='p';
                        maps[stage][x][y]='.';
                        x--;
                        new_(stage);
                        getmap(stage);
                        step++;
//                        debug(stage);
                    }
                    break;
                case 's':
                    if(maps[stage][x+1][y]!='w'){
                        maps[stage][x+1][y]=='p';
                        maps[stage][x][y]='.';
                        x++;
                        new_(stage);
                        getmap(stage);
                        step++;
//                        debug(stage);
                    }
                    break;
                case 'a':
                    if(maps[stage][x][y-1]!='w'){
                        maps[stage][x][y-1]=='p';
                        maps[stage][x][y]='.';
                        y--;
                        new_(stage);
                        getmap(stage);
                        step++;
//                        debug(stage);
                    }
                    break;
                case 'd':
                    if(maps[stage][x][y+1]!='w'){
                        maps[stage][x][y+1]=='p';
                        maps[stage][x][y]='.';
                        y++;
                        new_(stage);
                        getmap(stage);
                        step++;
//                        debug(stage);
                    }
                    break;
                default:
                    break;    
            }
            if(x==xk[stage]&&y==yk[stage]){
                key[stage]=true;
            }
            if(x==xe&&y==ye&&key[stage]==true){
                stage++;
                cout<<"\nLEVEL COMPLETE!";
                Sleep(1000);
                pg();
                pg();
                allstep+=step;
                step=0;
                goto stt;
            }
        }
    a:
        pg();
        cout<<"CLICK A TO GO LEFT\n";
        cout<<"CLICK D TO GO RIGHT\n";
        cout<<"CLICK W TO GO UP\n";
        cout<<"CLICK S TO GO DOWN\n";
        cout<<"MOVE TO THE END POINT 'X' TO WIN\n";
        cout<<"EAT the dot TO GET KEY\n";
        goto c;
    b:
        if(clr==0||clr==1){
            system("color 0a");
        }
        else if(clr==2){
            system("color fc");
        }
        else if(clr==3){
            system("color 41");
        }
        else if(clr==4){
            system("color ce");
        }
        else if(clr==5){
            system("color f0");
        }
        else if(clr==6){
            system("color 09");
        }
        else if(clr==7){
            system("color 21");
        }
        pg();
        cout<<"CLICK B TO BACK\n";
        cout<<"start at NO."<<stage<<" stage\n click 'w' to add stage\n click 's' to minute stage\n";
        cout<<"click 1~7 to choose color\n";
        while(1){
            switch(see()){
                case 'b':
                    goto c;
                case 'w':
                    if(stage<7){
                        stage++;
                        cout<<"add success";
                        Sleep(200);
                        goto b;
                    }
                    else{
                        cout<<"add failed, ("<<stage+1<<">7)";
                        system("color 04");
                        Sleep(500);
                        goto b;
                    }
                case 's':
                    if(stage>1){
                        stage--;
                        cout<<"remove success";
                        Sleep(500);
                        goto b;
                    }
                    else{
                        cout<<"minute failed, ("<<stage-1<<"<1)";
                        system("color 04");
                        Sleep(500);
                        goto b;
                    }
                case '1':
                    clr=1;
                    goto b;
                case '2':
                    clr=2;
                    goto b;
                case '3':
                    clr=3;
                    goto b;
                case '4':
                    clr=4;
                    goto b;
                case '5':
                    clr=5;
                    goto b;
                case '6':
                    clr=6;
                    goto b;
                case '7':
                    clr=7;
                    goto b;
            }
        }
    return 0;
}
收到的鲜花
  • 叶纤2020-03-25 00:43 送鲜花  5朵   附言:加油
搜索更多相关主题的帖子: cout clr case int for 
2020-03-24 21:23
return_0
Rank: 8Rank: 8
来 自:五维空间
等 级:禁止访问
威 望:3
帖 子:512
专家分:838
注 册:2020-1-28
得分:0 
回复 2楼 wmf2014
谢谢宝贵建议

2020-03-25 08:50
return_0
Rank: 8Rank: 8
来 自:五维空间
等 级:禁止访问
威 望:3
帖 子:512
专家分:838
注 册:2020-1-28
得分:0 
走迷宫,简单吧

2020-03-25 09:08
return_0
Rank: 8Rank: 8
来 自:五维空间
等 级:禁止访问
威 望:3
帖 子:512
专家分:838
注 册:2020-1-28
得分:0 
回复 6楼 maomao12345
w、a、s、d(代码里看不出来吗)

2020-03-25 09:10
return_0
Rank: 8Rank: 8
来 自:五维空间
等 级:禁止访问
威 望:3
帖 子:512
专家分:838
注 册:2020-1-28
得分:0 
这是最基础的了

2020-03-25 09:18
return_0
Rank: 8Rank: 8
来 自:五维空间
等 级:禁止访问
威 望:3
帖 子:512
专家分:838
注 册:2020-1-28
得分:0 
回复 12楼 叶纤
bug多着呢

2020-03-25 11:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-500556-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.866105 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved