/// 迷宫笑脸走一发
#include <stdlib.h>
#include <stdio.h>
#include "fun.h"
char szMaze[][15]={
"111111111111111",
"101111010011011",
"101000000000011",
"101011101101011",
"101000101101011",
"100000100101@11",
"111111111111111",
};
void showMaze();
int Maze(int x, int y)
{
system("cls");
showMaze();
system("pause");
if(szMaze[x][y]=='@')
{
exit(0);
return 0;
}
szMaze[x][y] ='\1';
if(szMaze[x][y+1]=='0'||szMaze[x][y+1]=='@')
{
Maze(x,y+1);
}
if(szMaze[x-1][y]=='0'||szMaze[x-1][y]=='@')
{
Maze(x-1,y);
}
if(szMaze[x][y-1]=='0'||szMaze[x][y-1]=='@')
{
Maze(x,y-1);
}
if(szMaze[x+1][y]=='0'||szMaze[x+1][y]=='@')
{
Maze(x+1,y);
}
szMaze[x][y] ='\2';
system("cls");
showMaze();
system("pause");
return 0;
}
void showMaze()
{
int iRowMax = sizeof(szMaze) / 15;
int iRow = 0;
int iCol = 0;
for (iRow = 0; iRow < iRowMax; iRow++)
{
for (iCol = 0; iCol < 15; iCol++)
{
printf("%c", szMaze[iRow][iCol]);
}
printf("\n");
}
}
int main()
{
Maze(1,1);
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include "fun.h"
char szMaze[][15]={
"111111111111111",
"101111010011011",
"101000000000011",
"101011101101011",
"101000101101011",
"100000100101@11",
"111111111111111",
};
void showMaze();
int Maze(int x, int y)
{
system("cls");
showMaze();
system("pause");
if(szMaze[x][y]=='@')
{
exit(0);
return 0;
}
szMaze[x][y] ='\1';
if(szMaze[x][y+1]=='0'||szMaze[x][y+1]=='@')
{
Maze(x,y+1);
}
if(szMaze[x-1][y]=='0'||szMaze[x-1][y]=='@')
{
Maze(x-1,y);
}
if(szMaze[x][y-1]=='0'||szMaze[x][y-1]=='@')
{
Maze(x,y-1);
}
if(szMaze[x+1][y]=='0'||szMaze[x+1][y]=='@')
{
Maze(x+1,y);
}
szMaze[x][y] ='\2';
system("cls");
showMaze();
system("pause");
return 0;
}
void showMaze()
{
int iRowMax = sizeof(szMaze) / 15;
int iRow = 0;
int iCol = 0;
for (iRow = 0; iRow < iRowMax; iRow++)
{
for (iCol = 0; iCol < 15; iCol++)
{
printf("%c", szMaze[iRow][iCol]);
}
printf("\n");
}
}
int main()
{
Maze(1,1);
return 0;
}