目录
- 开头
 - 程序
 - 程序的流程图
 - 程序游玩的效果
 - 下一篇博客要说的东西
 
开头
大家好,我叫这是我58。
程序
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
struct near {
	int i;
	int ia;
	int ix;
	int iy;
	int iwalk;
};
void printnear(const char* const cp, char ca, near* n) {
	int i = 0;
	int arr[9] = { -33,-32,-31,-1,0,1,31,32,33 };
	for (; i < 9; i++) {
		cout << "\033[" << ('G' == cp[arr[i]] ? "32;1m" : 4 == i && '0' == ca && (n->i == n->ix || n->ia == n->iy) ? "32m" : "0m") << cp[arr[i]] << "\033[0m" << (i % 3 - 2 ? "" : "#\n");
	}
	cout << "####" << endl << "你走了\033[" << ('0' == ca ? "32;1m" : "31;1m") << n->iwalk << "\033[0m步" << endl;
}
int main() {
	srand((unsigned int)time(NULL));
	near n = { rand() % 30 + 1, rand() % 30 + 1 };
	char strmaze[32][32] = {
		'@','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','@',
		'|',' ',' ',' ',' ','*',' ',' ','*',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ','|',
		'|','*',' ','*',' ','*',' ',' ','*',' ',' ','*',' ','*','*',' ','*','*',' ',' ',' ',' ',' ','*',' ','*',' ','*',' ',' ',' ','|',
		'|',' ',' ',' ',' ','*','*',' ',' ',' ','*',' ',' ','*',' ','*',' ',' ','*',' ','*',' ',' ','*',' ',' ',' ',' ',' ','*',' ','|',
		'|',' ','*',' ','*','*',' ',' ','*','*','*',' ',' ','*',' ',' ',' ',' ','*','*',' ',' ','*',' ','*',' ','*',' ','*',' ',' ','|',
		'|',' ',' ',' ',' ','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' ','*','*',' ','*',' ',' ','*',' ',' ','*','|',
		'|',' ','*',' ',' ','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','|',
		'|','*','*','*',' ',' ',' ','*',' ',' ','*','*','*',' ','*',' ',' ','*',' ','*',' ','*',' ',' ',' ',' ',' ',' ','*','*',' ','|',
		'|',' ','*',' ',' ','*',' ',' ',' ',' ','*',' ','*',' ','*','*',' ','*',' ','*',' ','*',' ',' ','*','*',' ','*',' ',' ','*','|',
		'|',' ','*','*','*','*',' ',' ',' ','*',' ',' ',' ','*',' ',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','|',
		'|',' ',' ','*',' ',' ',' ','*','*',' ',' ',' ','*',' ',' ','*','*',' ','*',' ',' ',' ','*',' ',' ',' ','*',' ',' ',' ',' ','|',
		'|','*',' ',' ','*',' ',' ',' ',' ',' ',' ','*',' ',' ','*',' ',' ',' ','*','*',' ',' ',' ',' ','*',' ',' ','*',' ',' ',' ','|',
		'|',' ',' ',' ',' ',' ','*',' ','*',' ','*',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','|',
		'|',' ','*',' ',' ','*',' ',' ','*',' ','*',' ','*',' ','*',' ','*',' ',' ','*',' ',' ','*',' ',' ',' ',' ',' ','*',' ',' ','|',
		'|',' ',' ','*',' ','*',' ',' ','*',' ',' ',' ','*','*','*',' ',' ',' ',' ',' ',' ','*','*','*',' ','*',' ','*',' ',' ','*','|',
		'|','*',' ','*',' ',' ','*',' ','*',' ','*',' ',' ','*',' ','*',' ','*',' ',' ','*','*',' ',' ',' ',' ',' ',' ','*',' ',' ','|',
		'|',' ',' ','*',' ',' ',' ','*','*',' ',' ',' ','*',' ',' ',' ',' ',' ','*',' ',' ','*','*','*',' ',' ',' ',' ',' ',' ',' ','|',
		'|',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ','*',' ',' ',' ','*',' ',' ','*',' ',' ',' ','*','|',
		'|',' ',' ','*','*',' ','*','*',' ','*',' ',' ',' ',' ','*',' ','*',' ',' ','*','*','*','*','*',' ','*','*','*','*',' ',' ','|',
		'|',' ',' ','*',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*','*',' ',' ','*',' ','*',' ',' ',' ','*',' ',' ','*','*',' ','|',
		'|',' ','*',' ',' ',' ','*',' ',' ',' ','*',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*',' ',' ','*',' ',' ',' ',' ',' ',' ','|',
		'|',' ',' ',' ',' ',' ',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' ',' ',' ','*',' ','*',' ',' ',' ','|',
		'|','*',' ','*',' ',' ',' ','*','*',' ','*',' ','*',' ','*',' ',' ',' ',' ','*',' ',' ','*',' ','*',' ','*',' ',' ',' ','*','|',
		'|',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ','*',' ','|',
		'|',' ',' ','*',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ',' ','|',
		'|','*',' ',' ',' ',' ',' ','*',' ','*','*',' ',' ','*',' ',' ','*','*',' ',' ',' ','*',' ','*',' ','*',' ','*',' ','*',' ','|',
		'|',' ','*',' ','*',' ','*',' ','*',' ','*',' ','*',' ',' ','*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','*',' ','|',
		'|',' ','*',' ',' ','*',' ',' ','*',' ',' ',' ',' ',' ','*',' ','*',' ',' ',' ','*',' ',' ',' ','*',' ',' ',' ','*',' ',' ','|',
		'|',' ','*','*',' ',' ',' ',' ','*',' ','*',' ',' ','*',' ',' ',' ','*','*','*',' ',' ','*',' ','*',' ','*',' ',' ','*',' ','|',
		'|',' ',' ',' ',' ',' ',' ','*',' ',' ',' ','*',' ',' ','*','*',' ',' ',' ',' ',' ','*',' ',' ','*','*',' ','*',' ',' ',' ','|',
		'|','*',' ','*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ','*',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ','|',
		'@','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','@',
	};
	char ca = 0;
	strmaze[n.i][n.ia] = 'P';
	char* cp = &strmaze[n.i][n.ia];
	while ('P' == strmaze[n.i = rand() % 30 + 1][n.ia = rand() % 30 + 1]) {
		;
	}
	strmaze[n.i][n.ia] = 'G';
	char ch = 0;
	cout << "欢迎你来玩这个\033[7m黑暗\033[0m迷宫,在这个迷宫中,“P”是你,“*”是墙,你不能走到这,空格是你可以走的地方,“w”上移,“a”左移,“s”下移,“d”右移,而\033[32;1m“G”\033[0m是\033[32;1m终点\033[0m,走到这能让你\033[32;1m胜利\033[0m,并且,\033[4m在这个迷宫中你的出生点与\033[32;1m“G”终点\033[0;4m是随机指定的\033[0m,\033[4m而你的可视范围是以你为中心点的3*3的方块\033[0m。其中,这迷宫游戏有\033[32;1m两个\033[31m模式\033[0m,\033[32;1m一个模式是简单模式\033[0m,以\033[32;1m这个模式开始游戏就会给你提供一些\033[4m增益\033[0m:如果\033[32;1m终点“G”\033[0m的X坐标与你的X坐标相等,或者\033[32;1m终点“G”\033[0m的Y坐标与你的Y坐标相等,那么你就会变\033[32m绿\033[0m,\033[31m另一个模式是困难模式,\033[4m没有任何的增益,全靠找。\033[0m这就是这迷宫的规则,你听明白了吗?" << endl << endl << "**************" << endl << "* \033[32;1m0.简单模式\033[0m *" << endl << "* \033[31m1.困难模式\033[0m *" << endl << "**************" << endl;
	cin >> ca;
	while ('0' != ca && '1' != ca) {
		cout << "\033[31;1m输入错误,请重新输入 ->\033[0m";
		rewind(stdin);
		cin >> ca;
	}
	system("cls");
	while ('G' == strmaze[n.i][n.ia]) {
		n.ix = (cp - &strmaze[0][0]) / 32;
		n.iy = (cp - &strmaze[0][0]) % 32;
		printnear(cp, ca, &n);
		cin >> ch;
		rewind(stdin);
		*cp = ' ';
		switch (ch) {
		case 'w':
			1 != n.ix && '*' != *(cp - 32) && (cp -= 32, n.iwalk++);
			break;
		case 'a':
			1 != n.iy && '*' != *(cp - 1) && (cp--, n.iwalk++);
			break;
		case 's':
			30 != n.ix && '*' != *(cp + 32) && (cp += 32, n.iwalk++);
			break;
		case 'd':
			30 != n.iy && '*' != *(cp + 1) && (cp++, n.iwalk++);
			break;
		default:
			break;
		}
		*cp = 'P';
		system("cls");
	}
	system("color 0A");
	cout << "恭喜你,走了\033[3" << ('0' == ca ? "2m" : "3;1m") << n.iwalk << "\033[0;32;1m步就赢了" << endl;
	return 0;
}
 
程序的流程图

程序游玩的效果
黑暗迷宫
下一篇博客要说的东西
C++平台跳跃游戏




















