This commit is contained in:
quenousimporte 2025-04-23 13:29:59 +01:00
parent eeb45106ee
commit 27ece09577
1 changed files with 17 additions and 22 deletions

39
w/w.c
View File

@ -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);
}
}
}