WSAD键控制,回车键提交
#include <bits/stdc++.h>
using namespace std;
string t[100][100] = {
{"#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#"},
{"#","○"," "," "," "," "," "," "," "," "," ","#"," "," "," ","#","#"," "," "," ","#"," ","#","#","#"," ","#","#","#","#"},
{"#"," ","#","#","#","#","#","#"," ","#"," ","#"," ","#"," "," "," "," ","#"," ","#"," ","#","#","#"," ","#","#","#","#"},
{"#"," ","#"," "," "," ","#","#"," ","#"," "," "," ","#"," ","#","#","#","#"," ","#"," ","#","#","#"," "," "," ","#","#"},
{"#"," "," "," ","#"," ","#","#"," "," ","#","#","#"," "," "," "," ","#"," "," ","#"," "," ","#","#"," ","#","#","#","#"},
{"#","#","#","#","#"," ","#"," "," "," "," "," ","#"," ","#","#","#","#","#"," ","#","#"," "," "," "," ","#","#","#","#"},
{"#"," "," "," ","#"," ","#","#","#","#","#"," ","#"," "," "," ","#"," "," "," ","#"," ","#"," ","#"," "," "," "," ","#"},
{"#"," ","#"," ","#"," "," "," "," ","#","#"," ","#"," ","#","#","#","#"," ","#","#"," ","#"," ","#"," ","#","#","#","#"},
{"#"," ","#"," ","#"," ","#","#"," "," "," "," "," "," ","#","#"," "," "," "," "," "," ","#"," ","#"," ","#","#","#","#"},
{"#"," ","#"," ","#"," ","#","#","#","#","#","#","#"," ","#","#"," ","#","#","#","#","#","#"," ","#"," "," "," ","#","#"},
{"#"," ","#"," "," "," ","#","#"," "," "," ","#","#","#","#","#","#","#","#","#","#","#"," ","#","#","#"," "," "," ","#"},
{"#"," ","#","#","#","#","#","#"," ","#"," ","#","#","#","#","#"," "," ","#"," "," "," "," "," "," "," "," ","#"," ","#"},
{"#"," "," "," "," "," "," "," "," ","#"," ","#"," "," "," "," "," ","#","#","#","#","#"," ","#","#","#"," ","#"," ","出"},
{"#"," ","#","#","#","#","#","#","#","#"," ","#","#","#","#","#"," ","#","#","#","#","#"," ","#","#","#"," ","#","#","#"},
{"#"," "," "," "," "," ","#"," ","#","#"," ","#","#","#","#","#"," ","#","#","#"," "," "," "," "," "," "," ","#","#","#"},
{"#","#","#","#","#"," ","#"," ","#","#"," ","#"," "," "," "," "," "," ","#","#","#","#","#","#","#","#"," ","#"," ","#"},
{"#"," "," "," "," "," ","#"," ","#","#"," ","#","#"," ","#","#","#"," "," "," "," "," "," "," "," ","#"," "," "," ","#"},
{"#"," ","#"," ","#","#","#"," "," "," "," "," "," "," ","#","#","#","#","#","#"," ","#","#","#","#","#","#","#"," ","#"},
{"#"," ","#"," "," "," "," ","#","#","#"," ","#","#"," "," "," "," "," "," ","#"," "," "," "," "," "," "," "," "," ","#"},
{"#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#"}
};
void show()
{
for(int i = 0; i < 20; i++)
{
for(int j = 0; j < 30; j++)
{
cout << t[i][j];
}
cout << endl;
}
return ;
}
int main()
{
char s;
int a = 1, b = 1;
while(true)
{
show();
cout << "输入走向(WSAD)";
cin >> s;
if(s == 'W')
{
if(t[a - 1][b] == "出")
{
system("cls");
cout << "#########################################################" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# 恭喜你走出了迷宫!!!!!! #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "#########################################################" << endl;
break;
}
if(a > 0)
{
if(t[a - 1][b] != "#")
{
swap(t[a - 1][b], t[a][b]);
a --;
}
}
}
else if(s == 'S')
{
if(t[a + 1][b] == "出")
{
system("cls");
cout << "#########################################################" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# 恭喜你走出了迷宫!!!!!! #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "#########################################################" << endl;
break;
}
if(a < 20)
{
if(t[a + 1][b] != "#")
{
swap(t[a + 1][b], t[a][b]);
a ++;
}
}
}
else if(s == 'A')
{
if(t[a][b - 1] == "出")
{
system("cls");
cout << "#########################################################" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# 恭喜你走出了迷宫!!!!!! #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "#########################################################" << endl;
break;
}
if(b > 0)
{
if(t[a][b - 1] != "#")
{
swap(t[a][b - 1], t[a][b]);
b --;
}
}
}
else if(s == 'D')
{
if(t[a][b + 1] == "出")
{
system("cls");
cout << "#########################################################" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# 恭喜你走出了迷宫!!!!!! #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "#########################################################" << endl;
break;
}
if(b < 30)
{
if(t[a][b + 1] != "#")
{
swap(t[a][b + 1], t[a][b]);
b ++;
}
}
}
system("cls");
}
return 0;
}