刚刚写完了一篇博客,不久就得到了回应,还收获了一个粉丝,并且我的一个粉丝“[PE]经典八炮”给我发了个666,即使只有三个字,三个粉丝,我也很高兴!

于是我决定趁热打铁,把我们的走迷宫小游戏1.2版本,也是最后一个版本给写完。当然,我明天还会写另一个小游戏的代码。

先放上资源:c++走迷宫1.2最终版-C++文档类资源-CSDN下载

话不多说,直接开始:

 1.更新内容

老样子,玩法内容要改一下,因为版本升级了。

代码:

if(ch=='b'){
		system("cls");
		string c="使用wasd控制‘*’(玩家)移动,‘#’为边界,‘0’是终点";
		string c1="玩家目标是通过移动到达终点,即可胜利。";
		string c2="说明:此为走迷宫最终版本。";
		string c3="更新:增加了换肤功能。";
		cout<<"版本:1.2"<<endl;//注意,1.2版本了
		cout<<"按1直接显示所有内容,否则按2。"<<endl;
		int q;
		q=getch();
		if(q=='1'){
			cout<<c3<<endl<<c<<endl<<c1<<endl<<c2<<endl;
		} 
		if(q=='2'){
			for(int i=0;i<c3.size();i++){
				cout<<c3[i];
				Sleep(100);//延时 
			} 
			cout<<endl;
			for(int i=0;i<c.size();i++){
				cout<<c[i];
				Sleep(100);
			} 
			cout<<endl;
			for(int i=0;i<c1.size();i++){
				cout<<c1[i];
				Sleep(100);
			} 
			cout<<endl;
			for(int i=0;i<c2.size();i++){
				cout<<c2[i];
				Sleep(100);
			} 
			cout<<endl;
		}
		cout<<"按y开始游戏。"; 
		ch=getch();
	}

截至目前,我们写了:

/*
	作者:瑞 
	制作日期:2022/7/29/18:04:40
	适合编译环境:DEV-C++ 
*/ 
#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>
using namespace std;
char a[50][50]={"############",
				"#*         #",
				"# ######## #",
				"#        # #",
				"##### ## # #",
				"# # #  #####",
				"## # #     0",
				"############"
};
char a1[50][50]={"############",
                "#*         #",
                "########## #",
                "#          #",
                "# ##########",
                "#          0",
                "############",
};     
char a2[50][50]={"################",
                "#*       #     #",
                "# ## ### # ## ##",
                "#  #   #   #   #",
                "## ### # # # # #",
                "#   #  # # # # #",
                "# # # # # ##  ##",
				"#   ###   ###  0",
				"################",
};
char a3[50][50]={"#####################",
                "#*      #       # # 0",
				"# ### # # ### # # # #",
				"#  #  #     # #   # #",
				"##  #  #### # ####  #",
				"#   #   #  # #     ##",
				"#   # #   #    # #  #",
				"# # # ####### ####  #",
				"#   #         #     #",
				"#####################",	
};
char a4[210][210]={//地图(手搓,累死了) 
				"##################################################",
				"##*             ##              ##              ##",
				"##  ##########  ##  ######  ######  ######  ######",
				"##      ##      ##      ##  ##      ##  ##      ##",
				"##########  ##########  ##  ##  ######  ######  ##",
				"##      ##          ##  ##      ##          ##  ##",
				"##  ##  ##########  ##  ##########  ##########  ##",
				"##  ##              ##  ##          ##          ##",
				"##  ##########  ######  ######  ##  ##  ######  ##",
				"##          ##  ##              ##  ##      ##  ##",
				"##########  ######  ##############  ######  ##  ##",
				"##          ##      ##          ##      ##  ##  ##",
				"##  ##  ######  ######  ######  ##########  ##  ##",
				"##  ##  ##      ##      ##  ##          ##  ##  ##",
				"##  ######  ######  ######  ##########  ##  ##  ##",
				"##              ##  ##          ##      ##  ##  ##",
				"##################  ##  ##########  ######  ######",
				"##          ##      ##      ##      ##          ##",
				"##  ######  ##  ######  ##  ##  ##############  ##",
				"##  ##          ##      ##              ##      ##",
				"##  ##############  ##################  ##  ######",
				"##          ##      ##              ##  ##      ##",
				"##  ######  ##########  ##############  ######  ##",
				"##      ##              ##                      00",
				"##################################################",
};
int main()
{
	system("title 走迷宫1.2最终版本");//标题 
	system("mode con cols=60 lines=37");//设置窗口大小
	string s="|                          走迷宫                          |";
	string s1="|                        开 始 游 戏                       |";
	string s2="|                        玩 法 说 明                       |";
	cout<<"@==========================================================@"<<endl;
	cout<<"|                                                          |"<<endl;
	cout<<"|                                                          |"<<endl;
	for(int i=0;i<s.size();i++){
		cout<<s[i];
		Sleep(10);//Sleep函数延长时间 
	}
	cout<<endl;
	cout<<"|                                                          |"<<endl;
	for(int i=0;i<s1.size();i++){
		cout<<s1[i];
		Sleep(10);
	}
	cout<<endl;
	cout<<"|                                                          |"<<endl;
	for(int i=0;i<s2.size();i++){
		cout<<s2[i];
		Sleep(10);
	}
	cout<<endl;
	cout<<"|                                                          |"<<endl;
	cout<<"|                                                          |"<<endl;
	cout<<"|                                                          |"<<endl;
	cout<<"|(按‘k’开始游戏,按‘b’看玩法说明)        |"<<endl;
	cout<<"@==========================================================@"<<endl;
	char ch;
	ch=getch();//提取键盘指令 
	if(ch=='b'){
		system("cls");
		string c="使用wasd控制‘*’(玩家)移动,‘#’为边界,‘0’是终点";
		string c1="玩家目标是通过移动到达终点,即可胜利。";
		string c2="说明:此为走迷宫最终版本。";
		string c3="更新:增加了换肤功能。";
		cout<<"版本:1.2"<<endl;
		cout<<"按1直接显示所有内容,否则按2。"<<endl;
		int q;
		q=getch();
		if(q=='1'){
			cout<<c3<<endl<<c<<endl<<c1<<endl<<c2<<endl;
		} 
		if(q=='2'){
			for(int i=0;i<c3.size();i++){
				cout<<c3[i];
				Sleep(100);//延时 
			} 
			cout<<endl;
			for(int i=0;i<c.size();i++){
				cout<<c[i];
				Sleep(100);
			} 
			cout<<endl;
			for(int i=0;i<c1.size();i++){
				cout<<c1[i];
				Sleep(100);
			} 
			cout<<endl;
			for(int i=0;i<c2.size();i++){
				cout<<c2[i];
				Sleep(100);
			} 
			cout<<endl;
		}
		cout<<"按y开始游戏。"; 
		ch=getch();
	}
	if(ch=='k'||ch=='y'||ch=='q'){
		system("cls");//清屏 
		cout<<"                         第一关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=7;i++){
			puts(a[i]);//将地图一行一行输出 
		}
		char b;
		int x=1,y=1;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b=getch();
			if(a[x][y+1]=='0'){//判断是否到达终点 
				system("cls");
				cout<<"恭喜你走出迷宫!是否进入下一关?(y进入,b退出)";
				char ch1;
				ch1=getch();
				if(ch1=='y')break;
				else if(ch1=='b')return 0;
			}
			if(b=='a'){ 
				if(a[x][y-1]!='#'){
					a[x][y]=' ';
					y--;
					a[x][y]='*'; 
				}
			}
			if(b=='s'){
				if(a[x+1][y]!='#'){
					a[x][y]=' ';
					x++;
					a[x][y]='*';
				}
			}
			if(b=='d'){
				if(a[x][y+1]!='#'){
					a[x][y]=' ';
					y++;
					a[x][y]='*';
				}
			}
			if(b=='w'){
				if(a[x-1][y]!='#'){
					a[x][y]=' ';
					x--;
					a[x][y]='*';
				}
			}
			if(b=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=7;i++){
				puts(a[i]);
			}
		}
		system("cls");
		cout<<"                         第二关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=6;i++){
			puts(a1[i]);//将地图一行一行输出 
		}
		char b1;
		int x1=1,y1=1;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b1=getch();
			if(a1[x1][y1+1]=='0'){//判断是否到达终点 
				system("cls");
				cout<<"恭喜你走出迷宫!是否进入下一关?(y进入,b退出)";
				char ch2;
				ch2=getch();
				if(ch2=='y')break;
				else if(ch2=='b')return 0;
			}
			if(b1=='a'){ 
				if(a1[x1][y1-1]!='#'){
					a1[x1][y1]=' ';
					y1--;
					a1[x1][y1]='*'; 
				}
			}
			if(b1=='s'){
				if(a1[x1+1][y1]!='#'){
					a1[x1][y1]=' ';
					x1++;
					a1[x1][y1]='*';
				}
			}
			if(b1=='d'){
				if(a1[x1][y1+1]!='#'){
					a1[x1][y1]=' ';
					y1++;
					a1[x1][y1]='*';
				}
			}
			if(b1=='w'){
				if(a1[x1-1][y1]!='#'){
					a1[x1][y1]=' ';
					x1--;
					a1[x1][y1]='*';
				}
			}
			if(b1=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=6;i++){
				puts(a1[i]);
			}
		}
		system("cls");
		cout<<"                         第三关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=8;i++){
			puts(a2[i]);//将地图一行一行输出 
		}
		char b2;
		int x2=1,y2=1;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b2=getch();
			if(a2[x2][y2+1]=='0'){//判断是否到达终点 
				system("cls");
				cout<<"恭喜你走出迷宫!是否进入下一关?(y进入,b退出)";
				char ch3;
				ch3=getch();
				if(ch3=='y')break;
				else if(ch3=='b')return 0;
			}
			if(b2=='a'){ 
				if(a2[x2][y2-1]!='#'){
					a2[x2][y2]=' ';
					y2--;
					a2[x2][y2]='*'; 
				}
			}
			if(b2=='s'){
				if(a2[x2+1][y2]!='#'){
					a2[x2][y2]=' ';
					x2++;
					a2[x2][y2]='*';
				}
			}
			if(b2=='d'){
				if(a2[x2][y2+1]!='#'){
					a2[x2][y2]=' ';
					y2++;
					a2[x2][y2]='*';
				}
			}
			if(b2=='w'){
				if(a2[x2-1][y2]!='#'){
					a2[x2][y2]=' ';
					x2--;
					a2[x2][y2]='*';
				}
			}
			if(b2=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=8;i++){
				puts(a2[i]);
			}
		}
		system("cls");
		cout<<"                         第四关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=9;i++){
			puts(a3[i]);//将地图一行一行输出 
		}
		char b3;
		int x3=1,y3=1;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b3=getch();
			if(a3[x3][y3+1]=='0'){//判断是否到达终点 
				system("cls");
				cout<<"恭喜你走出迷宫!是否进入下一关?(y进入,b退出)";
				char ch4;
				ch4=getch();
				if(ch4=='y')break;
				else if(ch4=='b')return 0;
			}
			if(b3=='a'){ 
				if(a3[x3][y3-1]!='#'){
					a3[x3][y3]=' ';
					y3--;
					a3[x3][y3]='*'; 
				}
			}
			if(b3=='s'){
				if(a3[x3+1][y3]!='#'){
					a3[x3][y3]=' ';
					x3++;
					a3[x3][y3]='*';
				}
			}
			if(b3=='d'){
				if(a3[x3][y3+1]!='#'){
					a3[x3][y3]=' ';
					y3++;
					a3[x3][y3]='*';
				}
			}
			if(b3=='w'){
				if(a3[x3-1][y3]!='#'){
					a3[x3][y3]=' ';
					x3--;
					a3[x3][y3]='*';
				}
			}
			if(b3=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=9;i++){
				puts(a3[i]);
			}
		}
		system("cls");
		cout<<"                         第五关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=24;i++){
			puts(a4[i]);//将地图一行一行输出 
		}
		char b4;
		int x4=1,y4=2;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b4=getch();
			if(a4[x4][y4+1]=='0'){//判断是否到达终点 
				system("cls");
				string e="恭喜你通关了走迷宫游戏,如果好玩不妨动动小手,给作者点个赞,加个关注吧!";
				for(int i=0;i<e.size();i++){
					cout<<e[i];
					Sleep(100);
				}
				cout<<endl;
				cout<<"制作:瑞,CSDN"<<endl<<"1.2版本待推出……"; 
				return 0;
			}
			if(b4=='a'){ 
				if(a4[x4][y4-1]!='#'){
					a4[x4][y4]=' ';
					y4--;
					a4[x4][y4]='*'; 
				}
			}
			if(b4=='s'){
				if(a4[x4+1][y4]!='#'){
					a4[x4][y4]=' ';
					x4++;
					a4[x4][y4]='*';
				}
			}
			if(b4=='d'){
				if(a4[x4][y4+1]!='#'){
					a4[x4][y4]=' ';
					y4++;
					a4[x4][y4]='*';
				}
			}
			if(b4=='w'){
				if(a4[x4-1][y4]!='#'){
					a4[x4][y4]=' ';
					x4--;
					a4[x4][y4]='*';
				}
			}
			if(b4=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=24;i++){
				puts(a4[i]);
			}
		}
	}
	return 0;
} 

2.改皮肤(就是改颜色)

改颜色,很简单,有很多种方法,system("color")是最典型的一种,感兴趣的小伙伴可以去我的另一篇博客教你如何用c++写2D版我的世界(1)——续_ 瑞的博客-CSDN博客,在那篇博客里我详细的讲了几种改变颜色的方法。

这里我们用简单的system("color")。

给大家贴出一张颜色编码对照表:

设置默认的控制台前景和背景颜色。

COLOR [attr]

  attr        指定控制台输出的颜色属性。

颜色属性由两个十六进制数字指定 -- 第一个
对应于背景,第二个对应于前景。每个数字
可以为以下任何值:

    0 = 黑色       8 = 灰色
    1 = 蓝色       9 = 淡蓝色
    2 = 绿色       A = 淡绿色
    3 = 浅绿色     B = 淡浅绿色
    4 = 红色       C = 淡红色
    5 = 紫色       D = 淡紫色
    6 = 黄色       E = 淡黄色
    7 = 白色       F = 亮白色

如果没有给定任何参数,此命令会将颜色还原到 CMD.EXE 启动时
的颜色。这个值来自当前控制台
窗口、/T 命令行开关或 DefaultColor 注册表
值。

如果尝试使用相同的
前景和背景颜色来执行
 COLOR 命令,COLOR 命令会将 ERRORLEVEL 设置为 1。

然后先把换皮肤这部分的代码贴出来:

if(ch=='d'||ch=='e'){
		system("cls");
		cout<<"请选择皮肤:"<<endl;
		cout<<"1.【日间色】"<<endl<<"2.【夜间色】"<<endl<<"3.【黑客】"<<endl<<"4.【科幻】"<<endl<<"5.【紫水晶】"<<endl;
		cout<<"开始游戏请按q,换肤请输入序号。";
		char sh;
		while(1){
			sh=getch();
			if(sh-'0'==1)
					system("color f0");
			else if(sh-'0'==2)
					system("color 0f");
			else if(sh-'0'==3)
					system("color 0a");
			else if(sh-'0'==4)
					system("color 09");
			else if(sh-'0'==5)
					system("color 01");
			else if(sh=='q'){
				ch='q';
				break;
			}
		}
	}

然后我们来解读一下这个代码。

首先,当ch变量读到的键盘指令为d或e时,就执行下面操作,先将屏幕清屏,输出“请选择皮肤:”,换行,再输出各个皮肤名称:【日间色】【夜间色】【黑客】【科幻】【紫水晶】,然后输出开始游戏请按q,换肤请输入序号。之后定义一个sh变量,用来存储接下来的键盘指令,然后重复执行(因为你不可能一下子就确定你想换的皮肤,用户要反复选择)如果输入1,将皮肤改成日间色,如果输入2,将皮肤改成夜间色……以此类推,然后如果输入q,就将ch变量转为q,一边下面判断,然后结束换肤,break退出。

看到上面这个解释,是不是明白多了?

总代码:

/*
	作者:瑞 
	制作日期:2022/7/29/18:04:40
	适合编译环境:DEV-C++ 
*/ 
#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>
using namespace std;
char a[50][50]={"############",
				"#*         #",
				"# ######## #",
				"#        # #",
				"##### ## # #",
				"# # #  #####",
				"## # #     0",
				"############"
};
char a1[50][50]={"############",
                "#*         #",
                "########## #",
                "#          #",
                "# ##########",
                "#          0",
                "############",
};     
char a2[50][50]={"################",
                "#*       #     #",
                "# ## ### # ## ##",
                "#  #   #   #   #",
                "## ### # # # # #",
                "#   #  # # # # #",
                "# # # # # ##  ##",
				"#   ###   ###  0",
				"################",
};
char a3[50][50]={"#####################",
                "#*      #       # # 0",
				"# ### # # ### # # # #",
				"#  #  #     # #   # #",
				"##  #  #### # ####  #",
				"#   #   #  # #     ##",
				"#   # #   #    # #  #",
				"# # # ####### ####  #",
				"#   #         #     #",
				"#####################",	
};
char a4[210][210]={//地图(手搓,累死了) 
				"##################################################",
				"##*             ##              ##              ##",
				"##  ##########  ##  ######  ######  ######  ######",
				"##      ##      ##      ##  ##      ##  ##      ##",
				"##########  ##########  ##  ##  ######  ######  ##",
				"##      ##          ##  ##      ##          ##  ##",
				"##  ##  ##########  ##  ##########  ##########  ##",
				"##  ##              ##  ##          ##          ##",
				"##  ##########  ######  ######  ##  ##  ######  ##",
				"##          ##  ##              ##  ##      ##  ##",
				"##########  ######  ##############  ######  ##  ##",
				"##          ##      ##          ##      ##  ##  ##",
				"##  ##  ######  ######  ######  ##########  ##  ##",
				"##  ##  ##      ##      ##  ##          ##  ##  ##",
				"##  ######  ######  ######  ##########  ##  ##  ##",
				"##              ##  ##          ##      ##  ##  ##",
				"##################  ##  ##########  ######  ######",
				"##          ##      ##      ##      ##          ##",
				"##  ######  ##  ######  ##  ##  ##############  ##",
				"##  ##          ##      ##              ##      ##",
				"##  ##############  ##################  ##  ######",
				"##          ##      ##              ##  ##      ##",
				"##  ######  ##########  ##############  ######  ##",
				"##      ##              ##                      00",
				"##################################################",
};
int main()
{
	system("title 走迷宫1.2最终版本");//标题 
	system("mode con cols=60 lines=37");//设置窗口大小
	string s="|                          走迷宫                          |";
	string s1="|                        开 始 游 戏                       |";
	string s2="|                        玩 法 说 明                       |";
	string s3="|                        更 换 皮 肤                       |"; 
	cout<<"@==========================================================@"<<endl;
	cout<<"|                                                          |"<<endl;
	cout<<"|                                                          |"<<endl;
	for(int i=0;i<s.size();i++){
		cout<<s[i];
		Sleep(10);//Sleep函数延长时间 
	}
	cout<<endl;
	cout<<"|                                                          |"<<endl;
	for(int i=0;i<s1.size();i++){
		cout<<s1[i];
		Sleep(10);
	}
	cout<<endl;
	cout<<"|                                                          |"<<endl;
	for(int i=0;i<s2.size();i++){
		cout<<s2[i];
		Sleep(10);
	}
	cout<<endl;
	cout<<"|                                                          |"<<endl;
	for(int i=0;i<s3.size();i++){
		cout<<s3[i];
		Sleep(10);
	}
	cout<<endl;
	cout<<"|                                                          |"<<endl;
	cout<<"|                                                          |"<<endl;
	cout<<"|                                                          |"<<endl;
	cout<<"|(按‘k’开始游戏,按‘b’看玩法说明,按‘d’换皮肤)        |"<<endl;
	cout<<"@==========================================================@"<<endl;
	char ch;
	ch=getch();//提取键盘指令 
	if(ch=='b'){
		system("cls");
		string c="使用wasd控制‘*’(玩家)移动,‘#’为边界,‘0’是终点";
		string c1="玩家目标是通过移动到达终点,即可胜利。";
		string c2="说明:此为走迷宫最终版本。";
		string c3="更新:增加了换肤功能。";
		cout<<"版本:1.2"<<endl;
		cout<<"按1直接显示所有内容,否则按2。"<<endl;
		int q;
		q=getch();
		if(q=='1'){
			cout<<c3<<endl<<c<<endl<<c1<<endl<<c2<<endl;
		} 
		if(q=='2'){
			for(int i=0;i<c3.size();i++){
				cout<<c3[i];
				Sleep(100);//延时 
			} 
			cout<<endl;
			for(int i=0;i<c.size();i++){
				cout<<c[i];
				Sleep(100);
			} 
			cout<<endl;
			for(int i=0;i<c1.size();i++){
				cout<<c1[i];
				Sleep(100);
			} 
			cout<<endl;
			for(int i=0;i<c2.size();i++){
				cout<<c2[i];
				Sleep(100);
			} 
			cout<<endl;
		}
		cout<<"按y开始游戏。按e换皮肤。"; 
		ch=getch();
	}
	if(ch=='d'||ch=='e'){
		system("cls");
		cout<<"请选择皮肤:"<<endl;
		cout<<"1.【日间色】"<<endl<<"2.【夜间色】"<<endl<<"3.【黑客】"<<endl<<"4.【科幻】"<<endl<<"5.【紫水晶】"<<endl;
		cout<<"开始游戏请按q,换肤请输入序号。";
		char sh;
		while(1){
			sh=getch();
			if(sh-'0'==1)
					system("color f0");
			else if(sh-'0'==2)
					system("color 0f");
			else if(sh-'0'==3)
					system("color 0a");
			else if(sh-'0'==4)
					system("color 09");
			else if(sh-'0'==5)
					system("color 01");
			else if(sh=='q'){
				ch='q';
				break;
			}
		}
	}
	if(ch=='k'||ch=='y'||ch=='q'){
		system("cls");//清屏 
		cout<<"                         第一关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=7;i++){
			puts(a[i]);//将地图一行一行输出 
		}
		char b;
		int x=1,y=1;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b=getch();
			if(a[x][y+1]=='0'){//判断是否到达终点 
				system("cls");
				cout<<"恭喜你走出迷宫!是否进入下一关?(y进入,b退出)";
				char ch1;
				ch1=getch();
				if(ch1=='y')break;
				else if(ch1=='b')return 0;
			}
			if(b=='a'){ 
				if(a[x][y-1]!='#'){
					a[x][y]=' ';
					y--;
					a[x][y]='*'; 
				}
			}
			if(b=='s'){
				if(a[x+1][y]!='#'){
					a[x][y]=' ';
					x++;
					a[x][y]='*';
				}
			}
			if(b=='d'){
				if(a[x][y+1]!='#'){
					a[x][y]=' ';
					y++;
					a[x][y]='*';
				}
			}
			if(b=='w'){
				if(a[x-1][y]!='#'){
					a[x][y]=' ';
					x--;
					a[x][y]='*';
				}
			}
			if(b=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=7;i++){
				puts(a[i]);
			}
		}
		system("cls");
		cout<<"                         第二关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=6;i++){
			puts(a1[i]);//将地图一行一行输出 
		}
		char b1;
		int x1=1,y1=1;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b1=getch();
			if(a1[x1][y1+1]=='0'){//判断是否到达终点 
				system("cls");
				cout<<"恭喜你走出迷宫!是否进入下一关?(y进入,b退出)";
				char ch2;
				ch2=getch();
				if(ch2=='y')break;
				else if(ch2=='b')return 0;
			}
			if(b1=='a'){ 
				if(a1[x1][y1-1]!='#'){
					a1[x1][y1]=' ';
					y1--;
					a1[x1][y1]='*'; 
				}
			}
			if(b1=='s'){
				if(a1[x1+1][y1]!='#'){
					a1[x1][y1]=' ';
					x1++;
					a1[x1][y1]='*';
				}
			}
			if(b1=='d'){
				if(a1[x1][y1+1]!='#'){
					a1[x1][y1]=' ';
					y1++;
					a1[x1][y1]='*';
				}
			}
			if(b1=='w'){
				if(a1[x1-1][y1]!='#'){
					a1[x1][y1]=' ';
					x1--;
					a1[x1][y1]='*';
				}
			}
			if(b1=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=6;i++){
				puts(a1[i]);
			}
		}
		system("cls");
		cout<<"                         第三关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=8;i++){
			puts(a2[i]);//将地图一行一行输出 
		}
		char b2;
		int x2=1,y2=1;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b2=getch();
			if(a2[x2][y2+1]=='0'){//判断是否到达终点 
				system("cls");
				cout<<"恭喜你走出迷宫!是否进入下一关?(y进入,b退出)";
				char ch3;
				ch3=getch();
				if(ch3=='y')break;
				else if(ch3=='b')return 0;
			}
			if(b2=='a'){ 
				if(a2[x2][y2-1]!='#'){
					a2[x2][y2]=' ';
					y2--;
					a2[x2][y2]='*'; 
				}
			}
			if(b2=='s'){
				if(a2[x2+1][y2]!='#'){
					a2[x2][y2]=' ';
					x2++;
					a2[x2][y2]='*';
				}
			}
			if(b2=='d'){
				if(a2[x2][y2+1]!='#'){
					a2[x2][y2]=' ';
					y2++;
					a2[x2][y2]='*';
				}
			}
			if(b2=='w'){
				if(a2[x2-1][y2]!='#'){
					a2[x2][y2]=' ';
					x2--;
					a2[x2][y2]='*';
				}
			}
			if(b2=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=8;i++){
				puts(a2[i]);
			}
		}
		system("cls");
		cout<<"                         第四关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=9;i++){
			puts(a3[i]);//将地图一行一行输出 
		}
		char b3;
		int x3=1,y3=1;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b3=getch();
			if(a3[x3][y3+1]=='0'){//判断是否到达终点 
				system("cls");
				cout<<"恭喜你走出迷宫!是否进入下一关?(y进入,b退出)";
				char ch4;
				ch4=getch();
				if(ch4=='y')break;
				else if(ch4=='b')return 0;
			}
			if(b3=='a'){ 
				if(a3[x3][y3-1]!='#'){
					a3[x3][y3]=' ';
					y3--;
					a3[x3][y3]='*'; 
				}
			}
			if(b3=='s'){
				if(a3[x3+1][y3]!='#'){
					a3[x3][y3]=' ';
					x3++;
					a3[x3][y3]='*';
				}
			}
			if(b3=='d'){
				if(a3[x3][y3+1]!='#'){
					a3[x3][y3]=' ';
					y3++;
					a3[x3][y3]='*';
				}
			}
			if(b3=='w'){
				if(a3[x3-1][y3]!='#'){
					a3[x3][y3]=' ';
					x3--;
					a3[x3][y3]='*';
				}
			}
			if(b3=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=9;i++){
				puts(a3[i]);
			}
		}
		system("cls");
		cout<<"                         第五关";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中";
		Sleep(2000);
		system("cls");
		cout<<"加载代码中 ◎         20%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎       40%";
		Sleep(2000);
		system("cls");
		cout<<"加载地图中 ◎◎◎     60%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎   80%";
		Sleep(2000);
		system("cls");
		cout<<"生成地图中 ◎◎◎◎◎ 100%";
		Sleep(2000);
		system("cls");
		cout<<"完成!!!";
		Sleep(2000);
		system("cls");
		for(int i=0;i<=24;i++){
			puts(a4[i]);//将地图一行一行输出 
		}
		char b4;
		int x4=1,y4=2;//玩家初始坐标 
		//wasd移动 
		while(1){//重复运动 
			cout<<"wasd上下左右移动,o退出"<<endl; 
			b4=getch();
			if(a4[x4][y4+1]=='0'){//判断是否到达终点 
				system("cls");
				string e="恭喜你通关了走迷宫游戏,如果好玩不妨动动小手,给作者点个赞,加个关注吧!";
				for(int i=0;i<e.size();i++){
					cout<<e[i];
					Sleep(100);
				}
				cout<<endl;
				cout<<"制作:瑞,CSDN"<<endl<<"1.2版本待推出……"; 
				return 0;
			}
			if(b4=='a'){ 
				if(a4[x4][y4-1]!='#'){
					a4[x4][y4]=' ';
					y4--;
					a4[x4][y4]='*'; 
				}
			}
			if(b4=='s'){
				if(a4[x4+1][y4]!='#'){
					a4[x4][y4]=' ';
					x4++;
					a4[x4][y4]='*';
				}
			}
			if(b4=='d'){
				if(a4[x4][y4+1]!='#'){
					a4[x4][y4]=' ';
					y4++;
					a4[x4][y4]='*';
				}
			}
			if(b4=='w'){
				if(a4[x4-1][y4]!='#'){
					a4[x4][y4]=' ';
					x4--;
					a4[x4][y4]='*';
				}
			}
			if(b4=='o'){//退出 
				return 0;
			}
			system("cls");
			for(int i=0;i<=24;i++){
				puts(a4[i]);
			}
		}
	}
	return 0;
} 

 好了,时间也不早了,我们的C++走迷宫也正式完成!完结撒花!

效果我会在评论里补发。

如果还有小伙伴想看我之前的博客,下面我给出了链接:

额,我要说一件重要的事+用C++编写一个走迷宫小游戏(1.1版)_ 瑞的博客-CSDN博客

用C++编写一个走迷宫游戏(1.0版)_ 瑞的博客-CSDN博客

再给出资源的链接:

1.0:c++走迷宫(原创作品)如要转载请标版权-其他文档类资源-CSDN下载

1.1:C++走迷宫游戏(原创)转载请标注版权-C++文档类资源-CSDN下载

1.2:在前面哦~

求关注+三连!

最后说一下,游戏里的某些地图和皮肤是从别的博客复制的。

投个票:

更多推荐

用DEV-C++写一个走迷宫小游戏1.2最终版(完结,撒花)