|
|
@ -263,3 +263,53 @@ void chu()
|
|
|
|
map[i][j]=2;
|
|
|
|
map[i][j]=2;
|
|
|
|
make(i,j);
|
|
|
|
make(i,j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//得到方位且可判断是否有有效邻居(可挖掘的)
|
|
|
|
|
|
|
|
char des(int x1,int y1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char a[5];
|
|
|
|
|
|
|
|
int k=0;
|
|
|
|
|
|
|
|
if(x1>1&&map[x1-2][y1]==1) a[k++]='w';
|
|
|
|
|
|
|
|
if(x1<n-2&&map[x1+2][y1]==1) a[k++]='s';
|
|
|
|
|
|
|
|
if(y1>1&&map[x1][y1-2]==1) a[k++]='a';
|
|
|
|
|
|
|
|
if(y1<m-2&&map[x1][y1+2]==1) a[k++]='d';
|
|
|
|
|
|
|
|
if(k==0) return 'e';
|
|
|
|
|
|
|
|
return a[rand()%k];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//根据方向挖掘道路
|
|
|
|
|
|
|
|
void dig(char d,int x2,int y2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch(d){
|
|
|
|
|
|
|
|
case 'w':map[x2-1][y2]=2;map[x2-2][y2]=2;break;
|
|
|
|
|
|
|
|
case 's':map[x2+1][y2]=2;map[x2+2][y2]=2;break;
|
|
|
|
|
|
|
|
case 'a':map[x2][y2-1]=2;map[x2][y2-2]=2;break;
|
|
|
|
|
|
|
|
case 'd':map[x2][y2+1]=2;map[x2][y2+2]=2;break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//生成地图的递归
|
|
|
|
|
|
|
|
void make(int x3,int y3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char d;
|
|
|
|
|
|
|
|
while(des(x3,y3)!='e'){
|
|
|
|
|
|
|
|
d=des(x3,y3);
|
|
|
|
|
|
|
|
dig(d,x3,y3);
|
|
|
|
|
|
|
|
switch(d){
|
|
|
|
|
|
|
|
case 'w':make(x3-2,y3);break;
|
|
|
|
|
|
|
|
case 's':make(x3+2,y3);break;
|
|
|
|
|
|
|
|
case 'a':make(x3,y3-2);break;
|
|
|
|
|
|
|
|
case 'd':make(x3,y3+2);break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//生产地图的主要函数
|
|
|
|
|
|
|
|
void CreateMaze()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i,j;
|
|
|
|
|
|
|
|
srand(time(NULL));
|
|
|
|
|
|
|
|
chu();
|
|
|
|
|
|
|
|
for(i=0;i<n;i++)for(j=0;j<m;j++){
|
|
|
|
|
|
|
|
if(i==0||j==0||i==n-1||j==m-1) map[i][j]=Wall;
|
|
|
|
|
|
|
|
if(map[i][j]==2) map[i][j]=Road;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
map[1][1]=Player;
|
|
|
|
|
|
|
|
map[n-2][m-2]=Des;
|
|
|
|
|
|
|
|
}
|