fix(Map.java): modif des fonc bind, follow et build path

- `bindPath`: `Point(i, j)` -> `Point(j, i)`
- `buildPath`: init ArrayList
- `followPath`: ajout current == ROAD ET next == FINISH
This commit is contained in:
2025-10-29 16:00:21 +01:00
parent df30cd0716
commit 072b37ece7

View File

@@ -9,7 +9,13 @@ public class Map
public Map(Circuit[][] map)
{
this.map = map;
this.buildPath();
boolean isPossible = this.buildPath();
if (!isPossible)
{
System.err.println("La map contient des doublons ou est impossible à finir!");
System.exit(1);
}
}
private boolean buildPath()
@@ -20,8 +26,9 @@ public class Map
return false;
Point start = p[0];
Point end = p[0];
Point end = p[1];
this.pathMap = new ArrayList<>();
return followPath(start, end);
}
@@ -37,11 +44,11 @@ public class Map
switch (map[i][j].getType())
{
case CircuitCell.START:
if (start == null) start = new Point(i, j);
if (start == null) start = new Point(j, i);
else return null;
break;
case CircuitCell.FINISH:
if (end == null) end = new Point(i, j);
if (end == null) end = new Point(j, i);
else return null;
break;
default:
@@ -49,7 +56,7 @@ public class Map
}
}
}
if (start == null || end == null) return null;
return new Point[] {start, end};
}
@@ -86,7 +93,7 @@ public class Map
int x = current.x + pos[0];
int y = current.y + pos[1];
if ((x >= 0 || map[0].length > x) || (y >= 0 || map.length > y))
if ((x >= 0 && map[0].length > x) && (y >= 0 && map.length > y))
{
Point next = new Point(x, y);
@@ -94,8 +101,8 @@ public class Map
continue;
CircuitCell type = map[y][x].getType();
if (type == CircuitCell.FINISH || type == CircuitCell.ROAD
|| type == CircuitCell.YROAD)
if ((type == CircuitCell.ROAD || type == CircuitCell.YROAD) ||
(type == CircuitCell.FINISH && map[current.y][current.x] == CircuitCell.ROAD))
{
previous = current;
current = next;
@@ -104,6 +111,7 @@ public class Map
}
}
}
// Si il est bloqué
if (!moved) break;
}