#include <stdio.h>
#include <cstdio>
#include <conio.h>
#include <windows.h>
char a[50][50]={"################",
"#0 #",
"############## #",
"# #",
"# ##############",
"# ",
"################",};//5,15
void welcome()
{
printf(" 走迷宫\n");
printf(" 按任意键继续 ");
getch();
system("cls");
}
int main()
{
int x=1,y=1;
char ch;
for(int i=0;i<=7;i++)
puts(a[i]);
while(1)
{
ch=getch();
if(ch=='d')
{
if(a[y][x+1]==' ')
{
a[y][x]=' ';
x++;
a[y][x]='0';
}
}
if(ch=='s')
{
if(a[y+1][x]==' ')
{
a[y][x]=' ';
y++;
a[y][x]='0';
}
}
if(ch=='a')
{
if(a[y][x-1]==' ')
{
a[y][x]=' ';
x--;
a[y][x]='0';
}
}
if(ch=='w')
{
if(a[y-1][x]==' ')
{
a[y][x]=' ';
y--;
a[y][x]='0';
}
}
system("cls");
for(int i=0;i<=7;i++)
puts(a[i]);
if(y==5 && x==15)
break;
}
printf("win\n\n\n\n\n");
return 0;
}
走迷宫源代码
最新推荐文章于 2023-10-16 17:14:16 发布