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