目录
- 开头
- 程序
- 程序的流程图
- 程序游玩的效果
- 下一篇博客要说的东西
开头
大家好,我叫这是我58。
程序
#include <iostream>
using namespace std;
void printmaze(char strmaze[5][5][5]) {
cout << "-----@" << endl;
int i = 0;
int ia = 0;
int ib = 0;
for (; i < 5; i++) {
for (ia = 0; ia < 5; ia++) {
for (ib = 0; ib < 5; ib++) {
cout << "\033[" << ('G' == strmaze[i][ia][ib] ? "32;1" : "0") << "m" << strmaze[i][ia][ib] << "\033[0m";
}
cout << "|" << endl;
}
cout << "-----@" << endl;
}
}
int main() {
char strmaze[5][5][5] = {
'P','*',' ','*','*',
'*',' ',' ',' ','*',
' ',' ','*',' ',' ',
' ','*','*','*',' ',
' ',' ','*',' ',' ',
' ',' ','*',' ',' ',
' ','*',' ','*',' ',
'*','*','*','*','*',
' ',' ','*',' ',' ',
' ',' ','*',' ',' ',
'*',' ',' ','*',' ',
'*',' ','*',' ',' ',
' ','*',' ','*','*',
' ',' ','*',' ',' ',
' ',' ','*',' ',' ',
'*','*',' ',' ',' ',
' ',' ','*','*',' ',
' ',' ','*',' ','*',
' ',' ','*',' ',' ',
' ',' ','*','*',' ',
'*','*',' ',' ',' ',
'*',' ',' ',' ',' ',
' ','*','*',' ','*',
' ',' ','*','*','*',
' ','*',' ',' ','G',
};
char* cp = &strmaze[0][0][0];
char ch = 0;
cout << "欢迎你来玩这个3D迷宫,在这个迷宫中,“P”是你,“*”是墙,空格是你可以走的地方,而\033[32;1m“G”\033[0m是\033[32;1m终点\033[0m,走到这就能让你胜利了,并且,按“w”能使你往上移,按“a”能使你往左移,按“s”能使你往下移,按“d”能使你往右移,按“q”能使你上一层,按“e”能使你下一层。这就是这迷宫的规则,你听明白了吗?" << endl << endl;
system("pause");
system("cls");
while ('G' == strmaze[4][4][4]) {
int ix = (cp - &strmaze[0][0][0]) / 25;
int iy = (cp - &strmaze[0][0][0]) / 5 % 5;
int iz = (cp - &strmaze[0][0][0]) % 5;
printmaze(strmaze);
cin >> ch;
rewind(stdin);
*cp = ' ';
switch (ch) {
case 'w':
iy && '*' != *(cp - 5) && (cp -= 5);
break;
case 'a':
iz && '*' != *(cp - 1) && (cp--);
break;
case 's':
4 != iy && '*' != *(cp + 5) && (cp += 5);
break;
case 'd':
4 != iz && '*' != *(cp + 1) && (cp++);
break;
case 'q':
ix && '*' != *(cp - 25) && (cp -= 25);
break;
case 'e':
4 != ix && '*' != *(cp + 25) && (cp += 25);
break;
default:
break;
}
*cp = 'P';
system("cls");
}
system("color 0A");
cout << "恭喜你,你赢了" << endl;
return 0;
}
程序的流程图
程序游玩的效果
3D迷宫
下一篇博客要说的东西
C++掉血迷宫