C++超级迷宫游戏_蒟蒻一枚的博客-程序员秘密

技术标签: 游戏  

游戏效果
用钥匙、护盾等道具帮助你的小人通过大门、墙、怪物、岩浆等困难到达终点。
游戏代码

#include<bits/stdc++.h> 
#include<conio.h>
#include<windows.h>
using namespace std;
void Color(int a)
{
    
    if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
    if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
    if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
    if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
    if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
    if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
    if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
    if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|BACKGROUND_RED);
}
void Setpos(int x,int y){
    COORD pos;pos.X=y*2,pos.Y=x;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
int R[5];
void SlowDisplay(int x,char *p){
    while(1){
    if(*p!=0) printf("%c",*p++);else break;Sleep(x);}}
struct xg{
    int xgx,xgy;bool fx,sw=0; }xg[21];
int ys=0,hd=0,sj=0,sl=0,mg=0,hp=0,hss=0,hsx=0,jt=0,s=0;
char ch[35][35];
char ch1[35][35]={
    "", "      #####     #####  ########"," #&##       ###       ###      ","      #### #    ## ####   #### ","  ### ##   # ####!      ##     ","  ###&   ###   +##  ###### ####"," ######&############!        ##"," #  *#      !  ######### ###-##"," # ### #####             #     "," # ###*#   ############### ### "," # ###&###                 ####"," #      #  # ##-############## "," ######   #####!               "," #+     #  ###### ############ ", " ##&########## ### ### ### ##  "," #                   !      ! #","   ############################","  #       ! #       ! #       #","    #     !   #     !   ####   "," #&########################### "," )                             ",}; 
char ch2[35][35]={
    ""," ##############################"," #*                           #"," ########&###################-#"," #                          # #"," # # ################&#####-# #"," # # #               !   +# # #"," # # # ##&############### # # #"," # # # #                # # # #"," # # # # ###########&## # # # #"," # # # # #)- !        # # # & #"," # # # # ###      !   # # # # #", " # # # ##########&####### # # #"," # # #              !       # #"," # # ##################&##### #"," # #       !               *# #"," # #####&####### ############ #"," #     !       # #   !        #"," # ############# ###########  #"," #              !             #"," ##############################", };
char ch3[31][33]={
    ""," ##############################"," #.          +               .#"," #                      !     #"," #      +     !               #"," #                            #"," #          ! +               #"," #     !               +    ! #"," #                  +         #"," #           +          !     #", " #  +                      !  #"," #      !           +         #"," #+           _____           #"," #           |_ _ _|     +    #"," #     +     |_|||_|          #"," #        +  |MMMMM|         !#"," #           |WWWWW|          #"," #!          |_____|          #"," #                      !     #"," #.        +                 .#"," ##############################", }; 
char ch4[35][35]={
    "","         ###*###       ########","     ###!      # ##### #     *#"," ###&#+####### # #   # # ######"," #          !# # #-# # # #    #"," ###&#######     # #   # # ## #","           ####### ##### # ## #","  ####&###        !  !  !# ## #","  #       ################ ## #","    ###             !!     ##  "," #### ##&##################### "," #                !         !# "," #-############&######### #&## "," #-#ooooooooooo   o     # #*## "," o ooo   o   o  o o ooo # #### "," o   o o   o   oo o   o #      "," ooo o ooooooo oo ooo o #######"," ooo o o   o   oo     o       #"," ooo   o o o*oooooooooooooooo-#"," ooooooo o oo   o   o   o   o #"," )       o    o   o   o   o   #",};
char ch5[35][35]={
    "","  oooo     oooooooooooooooooooo","       ooo    o   oo+oo   o   o"," ooooooo*oooo !   o   ! o   o o"," o          o  o    o   o   o o"," oooooooooo ooooooooooooooooo o"," o     !       !              o"," oooooooo ooooooooooooooooooooo"," oooooooo ooooooooooooooooooooo", " o              !             o"," o^^^^^^^^^^^^^^^^^^^^^^^^^^^^o"," o    !   !   !   !   !       o"," o^^^^^^^^^^^^^^^^^^^^^^^^^^^^o"," o^*^! !^! !^!  ^^! +^! !^! *^o"," o^^^^^^^^^^^^^^^^^^^^^^^^^^^^o"," o   !   !   !   !   !        o"," #^^^^^^^^^^^^^^^^^^^^^^^^^^^^#"," #                 !          #"," ####oooooooooo--oooooooooooo##"," ########oooooo--ooooooo#######"," ###########ooo))oooo##########", };
char ch6[35][35]={
    ""," oooooooooooooo .oooooooooooooo"," o+oooooooooooo  oooooooooooo+o"," ooooooooooooo#  #ooooooooooooo"," oooooooooooo#^^^^#oooooooooooo"," oooo*oooooo#^    ^#oooooo*oooo"," oooooooooo# ^    ^ #oooooooooo"," ooooooooo#  ^    ^  #ooooooooo"," oooooooo#^^^^^^^^^^^^#oooooooo"," ooooooo#^   ^#--#^   ^#ooooooo"," .       ^   ^-NO-^   ^         ","         ^   ^-IP-^   ^       ."," ooooooo#^   ^#--#^   ^#ooooooo"," oooooooo#^^^^^^^^^^^^#oooooooo"," ooooooooo#  ^    ^  #ooooooooo"," oooooooooo# ^    ^ #oooooooooo"," oooo*oooooo#^    ^#oooooo*oooo"," oooooooooooo#^^^^#oooooooooooo"," ooooooooooooo#  #ooooooooooooo"," o+oooooooooooo  oooooooooooo+o"," oooooooooooooo. oooooooooooooo",};
void map1(int x,int y,int k){
    
    for(int i=1;i<=20;++i)
    for(int j=1;j<=30;++j){
    
        bool f=1;
        for (int l=1;l<=k;++l)
        if (xg[l].xgx==i&&xg[l].xgy==j&&xg[l].sw==0) {
    Setpos(i,j);Color(4),cout<<"▼";f=0;break;}
        if (f==1)
        {
    Setpos(i,j);
        if (i==x&&j==y) Color(1),cout<<"●";
        else if (ch[i][j]=='#'||ch[i][j]=='&') Color(7),cout<<"■";
        else if (ch[i][j]==')') Color(5),cout<<"☆";
        else if (ch[i][j]=='*') Color(5),cout<<"♂";
        else if (ch[i][j]=='-') Color(3),cout<<"▋"; 
        else if (ch[i][j]=='+') Color(2),cout<<"◆";
        else if (ch[i][j]=='.') Color(1),cout<<"◆";
        else if (ch[i][j]=='o') Color(8),cout<<"~ "; 
        else if (ch[i][j]=='_') Color(3),cout<<"▁";
        else if (ch[i][j]=='^') Color(3),cout<<"▲";
        else if (ch[i][j]=='|') Color(3),cout<<"|";
        else if (ch[i][j]=='M') Color(3),cout<<'M'<<'M';
        else if (ch[i][j]=='W') Color(3),cout<<'W'<<'W';
        else if (ch[i][j]=='N') Color(2),cout<<"NO";
        else if (ch[i][j]=='I') Color(2),cout<<"..";
        else if (ch[i][j]=='O') Color(2),cout<<"I!";
        else if (ch[i][j]=='P') Color(2),cout<<".P";
        else Color(0),cout<<"  ";
        }
    }
    Setpos(21,3);Color(5),cout<<"["<<ys<<" ♂]      ",Color(2),cout<<"["<<hd<<" ◆]";
}
int yx(int a)
{
    
    int k=0,T=0,x,y,boss=0,win=0;ys=0,hd=0,sj=0;
    system("cls");
if(a==1) {
    for(int i=0;i<35;i++)for(int j=0;j<35;j++) ch[i][j]=ch1[i][j];x=1,y=1;}
if(a==2) {
    for(int i=0;i<35;i++)for(int j=0;j<35;j++) ch[i][j]=ch2[i][j];x=2,y=29;}
if(a==3) {
    for(int i=0;i<35;i++)for(int j=0;j<35;j++) ch[i][j]=ch3[i][j];x=10,y=15;boss=1;}
if(a==4) {
    for(int i=0;i<35;i++)for(int j=0;j<35;j++) ch[i][j]=ch4[i][j];x=1,y=1;}
if(a==5) {
    for(int i=0;i<35;i++)for(int j=0;j<35;j++) ch[i][j]=ch5[i][j];x=1,y=1;}
if(a==6) {
    for(int i=0;i<35;i++)for(int j=0;j<35;j++) ch[i][j]=ch6[i][j];x=1,y=15;boss=2;}
    if(boss==1){
    for (int i=1;i<=200;++i) {
    int xx=rand()%21,yy=rand()%31;if ((xx!=x||yy!=y)&&ch[xx][yy]!='_'&&ch[xx][yy]!='W'&&ch[xx][yy]!='|'&&ch[xx][yy]!='M'&&ch[xx][yy]!='.') ch[xx][yy]='o';}map1(x,y,k);} 
    for(int i=1;i<35;++i)for(int j=1;j<35;++j) if (ch[i][j]=='!')k++,xg[k].xgx=i,xg[k].xgy=j,ch[i][j]=' ';
    map1(x,y,k);

while (1)
{
    
    T++;
        Setpos(x,y),cout<<"  ";
        if(GetAsyncKeyState(VK_UP)&0x8000&&x!=1&&ch[x-1][y]!='#') x--;
        else if(GetAsyncKeyState(VK_DOWN)&0x8000&&x!=20&&ch[x+1][y]!='#') x++;
        else if(GetAsyncKeyState(VK_LEFT)&0x8000&&y!=1&&ch[x][y-1]!='#') y--;
        else if(GetAsyncKeyState(VK_RIGHT)&0x8000&&y!=30&&ch[x][y+1]!='#') y++;
        Setpos(x,y),Color(1),cout<<"●";

    if(boss!=0&&T%20==5){
    
        for (int i=1;i<=20;++i)for (int j=1;j<=30;++j)if (ch[i][j]=='o') ch[i][j]=' ';
        for (int i=1;i<=200*boss;++i) {
    int xx=rand()%21,yy=rand()%31;if ((xx!=x||yy!=y)&&ch[xx][yy]==' ') ch[xx][yy]='o';}
        map1(x,y,k);} 

    if(T%20==0) map1(x,y,k);if(T%20==10){
    for(int i=1;i<35;++i)for(int j=1;j<35;++j) if(ch[i][j]=='^')Setpos(i,j),cout<<"  ";}
    if(T%4==0&&k!=0)
        for (int i=1;i<=k;i++){
    
            if (xg[i].fx==0&&(ch[xg[i].xgx][xg[i].xgy+1]==' '||(ch[xg[i].xgx][xg[i].xgy-1]=='^'&&T%20>=10))&&xg[i].xgy!=30)     Setpos(xg[i].xgx,xg[i].xgy),cout<<"  ",xg[i].xgy++,Setpos(xg[i].xgx,xg[i].xgy),Color(4),cout<<"▼";
            else if (xg[i].fx==1&&(ch[xg[i].xgx][xg[i].xgy-1]==' '||(ch[xg[i].xgx][xg[i].xgy-1]=='^'&&T%20>=10))&&xg[i].xgy!=1) Setpos(xg[i].xgx,xg[i].xgy),cout<<"  ",xg[i].xgy--,Setpos(xg[i].xgx,xg[i].xgy),Color(4),cout<<"▼";
            else if (xg[i].fx==1) xg[i].fx=0;else xg[i].fx=1;}
    for (int i=1;i<=k;i++){
    
        if (xg[i].xgx==x&&xg[i].xgy==y&&xg[i].sw==0&&hd==0) {
    system("cls");cout<<"怪物啊!!!";Sleep(2000);system("cls");return 0;}
        else if (xg[i].xgx==x&&xg[i].xgy==y&&hd>0&&xg[i].sw==0) {
    system("cls");cout<<"护盾保护了你!";Sleep(1000);system("cls");map1(x,y,k);hd--;xg[i].sw=1;}}

    if (ch[x][y]==')') {
    system("cls");cout<<"You Win!";Sleep(2000);system("cls");win=1;}
    if (ch[x][y]=='*') {
    system("cls");cout<<"你找到了钥匙!";ys++;Sleep(1000);system("cls");map1(x,y,k);ch[x][y]=' ';} 
    if (ch[x][y]=='.') {
    system("cls");cout<<"你破坏了水晶!";sj++;Sleep(1000);system("cls");map1(x,y,k);ch[x][y]=' ';}
    if (ch[x][y]=='-'&&ys>0) {
    system("cls");cout<<"门开了!";ys--;Sleep(1000);system("cls");map1(x,y,k);ch[x][y]=' ';}else if (ch[x][y]=='-') {
    system("cls");cout<<"你没有钥匙!";--x;Sleep(3000);system("cls");map1(x,y,k);}
    if (ch[x][y]=='+') {
    system("cls");cout<<"你找到了护盾!";hd++;Sleep(1000);system("cls");map1(x,y,k);ch[x][y]=' ';}
    if (ch[x][y]=='o'&&hd==0) {
    system("cls");cout<<"烫死啦!!!";Sleep(2000);return 0;} 
    else if (hd>0&&ch[x][y]=='o') {
    system("cls");cout<<"护盾保护了你!";ch[x][y]=' ';hd--;Sleep(1000);system("cls");map1(x,y,k);} 
    if (ch[x][y]=='^'&&T%20<10&&hd==0) {
    system("cls");cout<<"被刺穿啦!!!";Sleep(2000);return 0;} 
    else if (hd>0&&ch[x][y]=='^'&&T%20<10) {
    system("cls");cout<<"护盾保护了你!";ch[x][y]=' ';hd--;Sleep(1000);system("cls");map1(x,y,k);} 

    if ((a==3||a==6)&&sj==4)   {
    system("cls");cout<<"You Win!";Sleep(2000);system("cls");win=1;}

    for (int i=1;i<=k;i++)
        if (xg[i].xgx==x&&xg[i].xgy==y&&xg[i].sw==0&&hd==0) {
    system("cls");cout<<"怪物啊!!!";Sleep(1000);system("cls");return 0;}
        else if (xg[i].xgx==x&&xg[i].xgy==y&&hd>0&&xg[i].sw==0) {
    system("cls");cout<<"护盾保护了你!";Sleep(1000);system("cls");map1(x,y,k);map1(x,y,k);hd--;xg[i].sw=1;}
    if(win==1){
    if(a==1)sl=1;if(a==2)mg=1;if(a==3)hp=1;if(a==4)hss=1;if(a==5)hsx=1;return 0;}
Sleep(100);
}}
void ml(){
    while(1){
    
    system("cls");Color(0); 
    cout<<"1、迷雾森林   ";cout<<endl;
    if (sl==0) cout<<"2、 ? ? ? ?   ";else cout<<"2、巨石迷宫(图中如果走可穿透墙,能避开所有的怪)   "; cout<<endl;
    if (mg==0) cout<<"3、 ? ? ? ?   ";else cout<<"3、熔岩喷泉(BOSS,图中随机出现熔岩)   ";cout<<endl;
    if (hp==0) cout<<"4、 ? ? ? ?   ";else cout<<"4、火山口(上)   ";cout<<endl;
    if (hss==0) cout<<"5、 ? ? ? ?   ";else cout<<"5、火山口(下)   ";cout<<endl;
    if (hsx==0) cout<<"6、 ? ? ? ?   ";else cout<<"6、火山祭坛(BOSS)";cout<<endl;
    cout<<"选择关卡(序号)"<<endl;cout<<"退出输入0"<<endl;
    int a;cin>>a;
    if (a==1) {
    yx(1);}if (a==2&&sl==1){
    yx(2);}if (a==3&&mg==1) {
    yx(3);}if (a==4&&hp==1) {
    yx(4);}if (a==5&&hss==1){
    yx(5);}if (a==6&&hsx==1){
    yx(6);}if (a==0) return;
}}
void gz() {
    
    system("cls");
    cout<<"由上下左右键控制"<<endl;
    cout<<"●是你"<<endl;
    cout<<"■是墙"<<endl;
    cout<<"☆是终点"<<endl;
    cout<<"▼是小怪(只会左右移动)"<<endl;
    cout<<"▋是门"<<endl;
    cout<<"♂是钥匙"<<endl;
    cout<<"◆是护盾(不可杀怪)"<<endl;
    cout<<"■是可穿透墙(每一关几乎都有)"<<endl; 
    cout<<"◆是水晶(BOSS关破坏所有水晶通关)"<<endl;
    cout<<"~ 是熔岩"<<endl; 
    cout<<"▁是尖刺(未升起)"<<endl;
    cout<<"▲是尖刺(升起)"<<endl;
    cout<<"输入1开始!"<<endl;
    int a;
    cin>>a;
    if (a==1) ml();
    else gz(); 
}
int main(){
     
    CONSOLE_CURSOR_INFO cursor_info={
    1,0};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);srand((unsigned)time(NULL));
    cout<<"欢迎来到超级迷宫!"<<endl;cout<<"1、开始!"<<endl;cout<<"2、规则..."<<endl;
    int a;cin>>a;if (a==1){
    system("cls");ml();}else if (a==2){
    gz();}
    return 0;
}
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/yueyuedog/article/details/112390459

智能推荐

百度地图离线开发demo(初始化地图)_oliver666666的博客-程序员秘密_百度地图初始化

使用百度地图api,只要瓦片对应上,api对上了,地图的使用还是较为简单的,demo官网上的也可参考,只需将BMapGL后边的gl去掉即可&lt;!--地图初始化 --&gt;&lt;template&gt; &lt;div id="allmap" style="width: 100%;height: 100%;" /&gt;&lt;/template&gt;&lt;script&gt;export default { components: {}..

opencv和HALCON坐标系的不同_冯相文要加油呀的博客-程序员秘密

opencv的坐标原点在左上角,往右为X轴正方向,往下为Y轴正方向(用Image Watch可以很容易看出来)HALCON的坐标原点在左上角,往右为Y轴正方向,往下为X轴正方向(HALCON窗口左下角可以出来)

Python自学之路:第二课_MIYAGI_Desu的博客-程序员秘密

第2课0. 什么是BIF?BIF 就是 Built-in Functions,内置函数。为了方便程序员快速编写脚本程序(脚本就是要编程速度快快快!!!),Python 提供了非常丰富的内置函数,我们只需要直接调用即可,例如 print() 的功能是“打印到屏幕”,input() 的作用是接收用户输入(注:Python3 用 input() 取代了 Python2 的 raw_input(),用法如有不懂请看视频讲解)。太多BIF学不过来怎么办?看不懂英文说明怎么办?Python3的资料太少怎么办?没事

MemCache详解_Quiet_boy的博客-程序员秘密

MemCache是什么MemCache是一个自由、源码开放、高性能、分布式的分布式内存对象缓存系统,用于动态Web应用以减轻数据库的负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高了网站访问的速度。MemCaChe是一个存储键值对的HashMap,在内存中对任意的数据(比如字符串、对象等)所使用的key-value存储,数据可以来自数据库调用、API调用,或者页面渲染的结果。

apiDoc 详解 api接口文档生成_Dom_留声机的博客-程序员秘密_apidoc

PHP使用apiDoc api接口文档安装apidocapidoc 命令参数列表配置(apidoc.json)apidoc.json配置项apidoc注释参数@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@apiHeaderExam...

android api 和版本对应表汇总_AaVictory.的博客-程序员秘密_android api版本对应

Android历代版本的命名:我们都是知道,安卓系统的历来的名称都是很有意思的,下面无限互联Android培训的老师归纳了一下:Android在正式发行之前,最开始拥有两个内部测试版本,并且以著名的机器人名称来对其进行命名,它们分别是:阿童木(AndroidBeta),发条机器人(Android1.0)。后来由于涉及到版权问题,谷歌将其命名规则变更为用甜点作为它们系统版本的代号的命名方法。甜点命名法开始于Android1.5发布的时候。作为每个版本代表的甜点的尺寸越变越大,然后按照26个字母数序:

随便推点

Tomcat内存优化第二篇 - 个别优化参数详解_路克森的博客-程序员秘密_tomcat内存优化参数

博主个人主页前言今天我们接着来说tomcat这部分的小知识哦 上一篇我们提到了如何设置我们tomcat的内存大小 这一篇主要来说一下tomcat的优化思路 以及如何能够让tomcat抗住并发呢?开发众所周知 我们一个完整的系统肯定不是一个单体应用就能扛得住的 在大并发的压迫下 如果我们的程序还是个单机系统 那肯定会会快就挂了 所以我们就不得不做出改变 那么常见的tomcat优化或者说高可用...

科大讯飞指定录音文件转文字(异步)_XStorms的博客-程序员秘密_科大讯飞录音文件转文字

/** * 指定录音文件转文字(异步) * @param bo * @return */ @Override public JSONObject recognizeAudio(QueryRecognizeBo bo){ Map&lt;String,Object&gt; recordMap = extLxccCdrMapper.queryRelativePath(bo.getCallId()); String fileP.

优雅地处理运行时权限请求_rain9155的博客-程序员秘密

前言从android 6.0(API 级别 23)开始,android引入了运行时权限,用户开始在应用运行时向其授予权限,而不是在应用安装时向其授予权限,如果应用的某项功能需要使用到受运行时权限保护的资源(例如相机、位置、麦克风等),但在运行该功能前没有动态地申请相应的权限,那么在调用该功能时就会抛出SecurityException异常, android 6.0已经推出了很多年了,相信大家对于运行时权限的申请过程已经非常的熟悉,但是android的运行时权限的申请过程一直都是非常的繁琐的,主要有两步:

视频播放的心得体会(一)_JackLee18的博客-程序员秘密

  最近在做短视频播放的应用,为了实现比较好的交互体验,这边用到了缓存,预缓存处理。我这边用到的播放器是SJBaseVideoPlayer 这个库。首先要向这个开源库的作者表示感谢,感谢他贡献自己劳动成果。  在实际应用中,我主要对播放器划分了三个层,交互控制层,播放层,缓存处理层。交互控制层  交互控制层,主要就是根据产品的需求做出对应的交互效果,UI效果。这边会因为具体的业务需求而经常发...

运维思索:自动化运维体系如何入手_木讷大叔爱运维的博客-程序员秘密_自动化运维体系

需求运维是事件驱动,还是自驱动可能是我们在运维工作中不太关注的问题。事件驱动让运维止步于故障,而自驱动让运维不止于建设。持续性的运维建设就需要一套自动化的运维体系,那么我们应该从何入手?其实前期《运维思考》一系列文章已经给我们答案了,就是从运维框架入手分层建设、打好基础,记住“万丈高楼平地起,勿在浮沙筑高台”。运维框架通常讲到运维建设,我们脑海中首先浮现的是“一团麻”,因为这不是一个人、一个岗位的工作,而是一整个团队的工作;所以我们将“这团麻”进行由底层向上可划分为:IT基础设施层IT基础

推荐文章

热门文章

相关标签