mirror of
https://github.com/guezoloic/racing-game.git
synced 2026-03-28 18:03:50 +00:00
feat: fusion Circuit et CircuitCell
This commit is contained in:
@@ -1,14 +1,55 @@
|
||||
/**
|
||||
* Représente une cellule du circuit.
|
||||
* <p>
|
||||
* 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).
|
||||
* </p>
|
||||
*/
|
||||
public class Circuit
|
||||
{
|
||||
/**
|
||||
* <code>Cell</code> 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;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* <code>CircuitCell</code> 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;
|
||||
}
|
||||
@@ -6,6 +6,8 @@ public class Game
|
||||
private Car[] cars;
|
||||
private Map map;
|
||||
|
||||
private ArrayList<GObserver> obs;
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private int pnumber = 3;
|
||||
@@ -57,8 +59,6 @@ public class Game
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<GObserver> 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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
32
src/Map.java
32
src/Map.java
@@ -6,7 +6,7 @@ import java.util.function.Function;
|
||||
* <p> <code>Map</code> représente le circuit de course.</p>
|
||||
* <p>Cette classe contient: </p>
|
||||
* <ul>
|
||||
* <li>Un tableau 2D de CircuitCell</li>
|
||||
* <li>Un tableau 2D de Circuit.Cell</li>
|
||||
* <li>Une liste de Points qui représente le chemin pour la voiture entre <code>START</code> et <code>FINISH</code></li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -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 <code>CircuitCell</code>
|
||||
* @return Le type de cellule <code>Circuit.Cell</code>
|
||||
*/
|
||||
public CircuitCell getCell(int x, int y)
|
||||
public Circuit.Cell getCell(int x, int y)
|
||||
{
|
||||
return getElement(x, y).getType();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user