zoukankan      html  css  js  c++  java
  • 自编迷宫游戏

    自编的游戏,想要的可以考走,会不定时更新

    主要是我怕代码丢了

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<conio.h>
    #include<windows.h>
    #include<time.h>
    using namespace std;
    char a1[11][11]={"##########",
                     "#o #   # #",
                     "# #   #  #",
                     "# #### # #",
                     "#        #",
                     "# ####   #",
                     "# #  # # #",
                     "##   #   #",
                     "#    ##  E",
                     "##########"},
         a2[16][16]={"###############",
                     "#o#   #  #    #",
                     "# # # #    #  #",
                     "#        ######",
                     "##### #       #",
                     "#     #####   #",
                     "#   ##       ##",
                     "#     #  # #  #",
                     "### #     ### #",
                     "##  ###  #    #",
                     "#          #  #",
                     "##########E####"},
         a3[19][19]={"##################",
                     "#o#      #       #",
                     "#   ## #   #   ###",
                     "###   #   #  #   #",
                     "# ##    ##  ##  ##",
                     "#   ###        ###",
                     "# ##   ### ##  # #",
                     "#    #     # #  ##",
                     "#  ######     #  #",
                     "#      # #  #### #",
                     "#### ###   #     #",
                     "#  # #   ##  ### #",
                     "# #      #  ##   #",
                     "##### ##   ##E # #",
                     "#     #  #  #### #",
                     "## #  ##  #   #  #",
                     "#  #      # #   ##",
                     "##################"},
         a4[19][19]={"##################",
                     "#o#E    #        #",
                     "# ## ##   #####  #",
                     "#  ##  # ##  # # #",
                     "## #  #     #    #",
                     "#   #   ## ##   ##",
                     "# #  # ##   ###  #",
                     "#  ###   # ###   #",
                     "##     ##      ###",
                     "## # # #  # # #  #",
                     "#    # ## # #    #",
                     "# # ##     # #   #",
                     "# #    # #   ##  #",
                     "# ####  #  #    ##",
                     "#   #  # # #  #  #",
                     "# # # ## # #### ##",
                     "#   #    #       #",
                     "##################"},
         a5[19][19]={"##################",
                     "#o              ##",
                     "#   ## # #  # #  #",
                     "##  #    #   #  ##",
                     "#    #     ## ## #",
                     "# #### ####      #",
                     "#    #  # #  # ###",
                     "#  # #  #  # #   #",
                     "# #    #    #  # #",
                     "#   #########  # #",
                     "# #  ##       #  #",
                     "#  #    #######  #",
                     "#    # ##E#      #",
                     "#  #  ##  ## ### #",
                     "# #  ##   #   ## #",
                     "# ## #  ### #  # #",
                     "#     #      #   #",
                     "##################"}, 
         a6[19][19]={"##################",
                     "#                #",
                     "# #####  #  #  #X#",
                     "#  o#  #  #  #  ##",
                     "# ###X  #  X  #  #",
                     "# #      X  #  # #",
                     "# #  #X  X  X X  ",
                     "#  #  ##  #     ##",
                     "##  #  #X   ###  #",
                     "# #  #  #  #     #",
                     "#  #  # X#X  # X #",
                     "#   #  #E## #  # #",
                     "#    # ###  #X # #",
                     "#    #     #   # #",
                     "#   #  ###  #  # #",
                     "#  #  X#X   # #  #",
                     "#   #  ###   #   #",
                     "#               X#",
                     "##################"}; 
                     
    char s,g[101][101];                        
    int book[101][101],n,m,q,p,guan=6,hang,lie,hengd=7,lied,sgpz;
    int a[101][101],money=5,i,j;
    int jl[8]={0,5,10,15,20,25,30};
    
    void kjd(int a1,int b1)
    {
         book[a1+1][b1-1]=1;
         book[a1+1][b1]=1;
         book[a1+1][b1+1]=1;
         book[a1][b1-1]=1;
         book[a1][b1]=1;
         book[a1][b1+1]=1;
         book[a1-1][b1+1]=1;
         book[a1-1][b1]=1;
         book[a1-1][b1-1]=1;
    }
    
    void inti()
    {
         int i1,j1;
         for(i1=0;i1<=100;i1++)
             for(j1=0;j1<=100;j1++)
                     book[i1][j1]=0;
    }
    
    /*
    void deng1(int u)
    {
         int r;
         Sleep(1000);
         cout<<"你可以挑选"<<u<<"个道具"<<endl;
         cout<<"按1选择 横排神灯:照亮一整行" <<endl;
         cout<<"按2选择 竖排神灯:照亮一整列" <<endl;
         cout<<"选择完毕后请按回车键继续" <<endl;
         cin>>r;
         if(r==1) hengd++;
         if(r==2) lied++;
         system("cls");
    } 
    */
    
    void shop()
    {
        char r; 
        do
        {
            system("cls");
            cout<<"                                   shop"<<endl;
            cout<<"--------------------------------------------------------------------------------"<<endl;
            cout<<" 神器:"<<endl;
            cout<<" 按1购买 横排神灯:照亮一整行 10金币  已拥有"<<hengd<<""<<endl;
            cout<<" 按2购买 竖排神灯:照亮一整列 10金币  已拥有"<<lied<<""<<endl;
            cout<<" 按3购买 圣光普照:照亮全屏1.5秒 30金币 已拥有"<<sgpz<<""<<endl<<endl; 
            cout<<" 目前金币数量:"<<money<<endl; 
            cout<<" 按X键退出商店"<<endl<<endl<<endl; 
            r=getch();
            if(r=='1' && money>=10)
            {
                hengd++;
                money-=10;
                cout<<" 购买成功";
                Sleep(500);
            }
            if(r=='2' && money>=10)
            {
                lied++;
                money-=10;
                cout<<" 购买成功";
                Sleep(500);
            }
            if(r=='3' && money>=30)
            {
                sgpz++;
                money-=30;
                cout<<" 购买成功";
                Sleep(500);
            }
            if(r=='X' || r=='x')
            {
                system("cls");
                return ;
            }
        }while(1);
    }
     
    void SlowDisplay(char *p)
    {
        while(1)
        {
            if(*p!=0)
                printf("%c",*p++);
            else 
                break;
            Sleep(50);
        }
    } 
    
    int main()
    {
        //剧情 
        srand((unsigned)time(NULL));
        char asdf;
        
        SlowDisplay("你是一名普通的小学生。今天,你正走在上学的路上···
    ");
        SlowDisplay("按任意键继续···
    ");
        asdf=getch();
        system("cls");
        SlowDisplay("突然,一道白光袭来");
        system("color f5");
        SlowDisplay(",你昏迷过去
    ");
        SlowDisplay("按任意键继续···
    ");
        asdf=getch();
        system("cls");
        SlowDisplay("当你醒来时,看到了白茫茫的一片
    ");
        SlowDisplay("你心想:这是哪里?我会死吗?");
        Sleep(500);
        SlowDisplay("我不想死啊,我还这么年轻···
    ");
        SlowDisplay("按任意键继续···
    ");
        asdf=getch();
        system("cls");
        SlowDisplay("一道神秘的声音说道:
    ");
        SlowDisplay("这里是一处修炼场所,你是生是死全看个人的造化
    "); 
        Sleep(300);
        SlowDisplay("我看你骨骼惊奇、天赋异禀,有望成为一位强者,所以将你带到这里
    "); 
        Sleep(300);
        SlowDisplay("这里困难重重,你要小心
    ");
        Sleep(300); 
        SlowDisplay("你要收集神器,强化自己
    "); 
        Sleep(300);
        SlowDisplay("加油吧,少年!");
        cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
        cout<<"本游戏由MZA出品!!";
        Sleep(2000); 
        system("cls");
        
        SlowDisplay("第一部分 七重迷魂塔(走迷宫)
    "); 
        Sleep(500); 
        SlowDisplay("七重迷魂塔内道路曲折、迷雾重重,你需要努力找到出路
    ");
        Sleep(500); 
        system("cls"); 
        SlowDisplay("由于你只是凡人,所以只能看见身体周围9格的东西
    "); 
        Sleep(300);
        SlowDisplay("有一些神器可以破开迷雾,它们将帮助你
    ");
        Sleep(300);
        SlowDisplay("你需要走到E所在的位置
    ");
        Sleep(300);
        SlowDisplay("移动按键为a s d w
    ");
        Sleep(300);
        SlowDisplay("接受挑战吧!
    ");
        Sleep(500); 
        system("cls");
        
        while(guan<=6)
        {
            for(i=0;i<=100;i++)
                for(j=0;j<=100;j++)
                    a[i][j]=0;
            cout<<""<<guan<<""; 
            Sleep(1000);
            system("cls");
            inti();
            if(guan==1)
            {
                n=1;m=1;q=8;p=9;hang=9;lie=9;
                for(int i=0;i<=hang;i++)
                    for(int j=0;j<=lie;j++)
                        g[i][j]=a1[i][j];
            }
            if(guan==2)
            {
                n=1;m=1;q=11;p=10;hang=15;lie=15;
                for(int i=0;i<=hang;i++)
                    for(int j=0;j<=lie;j++)
                        g[i][j]=a2[i][j];
            }
            if(guan==3)
            {
                n=1;m=1;q=13;p=13;hang=17;lie=17;
                for(int i=0;i<=hang;i++)
                    for(int j=0;j<=lie;j++)
                        g[i][j]=a3[i][j];
            }
            if(guan==4)
            {
                n=1;m=1;q=1;p=3;hang=17;lie=17;
                for(int i=0;i<=hang;i++)
                    for(int j=0;j<=lie;j++)
                        g[i][j]=a4[i][j];
            }
            if(guan==5)
            {
                n=1;m=1;q=12;p=9;hang=17;lie=17;
                for(int i=0;i<=hang;i++)
                    for(int j=0;j<=lie;j++)
                        g[i][j]=a5[i][j];
            }
            if(guan==6)
            {
                n=3;m=3;q=11;p=8;hang=18;lie=17;
                for(int i=0;i<=hang;i++)
                    for(int j=0;j<=lie;j++)
                        g[i][j]=a6[i][j];
                system("cls");
                
                SlowDisplay("恭喜你一路闯到了第六关
    ");
                SlowDisplay("第六关的难度会增加很多
    ");
                SlowDisplay("而且会有一些开发者派出阻碍你进行游戏的不明生物…………
    ");
                Sleep(300);
                SlowDisplay("将它们称作“X”好了
    ");
                Sleep(500);
                system("color C7"); 
                SlowDisplay("“X”凶残无比,长着尖牙利爪,会将你撕成碎片并且……
    ");
                Sleep(300);
                SlowDisplay("……
    ");
                Sleep(300);
                SlowDisplay("……
    ");
                Sleep(300);
                system("color f5");
                SlowDisplay("逗你玩的
    ");
                Sleep(500);
                SlowDisplay("“X”只会待在原地,并不会移动
    ");
                Sleep(300);
                SlowDisplay("但如果你撞到了“X”身上
    ");
                SlowDisplay("你将会本关回到起点 或 扣除10金币(金币数量无下限)
    ");
                Sleep(300);
                SlowDisplay("小心它们……
    ");
                SlowDisplay("加油吧……
    ");
                Sleep(500);
                system("cls");
                system("color f5");
            }
            kjd(n,m);
            for(i=0;i<=hang;i++)
            {
                for(j=0;j<=lie;j++)
                {
                    if(book[i][j]==1) cout<<g[i][j];
                    else cout<<" ";
                }
                cout<<endl;
            }
            int bn,bm,flag=0;
            while(n!=q || m!=p)
            {
                cout<<"移动按键为a s d w"<<endl;
                cout<<"你只能看见身体周围9格的东西"<<endl;
                cout<<"神器:"<<endl; 
                cout<<"横排神灯:"<<hengd<<"个 按q释放    ";
                cout<<"竖排神灯:"<<lied<<"个 按e释放    ";
                cout<<"圣光普照:"<<sgpz<<"个 按z释放"; 
                s=getch();
                int nm=m,nn=n; 
                if(s=='a' && g[n][m-1]!='#')
                    nm--;
                if(s=='w' && g[n-1][m]!='#')
                    nn--;
                if(s=='s' && g[n+1][m]!='#')
                    nn++; 
                if(s=='d' && g[n][m+1]!='#')
                    nm++;
                if(s=='q' && hengd>0)
                {
                    for(i=0;i<=lie;i++) a[n][i]=1;
                    hengd--;
                }
                if(s=='e' && lied>0)
                {
                    for(i=0;i<=hang;i++) a[i][m]=1;
                    lied--;
                }
                if(s=='z' && sgpz>0)
                {
                    system("cls");
                    for(i=0;i<=hang;i++)
                    {
                        for(j=0;j<=lie;j++)
                            cout<<g[i][j];
                        cout<<endl;
                    }
                    Sleep(1500);
                    sgpz--;
                }
                g[n][m]=' ';
                n=nn,m=nm;
                if(g[n][m]=='X')
                {
                    flag=1;
                    bn=n;
                    bm=m;
                    system("cls");
                    //cout<<bn<<" "<<bm<<endl;
                    cout<<"你撞上了“X”"<<endl;
                    int sj=rand()%2;
                    if(sj)
                    {
                        cout<<"你被扣除10金币"<<endl;
                        money-=10;
                        cout<<"剩余金币数:"<<money<<endl; 
                    }
                    else
                    {
                        cout<<"你被送回本关起点"<<endl;
                        n=3;
                        m=3;
                    }
                    Sleep(2000); 
                }
                g[n][m]='o';
                inti();
                kjd(n,m);
                system("cls");
                if(flag && (n!=bn || m!=bm))
                {
                    g[bn][bm]='X';
                    flag=0;
                }
                for(int i=0;i<=hang;i++)
                {
                    for(int j=0;j<=lie;j++)
                    {
                        if(book[i][j]==1 || a[i][j]==1) cout<<g[i][j];
                        else cout<<" ";
                    }
                    cout<<endl;
                }
            }
            system("cls");
            cout<<"You win!"<<endl<<"你获得了"<<jl[guan]<<"金币的奖励"<<endl;
            money+=jl[guan];
            //if(guan==2) deng1(1);
            cout<<"按N键进入商店,按其它键继续"<<endl;
            asdf=getch();
            if(asdf=='n' || asdf=='N') shop();
            system("cls");
            guan++;
        }
        cout<<"恭喜通关!!!(撒花)(撒花)";
        Sleep(2000);
        return 0;
    }
    游戏
  • 相关阅读:
    bzoj2045: 双亲数&bzoj1101: [POI2007]Zap
    spoj GCDEX
    jQuery Ajax
    jQuery 动画效果
    jQuery 事件处理API
    jQuery 常用getter&setter
    jQuery 文档操作
    jQuery 基础
    Vue2.2.0+新特性整理
    JavaScript中的HTTP
  • 原文地址:https://www.cnblogs.com/llllllpppppp/p/7827311.html
Copyright © 2011-2022 走看看