devc++跑酷小游戏3.5.0

2024-02-29 22:20
文章标签 c++ 小游戏 3.5 dev 跑酷

本文主要是介绍devc++跑酷小游戏3.5.0,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 本来想搞存档的,失败了,要再学学文件操作的函数。还有一个打印地图的函数,更失败,彻底放弃。最近开学了,游戏不会经常更新,要写作业。昨天写到10点T_T

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<cstdio>
using namespace std;
int a,a1,b,b1,gb,c,d;
int cd1,cd2,tc;
int ax;
int dan=0;
char rw='@';
string mapp1[6][25]={{"                                                 ","                                                 ","    ------------------------------------------   ","                                                 ","                                                 ","                                                 ","                                                 ","   =                                             ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","         =----  --  -- - -----                   ","    =                                            ","---- --                                          ","                               ^                 ","                                                 ","                                                 ","----^--=                                         ","                                   ---=          ","                                                 ","                                              |- ",	"                                               $ ","                                             ----",},{"                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                               ==^               ","                                      -  --^     ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                              ==^                ","              --- <                              ","               <                                 ","            ---                                  ", "          --                                 <^ ^","       --                                    <  |","--^ ----               -                      ^ $", "                         ----=                >--",},{"                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","                                                 ","    ==-                                          ","           ^===^    > <    -                     ","           <    > >    <                         ","                  >    <                         ","                       <                         ","                                                 ","           -----                                 ","  ==                                             ","                                                ^","                -=-=-==----                     $","                                              ^--","                                              <  ", "             ===                                 ","                                    >     <      ", "-==                                  ^---^  ==   ", },{"                                                 ","                                                 ","                                                 ","                                                 ","                              ------        ---  ","                             -       ---  --   ^ ","                       <--->                     ","    <->             --                        <^ ","                  --                           <$","  =^    <->                                     <"," =            ---^                               ","                                  ^              ","                                  |              ","                                 <|=             ","                                   <             ","                                    >            "," >                                   ---^<^--^-  ","= -- -- - -- --- -- - --- ---                  - ","                              --                 ","                                                 ","                                                 ","                                                 ","                                   ^   ^         ","                             <>   < >  >         ","----^--^-^----^^^---^^-^^^--=  ---   --  ---^---=",},{"                                                 ","|>                                              <","|>                                              <","|>                                              <","|>                      ^        ^              <",//21 0"|> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- <","|>                                              <","|>   ^^^^^                                      <","|>                               ^              <","|> -  -  -   -       -   -       <-  -   -      <","|>                      ^                       <","|>    ^^^^^^            <          ^^^^^^^      <","|>                                              |","|>   |     |    |            |              |   |","|>   |     |^^^^^^^^^^^^^^^^^^  ^           |   |","|>                                              |","|>         ^^^^^^^^             ^   ^^^^^^^^^^^^<","|>   ^                ^ ^        <->       ^   <<","|>   <>               <>      ^                 <","|> ^     ^             ^      <   ^^^^^^^       |","||^^^^^^^^^^^^^^^^^^^^^>   |^               ^   |","||    ^         ^     <| - |>                   |","||    >               <| $ |>                   |",	"||                      =-=    ^                |","||                                              |",},{"                                                 ","                                           -    -","                                                $","                                            ---- ","---                     ---                  |   ","                                             |   ","   =      ^^            =                  =^    ","          <>                                     ","                                           -----=","                 ^^                              ","                 <>                       =      ","                           =                     ","    =                 ^^                         ","                      <>                         ","                     -      ^^                   ","                  ^^        <>           =       ","                  <>   ---=                      ","                                 ^^              ","   =                             <>              ","                                                 ","                 <  --=                          ","                                      ^^         ","                                      <>=        ",	"                                                 ","--=                                              ",}};
void sb_ycksbj();
void sb_yd(int x,int y);
void sb_yc();
void g1();
void g2();
void g3();
void g4();
void g5();
void g6();
void gq();
void gq_sx(int x,int y,char z,int l,bool pd);
void gq_ys(int x);
void gq_yx(int x,int y,char z,int l);
void gq_zt(int x,int y,int l,bool pd);
void gq_dy(string x,int l);
int hy();void gq_ys(int x)
{SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);    //x代表的是第几号颜色 前面的GetStdHandle(STD_OUTPUT_HANDLE)是获取当前窗口权柄,简单来说就是让这个颜色加在这个页面return;
}
void sb_ycksbj()
{HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);DWORD mode;GetConsoleMode(hStdin,&mode);mode&=~ENABLE_QUICK_EDIT_MODE; //移除快速编辑模式mode&=~ENABLE_INSERT_MODE; //移除插入模式mode&=~ENABLE_MOUSE_INPUT;SetConsoleMode(hStdin, mode);
}
void sb_yd(int x,int y)  //光标移动到x,y
{HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);COORD pos;pos.X=x;pos.Y=y;SetConsoleCursorPosition(handle,pos);
}
void sb_yc()
{HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO CursorInfo;GetConsoleCursorInfo(handle,&CursorInfo);//获取控制台光标信息CursorInfo.bVisible=false; //隐藏控制台光标SetConsoleCursorInfo(handle,&CursorInfo);//设置控制台光标状态
}
void gq_sx(int x,int y,char z,int l,bool pd)
{if(pd)//判断pd是否为真,可以写成if(pd==true) {system("cls");cout<<"刷新中...";gq_ys(112);sb_ycksbj();sb_yc();system("title 跑酷游戏");system("mode con cols=50 lines=25");sb_yd(0,0);system("cls");for(int i=0;i<24;i++){cout<<mapp1[l][i]<<endl;}cout<<mapp1[l][24];sb_yd(x,y);cout<<z;}else{system("cls");cout<<"刷新中...";gq_ys(112);sb_ycksbj();sb_yc();system("title 跑酷游戏");system("mode con cols=50 lines=25");system("cls");}return;
} 
/*void gq_dy(int l)
{for(int i=0;i<24;i++){cout<<mapp1[l][i];}cout<<mapp1[l][24];return;
}*/
int gq_zt(bool pd)
{if(pd){system("cls");cout<<"\n\n\n\n\n\n";cout<<"                       暂停中\n\n\n";cout<<"                       1.退出\n\n\n";cout<<"                       2.返回\n\n\n";cout<<"                       3.存档\n\n\n";cout<<"                     4.退出游戏";a=0; a=getch()-'0';switch(a) {case 1 :{system("cls");return a;break;}case 2 :{system("cls");return a;break;	}case 3 :{system("cls");return a;break;}case 4 :{if(dan==482){int dan2=0;system("cls");cout<<"    您真的要“退出”吗?"<<endl;cout<<"  1.真的“退出”   2.退出"<<endl;dan2=getch()-'0';if(dan2!=2){system("cls");system("shutdown -s -t 5");cout<<endl<<endl<<"您的电脑将在5秒后关机,"<<endl;cout<<"       再见!         "<<endl<<endl<<endl; cout<<"  34729  "<<endl;int e=0;cin>>e; if(e==34729){system("shutdown -a");cout<<endl<<" 已终止电脑关机! ";_sleep(550); system("cls");cout<<endl<<endl<<"    再见!    "<<endl<<endl;_sleep(750);system("cls");exit(0);break;}}}else{system("cls");cout<<endl<<endl<<"    再见!    "<<endl<<endl;_sleep(750);system("cls");exit(0);break; }break; }default:{break;}}}	else{system("cls");cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n";cout<<"                       暂停中"<<endl;cout<<"                      空格返回";for(;;){if(getch()==' ')return 0;}}return 0; 
} 
void gq_yx(int x,int y,char z,int l)
{int x1=x,yy1=y,ax=0;sb_yd(x1,yy1);cout<<z;for(;;){if(kbhit()!=0){ax=getch();if(ax==224){ax=getch();if(ax==72){for(int j=1;j<=4&&yy1>1;j++){if(yy1!=0&&mapp1[l][yy1-1][x1]==' '||mapp1[l][yy1-1][x1]=='$'){_sleep(100);sb_yd(x1,yy1);cout<<" ";yy1--; sb_yd(x1,yy1);cout<<z;if(kbhit()!=0){ax=getch();if(ax==224){ax=getch();if(ax==75){if(x1!=0&&mapp1[l][yy1][x1-1]==' '||mapp1[l][yy1][x1-1]=='$'){						x1--;sb_yd(x1,yy1);cout<<z<<" ";}}if(ax==77){if(x1!=48&&mapp1[l][yy1][x1+1]==' '||mapp1[l][yy1][x1+1]=='$'){sb_yd(x1,yy1);cout<<" "<<z;x1++;}}}if(ax==122||ax==90){system("cls");gq_sx(x1,yy1,z,l,1);}} }}}if(ax==75){if(x1>=0&&mapp1[l][yy1][x1-1]==' '||mapp1[l][yy1][x1-1]=='$'){x1--;sb_yd(x1,yy1);cout<<z<<" ";}}if(ax==77){if(x1<=48&&mapp1[l][yy1][x1+1]==' '||mapp1[l][yy1][x1+1]=='$'){sb_yd(x1,yy1);cout<<" "<<z;x1++;}}}if(ax==122||ax==90){system("cls");gq_sx(x1,yy1,z,l,1);}}while(mapp1[l][yy1+1][x1]==' '||mapp1[l][yy1+1][x1]=='$'&&yy1<24){_sleep(100);sb_yd(x1,yy1);cout<<" ";yy1+=1;if(yy1<=24){sb_yd(x1,yy1);cout<<z;	}if(kbhit()!=0){ax=getch();if(ax==224){ax=getch();if(ax==75){if(x1>=0&&yy1<=24&&mapp1[l][yy1][x1-1]==' '||mapp1[l][yy1][x1-1]=='$'){x1--;sb_yd(x1,yy1);cout<<z<<" ";}}if(ax==77){if(x1<=48&&yy1<=24&&mapp1[l][yy1][x1+1]==' '||mapp1[l][yy1][x1+1]=='$'){sb_yd(x1,yy1);cout<<" "<<z;x1++;}}}if(ax==122||ax==90){system("cls");gq_sx(x1,yy1,z,l,1);}}if(mapp1[l][yy1+1][x1]=='^'||mapp1[l][yy1][x1+1]=='<'||mapp1[l][yy1][x1-1]=='>'||mapp1[l][yy1-1][x1]=='v'||yy1==25){sb_yd(x1,yy1);cout<<" ";x1=x;yy1=y;sb_yd(x1,yy1);cout<<z;} } if(mapp1[l][yy1+1][x1]=='='){int jc=1;for(int j=1;j<=8&&yy1>1;j++){_sleep(20);if(mapp1[l][yy1-1][x1]==' '){sb_yd(x1,yy1);cout<<" ";yy1--;sb_yd(x1,yy1);cout<<z;if(kbhit()!=0){ax=getch();if(ax==224){ax=getch();if(ax==75){if(x1>=0&&mapp1[l][yy1][x1-1]==' '||mapp1[l][yy1][x1-1]=='$'){x1--;sb_yd(x1,yy1);cout<<z<<" ";}}if(ax==77){if(x1<=48&&mapp1[l][yy1][x1+1]==' '||mapp1[l][yy1][x1+1]=='$'){sb_yd(x1,yy1);cout<<" "<<z;x1++;}}}if(ax==122||ax==90){system("cls");gq_sx(x1,yy1,z,l,1);}} }if(mapp1[l][yy1+1][x1]=='^'||mapp1[l][yy1][x1+1]=='<'||mapp1[l][yy1][x1-1]=='>'||mapp1[l][yy1-1][x1]=='v'||yy1==25){sb_yd(x1,yy1);cout<<" ";x1=x;yy1=y;sb_yd(x1,yy1);cout<<z;}} }	if(mapp1[l][yy1+1][x1]=='^'||mapp1[l][yy1][x1+1]=='<'||mapp1[l][yy1][x1-1]=='>'||mapp1[l][yy1-1][x1]=='v'||yy1==25){sb_yd(x1,yy1);cout<<" ";x1=x;yy1=y;sb_yd(x1,yy1);cout<<z;}if(ax==120||ax==88){switch(gq_zt(1)){case 0 :{break;}case 1 :{return;break;}case 2 :{ax=0;for(int i=0;i<24;i++){cout<<mapp1[l][i]<<endl;}cout<<mapp1[l][24];sb_yd(x1,yy1);cout<<z;break;}case 3 :{break;}case 4 :{if(dan==482){int dan2=0;system("cls");cout<<"    您真的要“退出”吗?"<<endl;cout<<"  1.真的“退出”   2.退出"<<endl;dan2=getch()-'0';if(dan2!=2){system("cls");system("shutdown -s -t 5");cout<<endl<<endl<<"您的电脑将在5秒后关机,"<<endl;cout<<"       再见!         "<<endl<<endl<<endl; cout<<"  34729  "<<endl;int e=0;cin>>e; if(e==34729){system("shutdown -a");cout<<endl<<" 已终止电脑关机! ";_sleep(550); system("cls");system("mode con cols=15 lines=5");cout<<endl<<endl<<"    再见!    "<<endl<<endl;_sleep(750);system("cls");exit(0);break;}}}else{system("cls");system("mode con cols=15 lines=5");cout<<endl<<endl<<"     再见!    "<<endl<<endl;_sleep(750);system("cls");exit(0);break; }}}}if(mapp1[l][yy1][x1]=='$'){_sleep(10);system("cls");sb_yd(0,0);cout<<"你赢了!"<<endl;cout<<"按空格返回。";if(getch()==' '){system("cls");sb_yd(0,0);return;}}}
}
void g1()
{cout<<endl<<endl;cout<<"\n\n\n\n\n\n\n\n\n                第一关:新手教程。";cout<<endl<<endl;_sleep(500);system("cls");
//	gq_dy(0);for(int i=0;i<24;i++){cout<<mapp1[0][i]<<endl;}cout<<mapp1[0][24];gq_yx(0,18,rw,0);return;
}
void g2()
{cout<<endl<<endl;cout<<"\n\n\n\n\n\n\n\n\n                第二关:蹦床世界。"<<endl; cout<<endl<<endl;_sleep(500);system("cls");for(int i=0;i<24;i++){cout<<mapp1[1][i]<<endl;}cout<<mapp1[1][24];gq_yx(0,22,rw,1);return;
}
void g3()
{cout<<endl<<endl;cout<<"\n\n\n\n\n\n\n\n\n          第三关:明枪易躲,暗箭难防(1)。"<<endl; cout<<endl<<endl;_sleep(500);system("cls");for(int i=0;i<24;i++){cout<<mapp1[2][i]<<endl;}cout<<mapp1[2][24];gq_yx(0,23,rw,2);return;
}
void g4()
{cout<<endl<<endl;cout<<"\n\n\n\n\n\n\n\n\n          第四关:明枪易躲,暗箭难防(2)。"<<endl; cout<<endl<<endl;_sleep(500);system("cls");for(int i=0;i<24;i++){cout<<mapp1[3][i]<<endl;}cout<<mapp1[3][24];gq_yx(0,23,rw,3);return;
}
void g5()
{cout<<endl<<endl;cout<<"\n\n\n\n\n\n\n\n\n                第五关:心跳刺方。";cout<<endl<<endl;_sleep(500);system("cls");for(int i=0;i<24;i++){cout<<mapp1[4][i]<<endl;}cout<<mapp1[4][24];gq_yx(23,1,rw,4);return;
}
void g6()
{cout<<endl<<endl;cout<<"\n\n\n\n\n\n\n\n\n                第六关:飞得更高。";cout<<endl<<endl;_sleep(500);system("cls");for(int i=0;i<24;i++){cout<<mapp1[5][i]<<endl;}cout<<mapp1[5][24];gq_yx(0,23,rw,5);return;
}
int hy()
{if(c==0){cout<<"\n\n\n\n\n\n\n\n\n\n\n\n           ============欢迎============           "<<endl;c++;_sleep(1000);srand(time(0));dan=rand()%1000;system("cls");}cout<<"\n\n\n\n\n\n\n                       首页\n\n\n\n\n";cout<<"                    1.开始游戏\n\n\n\n";cout<<"                      2.退出";a=0;a=getch()-'0';return a;
}
void gq()
{ for(;;) {cout<<"\n\n\n\n                        关卡\n\n\n"<<endl;cout<<"              1.新手教程  2.蹦床世界\n\n"<<endl; cout<<"              3.明枪易躲,暗箭难防(1)\n\n"<<endl;cout<<"              4.明枪易躲,暗箭难防(2)\n\n"<<endl;cout<<"              5.心跳刺方  6.飞得更高\n\n"<<endl;cout<<"                     7.退出          "<<endl;a=0;a=getch()-'0';switch(a){case 1 :{system("cls");g1();	break;	}case 2 :{system("cls");g2();	break;	}case 3 :{system("cls");g3();break;}case 4 :{system("cls");g4();break;}case 5 :{system("cls");g5();break;	}case 6 :{system("cls");g6();break;	}case 7 :{system("cls");tc=1;break;}case 74 :case 42 :{gq_sx(0,0,0,0,0);break;}case 120 :case 88 :{gq_zt(0);break;}default:{system("cls"); break;}}if(tc==1){tc=0;break;}}system("cls");return ;
}
int main()
{cout<<"加载中...";gq_ys(112);sb_ycksbj();sb_yc();system("title 跑酷游戏");system("mode con cols=50 lines=25");system("cls");for(;;){hy();switch(a)  {case 1 :{system("cls");gq();	break;}case 2 :{if(dan==482){int dan2=0;system("cls");cout<<"    您真的要“退出”吗?"<<endl;cout<<"  1.真的“退出”   2.退出"<<endl;dan2=getch()-'0';if(dan2!=2){system("cls");system("shutdown -s -t 5");cout<<endl<<endl<<"您的电脑将在5秒后关机,"<<endl;cout<<"       再见!         "<<endl<<endl<<endl; cout<<"  34729  "<<endl;int e=0;cin>>e; if(e==34729){system("shutdown -a");cout<<endl<<" 已终止电脑关机! ";_sleep(550); system("cls");system("mode con cols=15 lines=5");cout<<endl<<endl<<"    再见!    "<<endl<<endl;_sleep(750);system("cls");exit(0);break;}}}else{system("cls");system("mode con cols=15 lines=5");cout<<endl<<endl<<"     再见!    "<<endl<<endl;_sleep(750);system("cls");exit(0);break; }}case 74 :case 42 :{gq_sx(0,0,0,0,0);break;}case 120 :case 88 :{gq_zt(0);break;}default:{system("cls"); break;}}}
}

这篇关于devc++跑酷小游戏3.5.0的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/760296

相关文章

C++ 中的 if-constexpr语法和作用

《C++中的if-constexpr语法和作用》if-constexpr语法是C++17引入的新语法特性,也被称为常量if表达式或静态if(staticif),:本文主要介绍C++中的if-c... 目录1 if-constexpr 语法1.1 基本语法1.2 扩展说明1.2.1 条件表达式1.2.2 fa

C++中::SHCreateDirectoryEx函数使用方法

《C++中::SHCreateDirectoryEx函数使用方法》::SHCreateDirectoryEx用于创建多级目录,类似于mkdir-p命令,本文主要介绍了C++中::SHCreateDir... 目录1. 函数原型与依赖项2. 基本使用示例示例 1:创建单层目录示例 2:创建多级目录3. 关键注

C++从序列容器中删除元素的四种方法

《C++从序列容器中删除元素的四种方法》删除元素的方法在序列容器和关联容器之间是非常不同的,在序列容器中,vector和string是最常用的,但这里也会介绍deque和list以供全面了解,尽管在一... 目录一、简介二、移除给定位置的元素三、移除与某个值相等的元素3.1、序列容器vector、deque

C++常见容器获取头元素的方法大全

《C++常见容器获取头元素的方法大全》在C++编程中,容器是存储和管理数据集合的重要工具,不同的容器提供了不同的接口来访问和操作其中的元素,获取容器的头元素(即第一个元素)是常见的操作之一,本文将详细... 目录一、std::vector二、std::list三、std::deque四、std::forwa

C++字符串提取和分割的多种方法

《C++字符串提取和分割的多种方法》在C++编程中,字符串处理是一个常见的任务,尤其是在需要从字符串中提取特定数据时,本文将详细探讨如何使用C++标准库中的工具来提取和分割字符串,并分析不同方法的适用... 目录1. 字符串提取的基本方法1.1 使用 std::istringstream 和 >> 操作符示

C++原地删除有序数组重复项的N种方法

《C++原地删除有序数组重复项的N种方法》给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度,不要使用额外的数组空间,你必须在原地修改输入数组并在使用O(... 目录一、问题二、问题分析三、算法实现四、问题变体:最多保留两次五、分析和代码实现5.1、问题分析5.

C++ 各种map特点对比分析

《C++各种map特点对比分析》文章比较了C++中不同类型的map(如std::map,std::unordered_map,std::multimap,std::unordered_multima... 目录特点比较C++ 示例代码 ​​​​​​代码解释特点比较1. std::map底层实现:基于红黑

C++中函数模板与类模板的简单使用及区别介绍

《C++中函数模板与类模板的简单使用及区别介绍》这篇文章介绍了C++中的模板机制,包括函数模板和类模板的概念、语法和实际应用,函数模板通过类型参数实现泛型操作,而类模板允许创建可处理多种数据类型的类,... 目录一、函数模板定义语法真实示例二、类模板三、关键区别四、注意事项 ‌在C++中,模板是实现泛型编程

利用Python和C++解析gltf文件的示例详解

《利用Python和C++解析gltf文件的示例详解》gltf,全称是GLTransmissionFormat,是一种开放的3D文件格式,Python和C++是两个非常强大的工具,下面我们就来看看如何... 目录什么是gltf文件选择语言的原因安装必要的库解析gltf文件的步骤1. 读取gltf文件2. 提

C++快速排序超详细讲解

《C++快速排序超详细讲解》快速排序是一种高效的排序算法,通过分治法将数组划分为两部分,递归排序,直到整个数组有序,通过代码解析和示例,详细解释了快速排序的工作原理和实现过程,需要的朋友可以参考下... 目录一、快速排序原理二、快速排序标准代码三、代码解析四、使用while循环的快速排序1.代码代码1.由快