refactor
This commit is contained in:
parent
eeb45106ee
commit
27ece09577
39
w/w.c
39
w/w.c
|
@ -440,8 +440,8 @@ void dfs(int x, int y)
|
||||||
setatpos(x, y, TILE_ROOM);
|
setatpos(x, y, TILE_ROOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
int directions[4] = { NORTH, EAST, SOUTH, WEST };
|
|
||||||
// Shuffle the directions array
|
// Shuffle the directions array
|
||||||
|
int directions[4] = { NORTH, EAST, SOUTH, WEST };
|
||||||
for (int i = 3; i > 0; i--)
|
for (int i = 3; i > 0; i--)
|
||||||
{
|
{
|
||||||
int j = rand() % (i + 1);
|
int j = rand() % (i + 1);
|
||||||
|
@ -450,40 +450,35 @@ void dfs(int x, int y)
|
||||||
directions[j] = temp;
|
directions[j] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo refactor
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
|
Position close = { x, y, 0 };
|
||||||
|
Position far = { x, y, 0 };
|
||||||
switch (directions[i])
|
switch (directions[i])
|
||||||
{
|
{
|
||||||
case NORTH:
|
case NORTH:
|
||||||
if (charatpos(x, y - 2) == TILE_INIT)
|
close.y -= 1;
|
||||||
{
|
far.y -= 2;
|
||||||
setatpos(x, y - 1, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
|
||||||
dfs(x, y - 2);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SOUTH:
|
case SOUTH:
|
||||||
if (charatpos(x, y + 2) == TILE_INIT)
|
close.y += 1;
|
||||||
{
|
far.y += 2;
|
||||||
setatpos(x, y + 1, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
|
||||||
dfs(x, y + 2);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case EAST:
|
case EAST:
|
||||||
if (charatpos(x - 2, y) == TILE_INIT)
|
close.x -= 1;
|
||||||
{
|
far.x -= 2;
|
||||||
setatpos(x - 1, y, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
|
||||||
dfs(x - 2, y);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case WEST:
|
case WEST:
|
||||||
if (charatpos(x + 2, y) == TILE_INIT)
|
close.x += 1;
|
||||||
{
|
far.x += 2;
|
||||||
setatpos(x + 1, y, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
|
||||||
dfs(x + 2, y);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (charatpos(far.x, far.y) == TILE_INIT)
|
||||||
|
{
|
||||||
|
setatpos(close.x, close.y, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
||||||
|
dfs(far.x, far.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue