diff --git a/src/Map.java b/src/Map.java index 74004ba..08e1bdc 100644 --- a/src/Map.java +++ b/src/Map.java @@ -2,11 +2,35 @@ import java.awt.Point; import java.util.ArrayList; import java.util.function.Function; +/** + *
Map représente le circuit de course.
Cette classe contient:
+ *START et FINISHCircuit.
+ */
private Circuit[][] map;
+ /**
+ * Liste des coordonnées représentant le chemin du START au FINISH.
+ */
private ArrayListMap
+ */
public static Map
+ */
public static Map fromInts(Integer[][] map)
{
return create((i) -> switch (i) {
@@ -36,6 +73,19 @@ public class Map
}, map);
}
+ /**
+ * Crée une map à partir d'un tableau de caractères.
+ * Map
+ */
public static Map fromChars(Character[][] map)
{
return create((i) -> switch (i) {
@@ -48,6 +98,13 @@ public class Map
}, map);
}
+ /**
+ * Constructeur privé utilisé par les méthodes statiques de création.
+ * Initialise la map et construit le chemin.
+ * Si la map est invalide ou impossible à résoudre, termine le programme.
+ *
+ * @param map Tableau 2D de Circuit
+ */
private Map(Circuit[][] map)
{
this.map = map;
@@ -59,7 +116,12 @@ public class Map
System.exit(1);
}
}
-
+
+ /**
+ * Construit le chemin entre START et FINISH.
+ *
+ * @return true si un chemin valide existe, false sinon
+ */
private boolean buildPath()
{
Point[] p = bindPath();
@@ -74,6 +136,11 @@ public class Map
return followPath(start, end);
}
+ /**
+ * Cherche les points START et FINISH sur la map.
+ *
+ * @return Un tableau de 2 éléments : {START, FINISH} ou null si la map est invalide
+ */
private Point[] bindPath()
{
Point start = null;
@@ -102,6 +169,14 @@ public class Map
return new Point[] {start, end};
}
+ /**
+ * Suivi du chemin depuis START jusqu'à FINISH.
+ * Parcours les cases ROAD et YROAD jusqu'à atteindre FINISH.
+ *
+ * @param start Point de départ
+ * @param end Point d'arrivée
+ * @return true si un chemin complet a été trouvé, false sinon
+ */
private boolean followPath(Point start, Point end)
{
// remettre à 0 la liste
@@ -161,11 +236,46 @@ public class Map
return false;
}
- public CircuitCell getElement(int x, int y)
+ /**
+ * Retourne l'objet Circuit à la position (x, y).
+ *
+ * @param x Coordonnée X
+ * @param y Coordonnée Y
+ * @return L'objet Circuit
+ */
+ public Circuit getElement(int x, int y)
{
- return map[y][x].getType();
+ return map[y][x];
}
+ /**
+ * Retourne le type de cellule (CircuitCell) à la position (x, y).
+ *
+ * @param x Coordonnée X
+ * @param y Coordonnée Y
+ * @return Le type de cellule CircuitCell
+ */
+ public CircuitCell getCell(int x, int y)
+ {
+ return getElement(x, y).getType();
+ }
+
+ /**
+ * Retourne le point du chemin à l'indice donné.
+ *
+ * @param index Indice dans le chemin
+ * @return Point correspondant
+ */
+ public Point getPath(int i)
+ {
+ return this.pathMap.get(i);
+ }
+
+ /**
+ * Retourne la taille du chemin trouvé.
+ *
+ * @return Nombre de points dans le chemin
+ */
public int getPathSize()
{
return this.pathMap.size();