Skip to content
Snippets Groups Projects
Commit 26c3bac0 authored by Sarah CHERCHEM's avatar Sarah CHERCHEM
Browse files

BoardFireFighterBehavior : modify the methodeUpdate

parent 9f1d562b
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ public class SimulatorApplication extends javafx.application.Application { ...@@ -20,6 +20,7 @@ public class SimulatorApplication extends javafx.application.Application {
public static final int INITIAL_FIRE_COUNT = 3; public static final int INITIAL_FIRE_COUNT = 3;
public static final int INITIAL_FIREFIGHTER_COUNT = 0; public static final int INITIAL_FIREFIGHTER_COUNT = 0;
public static final int INITIAL_CLOUD_COUNT = 3; public static final int INITIAL_CLOUD_COUNT = 3;
public static final int INITIAL_MOTORIZED_COUNT = 3;
private Stage primaryStage; private Stage primaryStage;
private Parent view; private Parent view;
...@@ -45,7 +46,7 @@ public class SimulatorApplication extends javafx.application.Application { ...@@ -45,7 +46,7 @@ public class SimulatorApplication extends javafx.application.Application {
view = loader.load(); view = loader.load();
Controller controller = loader.getController(); Controller controller = loader.getController();
controller.initialize(BOX_WIDTH, BOX_HEIGHT, COLUMN_COUNT, ROW_COUNT, controller.initialize(BOX_WIDTH, BOX_HEIGHT, COLUMN_COUNT, ROW_COUNT,
INITIAL_FIRE_COUNT, INITIAL_FIREFIGHTER_COUNT,INITIAL_CLOUD_COUNT); INITIAL_FIRE_COUNT, INITIAL_FIREFIGHTER_COUNT,INITIAL_CLOUD_COUNT,INITIAL_MOTORIZED_COUNT);
} }
private void showScene() { private void showScene() {
......
...@@ -128,9 +128,9 @@ public class Controller { ...@@ -128,9 +128,9 @@ public class Controller {
} }
public void initialize(int squareWidth, int squareHeight, int columnCount, public void initialize(int squareWidth, int squareHeight, int columnCount,
int rowCount, int initialFireCount, int initialFirefighterCount,int initialCloud) { int rowCount, int initialFireCount, int initialFirefighterCount,int initialCloud,int initialMotorized) {
grid.setDimensions(columnCount, rowCount, squareWidth, squareHeight); grid.setDimensions(columnCount, rowCount, squareWidth, squareHeight);
this.setModel(new FirefighterBoard(columnCount, rowCount, initialFireCount, initialFirefighterCount,initialCloud)); this.setModel(new FirefighterBoard(columnCount, rowCount, initialFireCount, initialFirefighterCount,initialCloud,initialMotorized));
repaintGrid(); repaintGrid();
} }
......
...@@ -9,19 +9,23 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -9,19 +9,23 @@ public class BoardFireFighterBehavior implements BoardBehavior{
private final TargetStrategy targetStrategy = new TargetStrategy(); private final TargetStrategy targetStrategy = new TargetStrategy();
private final Map<Position, List<Position>> neighbors; private final Map<Position, List<Position>> neighbors;
private List<Position> firefighterPositions; private List<Position> firefighterPositions;
private List<Position> motorizedFighters;
private Set<Position> firePositions; private Set<Position> firePositions;
private final ElementFactory<FireFighter> firefighterFactory; private final ElementFactory<FireFighter> firefighterFactory;
private final ElementFactory<Fire> fireFactory; private final ElementFactory<Fire> fireFactory;
private final ElementFactory<Cloud> cloudFactory; private final ElementFactory<Cloud> cloudFactory;
private final ElementFactory<MotorizedFireFighter> motorizedFactory;
private List<Position> cloudPositions; private List<Position> cloudPositions;
private int step; private int step;
public BoardFireFighterBehavior(Map<Position, List<Position>> neighbors, ElementFactory<Fire> fireFactory ,ElementFactory<FireFighter> firefighterFactory,ElementFactory<Cloud> cloudFactory) { public BoardFireFighterBehavior(Map<Position, List<Position>> neighbors, ElementFactory<Fire> fireFactory ,ElementFactory<FireFighter> firefighterFactory,
ElementFactory<Cloud> cloudFactory,ElementFactory<MotorizedFireFighter> motorizedFactory) {
this.step=0; this.step=0;
this.neighbors = neighbors; this.neighbors = neighbors;
this.firefighterFactory = firefighterFactory; this.firefighterFactory = firefighterFactory;
this.fireFactory = fireFactory; this.fireFactory = fireFactory;
this.cloudFactory=cloudFactory; this.cloudFactory=cloudFactory;
this.motorizedFactory=motorizedFactory;
} }
public void initializeElements(int rowCount, int columnCount) { public void initializeElements(int rowCount, int columnCount) {
...@@ -81,6 +85,33 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -81,6 +85,33 @@ public class BoardFireFighterBehavior implements BoardBehavior{
firefighterPositions = newFirefighterPositions; firefighterPositions = newFirefighterPositions;
return modifiedPositions; return modifiedPositions;
} }
public List<Position> updateMotorized() {
List<Position> modifiedPositions = new ArrayList<>();
List<Position> newMotorizedPositions = new ArrayList<>();
// Déplace chaque pompier motorisé et éteint les feux à proximité
for (Position motorizedPosition : motorizedFighters) {
// Crée une instance temporaire de MotorizedFireFighter
MotorizedFireFighter motorizedFirefighter = new MotorizedFireFighter(motorizedPosition);
// Déplace le pompier
Position newPosition = motorizedFirefighter.move(firePositions, neighbors);
// Éteindre les feux à la nouvelle position
extinguishFire(firePositions, newPosition, modifiedPositions);
// Mettre à jour les positions
newMotorizedPositions.add(newPosition);
modifiedPositions.add(motorizedPosition); // Ancienne position
modifiedPositions.add(newPosition); // Nouvelle position
}
// Met à jour la liste des positions des pompiers motorisés
motorizedFighters = newMotorizedPositions;
return modifiedPositions;
}
private void extinguish(Position position) { private void extinguish(Position position) {
firePositions.remove(position); firePositions.remove(position);
......
...@@ -11,12 +11,12 @@ public class FirefighterBoard implements Board<List<ModelElement>> { ...@@ -11,12 +11,12 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
private final Random randomGenerator = new Random(); private final Random randomGenerator = new Random();
public FirefighterBoard(int columnCount, int rowCount, int initialFireCount, int initialFirefighterCount,int initialCloud) { public FirefighterBoard(int columnCount, int rowCount, int initialFireCount, int initialFirefighterCount,int initialCloud,int initialMotorized) {
Map<Position, List<Position>> neighbors = initializeNeighbors(rowCount, columnCount); Map<Position, List<Position>> neighbors = initializeNeighbors(rowCount, columnCount);
this.properties = new BoardFirefighterProperties(rowCount, columnCount); this.properties = new BoardFirefighterProperties(rowCount, columnCount);
this.behavior = new BoardFireFighterBehavior(neighbors,new FireFactory(randomGenerator,initialFireCount),new FirefighterFactory(randomGenerator,initialFirefighterCount), this.behavior = new BoardFireFighterBehavior(neighbors,new FireFactory(randomGenerator,initialFireCount),new FirefighterFactory(randomGenerator,initialFirefighterCount),
new CloudFactory(randomGenerator,initialCloud)); new CloudFactory(randomGenerator,initialCloud),new MotorizedFactory(randomGenerator,initialMotorized));
behavior.initializeElements( properties.rowCount(), properties.columnCount()); behavior.initializeElements( properties.rowCount(), properties.columnCount());
} }
......
...@@ -13,18 +13,26 @@ public class MotorizedFireFighter extends FireFighter{ ...@@ -13,18 +13,26 @@ public class MotorizedFireFighter extends FireFighter{
public Position move(List<Position> positions,Map<Position, List<Position>> neighbors, Set<Position> firePositions) { /**
List<Position> modifiedPositions = new ArrayList<>(); * Déplace le pompier motorisé en deux étapes maximum vers un feu.
List<Position> newPositions = new ArrayList<>(); *
Position finalPosition=null; * @param firePositions Les positions des feux.
for (Position firefighterPosition : positions) { * @param neighbors Les positions voisines accessibles.
// Déplacement motorisé (deux cases maximum) * @return La nouvelle position du pompier.
Position firstStep = targetStrategy.neighborClosestToTarget(firefighterPosition, firePositions, neighbors); */
Position secondStep = targetStrategy.neighborClosestToTarget(firstStep, firePositions, neighbors); public Position move(Set<Position> firePositions, Map<Position, List<Position>> neighbors) {
finalPosition = secondStep != null ? secondStep : firstStep; // Première étape
Position firstStep = targetStrategy.neighborClosestToTarget(getPosition(), firePositions, neighbors);
if (firstStep == null) {
return getPosition(); // Pas de mouvement possible
} }
return finalPosition; // Deuxième étape
Position secondStep = targetStrategy.neighborClosestToTarget(firstStep, firePositions, neighbors);
Position newPosition = secondStep != null ? secondStep : firstStep;
// Mise à jour de la position
setPosition(newPosition);
return newPosition;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment