#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
main() {
char a[7][12]={"###########"
,"#o # #"
,"# ## ## #"
,"# # # # #"
,"# ### # #"
,"# # "
,"###########"
};
int i ,x,y,p,q;
char ch;
x = 1;
y = 1;
p = 5;
q = 10;
for (i = 0; i <= 6; i++)
{
puts(a[i]);
}
while (x!=p||y!=10)
{
ch = getch();
if (ch == 's') {
if (a[x + 1][y] != '#') {
a[x][y] = ' ';
x++;
a[x][y] = 'o';
}
}
if (ch == 'w') {
if (a[x-1][y] != '#') {
a[x][y] = ' ';
x--;
a[x][y]='o';
}
}
if (ch == 'a') {
if (a[x][y-1] != '#') {
a[x][y] = ' ';
y--;
a[x][y]='o';
}
}
if (ch == 'd') {
if (a[x][y + 1] != '#') {
a[x][y]= ' ';
y++;
a[x][y]='o';
}
}
system("cls");
for (i = 0; i <= 6; i++)
{
puts(a[i]);
}
}
printf("成功走出迷宫");
Sleep(5000);
return 0;
}
|