资 源 简 介
资源描述void creatWay(int (*mg)[N],int x, int y)//在迷宫中产生一条路,使用图的深度遍历思想来实现,
{
static int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};////将要走的4个方向保存在二维数组中
int zx = x*2;
int zy = y*2;
int next, turn, i;
mg[zx][zy] = 0;
if(rand()%2)
turn = 1;
else
turn = 3;
for(i=0,next=rand()%4;i<4;i++,next=(next+turn)%4)
if(mg[zx+2*dir[next][0]][zy+2*dir[next][1]] == 1)
{
mg[zx+dir[next][0]][zy+dir[next][1]] = 0;
creatWay(mg,x+dir[next][0], y+dir[next][1]);
}
}
void CreatMaze(int (*mg)[N],int x)//创建一个边长是2*x+3的迷宫,并设置好墙和路。
{
int r,c;
for(r=0; r<=x*2+2; ++r)
for(c=0; c<=x*2+2; ++c)
mg[r][c] = 1;
for(r=0, c=2*x+2; r<=2*x+2; ++r)
{
mg[r][0] = 0;
mg[r][c] = 0;
}
for(r=0, c=2*x+2; r<=2*x+2; ++r)
{
mg[0][r] = 0;
mg[c][r] = 0;
}
mg[1][2] = 6;
mg[