目录
- 开头
- 程序
- 程序的流程图
- 程序游玩的效果
- 下一篇博客要说的东西
开头
大家好,我叫这是我58。
程序
#include <iostream>
using namespace std;
void printmaze(const char strmaze[11][11]) {
int i = 0;
int ia = 0;
for (; i < 11; i++) {
for (ia = 0; ia < 11; ia++) {
cout << "\033[" << ('0' == strmaze[i][ia] ? "33" : 'G' == strmaze[i][ia] ? "32;1" : "0") << "m" << strmaze[i][ia] << "\033[0m";
}
cout << "|" << endl;
}
cout << "-----------@" << endl;
}
int main() {
char strmaze[11][11] = {
'P','0','*','0','*','0','0',' ','0',' ',' ',
' ',' ','*',' ','*',' ',' ','0',' ',' ',' ',
'*','*','*',' ','*',' ','*',' ','*',' ',' ',
'0',' ','*',' ','*','0','*',' ',' ',' ',' ',
' ',' ','*',' ',' ',' ','0','*','*','*',' ',
' ','0','*',' ','0','0',' ','*',' ','*','*',
' ',' ','*','*',' ',' ','0','*','*','*','0',
' ',' ','*','0','*',' ',' ','*',' ',' ',' ',
'0',' ','*',' ','*',' ','*',' ',' ','*','0',
' ',' ','*',' ','*','*','*','0',' ','*',' ',
' ',' ','*',' ',' ','0',' ',' ',' ','*','G',
};
char* cp = &strmaze[0][0];
char ch = 0;
int i = 0;
bool bpw = 0;
int doorarr[36] = {0,1,3,0,5,1,0,8,8,0,0,3,3,5,4,6,1,7,0,5,0,6,6,6,5,5,9,7,6,10,8,10,5,4,7,3};
cout << "欢迎你来玩这个\033[33m门\033[0m迷宫,在这个迷宫中,“P”是你,“*”是墙,你不能走到这,空格是你可以走的地方,“w”使你上移,“a”使你左移,“s”使你下移,“d”使你右移,而\033[32;1m“G”\033[0m是\033[32;1m终点\033[0m,走到这能让你\033[32;1m胜利\033[0m,并且,\033[33m“0”\033[0m是\033[33m门\033[0m,按“\033[33mz\033[0m”键进入就可以走到\033[33m另外一扇门\033[0m的前面。这就是这迷宫的规则,你听明白了吗?" << endl << endl;
system("pause");
system("cls");
while ('G' == strmaze[10][10]) {
int ix = (cp - &strmaze[0][0]) / 11;
int iy = (cp - &strmaze[0][0]) % 11;
printmaze(strmaze);
cin >> ch;
rewind(stdin);
*cp = ' ';
switch (ch) {
case 'w':
ix && '*' != *(cp - 11) && '0' != *(cp - 11) && (cp -= 11);
bpw = 1;
break;
case 'a':
iy && '*' != *(cp - 1) && '0' != *(cp - 1) && (cp--);
bpw = 0;
break;
case 's':
10 != ix && '*' != *(cp + 11) && '0' != *(cp + 11) && (cp += 11);
bpw = 0;
break;
case 'd':
10 != iy && '*' != *(cp + 1) && '0' != *(cp + 1) && (cp++);
bpw = 0;
break;
case 'z':
if (bpw) {
for (i = 0; i < 36; i += 2) {
if (ix - 1 == doorarr[i] && iy == doorarr[i + 1]) {
if (i / 2 % 2) {
cp = &strmaze[doorarr[i - 2] + 1][doorarr[i - 1]];
}
else {
cp = &strmaze[doorarr[i + 2] + 1][doorarr[i + 3]];
}
}
}
}
break;
default:
break;
}
*cp = 'P';
system("cls");
}
system("color 0A");
cout << "恭喜你,你赢了" << endl;
return 0;
}
程序的流程图
程序游玩的效果
门迷宫
下一篇博客要说的东西
C++两点成一线