diff --git a/src/Circuit.java b/src/Circuit.java index de3cfd8..8f52aee 100644 --- a/src/Circuit.java +++ b/src/Circuit.java @@ -1,14 +1,55 @@ /** * Représente une cellule du circuit. *

- * Chaque cellule possède un type ({@link CircuitCell}) et éventuellement une valeur + * Chaque cellule possède un type ({@link Cell}) et éventuellement une valeur * numérique (par exemple pour indiquer une intensité, une vitesse, ou un identifiant de route). *

*/ public class Circuit { + /** + * Cell est un enum + * représentant les différents types de + * cases qui composent le circuit de + * course. + */ + public static enum Cell + { + /** + * Case hors piste, non + * praticable par les + * voitures. */ + EMPTY, + + /** + * Case de route normale + * sur laquelle les voitures + * peuvent circuler. + */ + ROAD, + + /** + * Case correspondant à la + * ligne de départ du circuit. + */ + START, + + /** + * Case correspondant à la + * ligne d'arrivée du circuit. + */ + FINISH, + + /** + * Case de route jaune, plus + * d'information sur le + * livrable 2 + */ + YROAD; + } + /** Type de la cellule (vide, route, départ, arrivée, etc.) */ - private final CircuitCell type; + private final Cell type; /** Valeur associée à la cellule (optionnelle, dépend du type) */ private int value; @@ -19,7 +60,7 @@ public class Circuit * * @param type le type de la cellule */ - public Circuit(CircuitCell type) + public Circuit(Cell type) { this.type = type; this.value = type.ordinal(); @@ -31,7 +72,7 @@ public class Circuit * @param type le type de la cellule * @param value la valeur associée à la cellule */ - public Circuit(CircuitCell type, int value) + public Circuit(Cell type, int value) { this.type = type; this.value = value; @@ -52,7 +93,7 @@ public class Circuit /** * @return le type de la cellule */ - public CircuitCell getType() + public Cell getType() { return type; } @@ -72,7 +113,7 @@ public class Circuit */ public boolean isRoad() { - return type == CircuitCell.ROAD || type == CircuitCell.YROAD; + return type == Cell.ROAD || type == Cell.YROAD; } /** @@ -82,7 +123,7 @@ public class Circuit */ public boolean isStart() { - return type == CircuitCell.START; + return type == Cell.START; } /** @@ -92,6 +133,6 @@ public class Circuit */ public boolean isFinish() { - return type == CircuitCell.FINISH; + return type == Cell.FINISH; } } \ No newline at end of file diff --git a/src/CircuitCell.java b/src/CircuitCell.java deleted file mode 100644 index cf4918f..0000000 --- a/src/CircuitCell.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * CircuitCell est un enum - * représentant les différents types de - * cases qui composent le circuit de - * course. - */ -public enum CircuitCell { - /** - * Case hors piste, non - * praticable par les - * voitures. */ - EMPTY, - - /** - * Case de route normale - * sur laquelle les voitures - * peuvent circuler. - */ - ROAD, - - /** - * Case correspondant à la - * ligne de départ du circuit. - */ - START, - - /** - * Case correspondant à la - * ligne d'arrivée du circuit. - */ - FINISH, - - /** - * Case de route jaune, plus - * d'information sur le - * livrable 2 - */ - YROAD; -} \ No newline at end of file diff --git a/src/Game.java b/src/Game.java index 64519e8..c5ef574 100644 --- a/src/Game.java +++ b/src/Game.java @@ -6,6 +6,8 @@ public class Game private Car[] cars; private Map map; + private ArrayList obs; + public static class Builder { private int pnumber = 3; @@ -57,8 +59,6 @@ public class Game } } - private ArrayList obs; - public Game(int pnumber, Map map, State state) { int loop = map.getPathSize(); @@ -71,6 +71,7 @@ public class Game { Car car = new Car(loop, state); cars[i] = car; + // Observer pour avancer obs.add(car); } diff --git a/src/Main.java b/src/Main.java index c95ad42..1b034ad 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,13 +1,13 @@ public class Main { public static void main(String[] args) throws InterruptedException { - Map m = Map.fromChars(new Character[][] { - {'3', '#', '2'}, - {'#', ' ', 'S'}, - {'9', '#', 'F'}, - }); + // Map m = Map.fromChars(new Character[][] { + // {'3', '#', '2'}, + // {'#', ' ', 'S'}, + // {'9', '#', 'F'}, + // }); Game game = new Game.Builder() - .setMap(m) + .defaultMap() .setPlayers(3) .build(); diff --git a/src/Map.java b/src/Map.java index c0a1411..fb0812f 100644 --- a/src/Map.java +++ b/src/Map.java @@ -6,7 +6,7 @@ import java.util.function.Function; *

Map représente le circuit de course.

*

Cette classe contient:

* */ @@ -65,11 +65,11 @@ public class Map public static Map fromInts(Integer[][] map) { return create((i) -> switch (i) { - case 0 -> new Circuit(CircuitCell.EMPTY); - case -1 -> new Circuit(CircuitCell.ROAD); - case -2 -> new Circuit(CircuitCell.START); - case -3 -> new Circuit(CircuitCell.FINISH); - default -> new Circuit(CircuitCell.YROAD, i); + case 0 -> new Circuit(Circuit.Cell.EMPTY); + case -1 -> new Circuit(Circuit.Cell.ROAD); + case -2 -> new Circuit(Circuit.Cell.START); + case -3 -> new Circuit(Circuit.Cell.FINISH); + default -> new Circuit(Circuit.Cell.YROAD, i); }, map); } @@ -89,12 +89,12 @@ public class Map public static Map fromChars(Character[][] map) { return create((i) -> switch (i) { - case '#' -> new Circuit(CircuitCell.ROAD); - case 'S' -> new Circuit(CircuitCell.START); - case 'F' -> new Circuit(CircuitCell.FINISH); + case '#' -> new Circuit(Circuit.Cell.ROAD); + case 'S' -> new Circuit(Circuit.Cell.START); + case 'F' -> new Circuit(Circuit.Cell.FINISH); case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' - -> new Circuit(CircuitCell.YROAD, i - '0'); - default -> new Circuit(CircuitCell.EMPTY); + -> new Circuit(Circuit.Cell.YROAD, i - '0'); + default -> new Circuit(Circuit.Cell.EMPTY); }, map); } @@ -152,11 +152,11 @@ public class Map { switch (map[i][j].getType()) { - case CircuitCell.START: + case Circuit.Cell.START: if (start == null) start = new Point(j, i); else return null; break; - case CircuitCell.FINISH: + case Circuit.Cell.FINISH: if (end == null) end = new Point(j, i); else return null; break; @@ -249,13 +249,13 @@ public class Map } /** - * Retourne le type de cellule (CircuitCell) à la position (x, y). + * Retourne le type de cellule (Circuit.Cell) à la position (x, y). * * @param x Coordonnée X * @param y Coordonnée Y - * @return Le type de cellule CircuitCell + * @return Le type de cellule Circuit.Cell */ - public CircuitCell getCell(int x, int y) + public Circuit.Cell getCell(int x, int y) { return getElement(x, y).getType(); }