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);
|
||||
}
|
||||
|
||||
int directions[4] = { NORTH, EAST, SOUTH, WEST };
|
||||
// Shuffle the directions array
|
||||
int directions[4] = { NORTH, EAST, SOUTH, WEST };
|
||||
for (int i = 3; i > 0; i--)
|
||||
{
|
||||
int j = rand() % (i + 1);
|
||||
|
@ -450,40 +450,35 @@ void dfs(int x, int y)
|
|||
directions[j] = temp;
|
||||
}
|
||||
|
||||
// todo refactor
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Position close = { x, y, 0 };
|
||||
Position far = { x, y, 0 };
|
||||
switch (directions[i])
|
||||
{
|
||||
case NORTH:
|
||||
if (charatpos(x, y - 2) == TILE_INIT)
|
||||
{
|
||||
setatpos(x, y - 1, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
||||
dfs(x, y - 2);
|
||||
}
|
||||
close.y -= 1;
|
||||
far.y -= 2;
|
||||
break;
|
||||
case SOUTH:
|
||||
if (charatpos(x, y + 2) == TILE_INIT)
|
||||
{
|
||||
setatpos(x, y + 1, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
||||
dfs(x, y + 2);
|
||||
}
|
||||
close.y += 1;
|
||||
far.y += 2;
|
||||
break;
|
||||
case EAST:
|
||||
if (charatpos(x - 2, y) == TILE_INIT)
|
||||
{
|
||||
setatpos(x - 1, y, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
||||
dfs(x - 2, y);
|
||||
}
|
||||
close.x -= 1;
|
||||
far.x -= 2;
|
||||
break;
|
||||
case WEST:
|
||||
if (charatpos(x + 2, y) == TILE_INIT)
|
||||
{
|
||||
setatpos(x + 1, y, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
||||
dfs(x + 2, y);
|
||||
}
|
||||
close.x += 1;
|
||||
far.x += 2;
|
||||
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