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

Display the rocky in the grid

parent 703e9184
No related branches found
No related tags found
No related merge requests found
Pipeline #41551 passed
Showing
with 89 additions and 15 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -21,6 +21,7 @@ public class SimulatorApplication extends javafx.application.Application { ...@@ -21,6 +21,7 @@ public class SimulatorApplication extends javafx.application.Application {
public static final int INITIAL_FIREFIGHTER_COUNT = 3; public static final int INITIAL_FIREFIGHTER_COUNT = 3;
public static final int INITIAL_CLOUD_COUNT = 3; public static final int INITIAL_CLOUD_COUNT = 3;
public static final int INITIAL_MOTORIZED_COUNT = 3; public static final int INITIAL_MOTORIZED_COUNT = 3;
public static final int INITIAL_ROCKY_COUNT = 3;
private Stage primaryStage; private Stage primaryStage;
private Parent view; private Parent view;
...@@ -46,7 +47,7 @@ public class SimulatorApplication extends javafx.application.Application { ...@@ -46,7 +47,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_MOTORIZED_COUNT); INITIAL_FIRE_COUNT, INITIAL_FIREFIGHTER_COUNT,INITIAL_CLOUD_COUNT,INITIAL_MOTORIZED_COUNT,INITIAL_ROCKY_COUNT);
} }
private void showScene() { private void showScene() {
......
...@@ -101,6 +101,10 @@ public class Controller { ...@@ -101,6 +101,10 @@ public class Controller {
{ {
return ViewElement.ROAD; return ViewElement.ROAD;
} }
if (element instanceof Rocky)
{
return ViewElement.ROCKY;
}
} }
return ViewElement.EMPTY; return ViewElement.EMPTY;
...@@ -140,9 +144,9 @@ public class Controller { ...@@ -140,9 +144,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 initialMotorized) { int rowCount, int initialFireCount, int initialFirefighterCount,int initialCloud,int initialMotorized,int initialRocky) {
grid.setDimensions(columnCount, rowCount, squareWidth, squareHeight); grid.setDimensions(columnCount, rowCount, squareWidth, squareHeight);
this.setModel(new FirefighterBoard(columnCount, rowCount, initialFireCount, initialFirefighterCount,initialCloud,initialMotorized)); this.setModel(new FirefighterBoard(columnCount, rowCount, initialFireCount, initialFirefighterCount,initialCloud,initialMotorized,initialRocky));
repaintGrid(); repaintGrid();
} }
......
...@@ -10,23 +10,26 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -10,23 +10,26 @@ public class BoardFireFighterBehavior implements BoardBehavior{
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 List<Position> motorizedFighters;
private List<Position> rocky;
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 final ElementFactory<MotorizedFireFighter> motorizedFactory;
private ElementFactory<Rocky> rockyFactory;
private List<Position> cloudPositions; private List<Position> cloudPositions;
private final Map<Position, Terrain> terrainMap = new HashMap<>(); private final Map<Position, Terrain> terrainMap = new HashMap<>();
private int step; private int step;
public BoardFireFighterBehavior(Map<Position, List<Position>> neighbors, ElementFactory<Fire> fireFactory ,ElementFactory<FireFighter> firefighterFactory, public BoardFireFighterBehavior(Map<Position, List<Position>> neighbors, ElementFactory<Fire> fireFactory ,ElementFactory<FireFighter> firefighterFactory,
ElementFactory<Cloud> cloudFactory,ElementFactory<MotorizedFireFighter> motorizedFactory) { ElementFactory<Cloud> cloudFactory,ElementFactory<MotorizedFireFighter> motorizedFactory,ElementFactory<Rocky> rockyFactory) {
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; this.motorizedFactory=motorizedFactory;
this.rockyFactory=rockyFactory;
} }
public void initializeElements(int rowCount, int columnCount) { public void initializeElements(int rowCount, int columnCount) {
...@@ -44,6 +47,7 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -44,6 +47,7 @@ public class BoardFireFighterBehavior implements BoardBehavior{
firefighterPositions.add(firefighter.getPosition()); firefighterPositions.add(firefighter.getPosition());
} }
// Nuages // Nuages
cloudPositions = new ArrayList<>(); cloudPositions = new ArrayList<>();
List<Cloud> clouds = cloudFactory.createElements(rowCount, columnCount); List<Cloud> clouds = cloudFactory.createElements(rowCount, columnCount);
...@@ -56,6 +60,13 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -56,6 +60,13 @@ public class BoardFireFighterBehavior implements BoardBehavior{
for (MotorizedFireFighter motorizedFirefighter : motorizedFirefighters) { for (MotorizedFireFighter motorizedFirefighter : motorizedFirefighters) {
motorizedFighters.add(motorizedFirefighter.getPosition()); motorizedFighters.add(motorizedFirefighter.getPosition());
} }
// Rocky
rocky = new ArrayList<>();
List<Rocky> rockies = rockyFactory.createElements(rowCount, columnCount);
for (Rocky rockyElement : rockies) {
rocky.add(rockyElement.getPosition());
}
generateMountainBlocks(rowCount, columnCount); generateMountainBlocks(rowCount, columnCount);
generateRoads(rowCount,columnCount); generateRoads(rowCount,columnCount);
...@@ -330,6 +341,10 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -330,6 +341,10 @@ public class BoardFireFighterBehavior implements BoardBehavior{
if (terrainMap.get(position) != null && !cloudPositions.contains(position)) { if (terrainMap.get(position) != null && !cloudPositions.contains(position)) {
return false; // Impossible de franchir une montagne, sauf pour un nuage return false; // Impossible de franchir une montagne, sauf pour un nuage
} }
if(rocky.contains(position))
{
return Rocky.canFirePropagate();
}
return true; // La position est traversable return true; // La position est traversable
} }
...@@ -374,9 +389,7 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -374,9 +389,7 @@ public class BoardFireFighterBehavior implements BoardBehavior{
} }
} }
public List<Position> getRocky() {
return rocky;
}
} }
...@@ -11,12 +11,13 @@ public class FirefighterBoard implements Board<List<ModelElement>> { ...@@ -11,12 +11,13 @@ 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,int initialMotorized) { public FirefighterBoard(int columnCount, int rowCount, int initialFireCount, int initialFirefighterCount,int initialCloud,int initialMotorized,
int initialRocky) {
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 MotorizedFactory(randomGenerator,initialMotorized)); new CloudFactory(randomGenerator,initialCloud),new MotorizedFactory(randomGenerator,initialMotorized),new RockyFactory(randomGenerator,initialRocky));
behavior.initializeElements( properties.rowCount(), properties.columnCount()); behavior.initializeElements( properties.rowCount(), properties.columnCount());
} }
...@@ -74,6 +75,10 @@ public class FirefighterBoard implements Board<List<ModelElement>> { ...@@ -74,6 +75,10 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
result.add((Road) value); // Ajouter uniquement un objet Mountain result.add((Road) value); // Ajouter uniquement un objet Mountain
} }
}); });
// Filtrage des éléments Rocky
behavior.getRocky().stream()
.filter(pos -> pos.isAtPosition(position))
.forEach(pos -> result.add(new Rocky(pos)));
return result; return result;
} }
...@@ -97,7 +102,9 @@ public class FirefighterBoard implements Board<List<ModelElement>> { ...@@ -97,7 +102,9 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
behavior.getCloudPositions().add(position); behavior.getCloudPositions().add(position);
} else if (element instanceof MotorizedFireFighter) { } else if (element instanceof MotorizedFireFighter) {
behavior.getMotorizedFighters().add(position); behavior.getMotorizedFighters().add(position);
}else if(element instanceof Rocky)
{
behavior.getRocky().add(position);
} }
} }
......
...@@ -3,10 +3,19 @@ package model; ...@@ -3,10 +3,19 @@ package model;
import util.Position; import util.Position;
public class Rocky extends BoardElement{ public class Rocky extends BoardElement{
private final int fireDelay=4; private static int firePropagationCounter;
public Rocky(Position position) { public Rocky(Position position) {
super(position); super(position);
} }
public static boolean canFirePropagate() {
// Le feu ne peut se propager que tous les 4 tours
if (firePropagationCounter >= 4) {
firePropagationCounter = 0; // Reset le compteur
return true;
}
firePropagationCounter++;
return false;
}
@Override @Override
public String getType() { public String getType() {
...@@ -17,4 +26,8 @@ public class Rocky extends BoardElement{ ...@@ -17,4 +26,8 @@ public class Rocky extends BoardElement{
public String toString() { public String toString() {
return null; return null;
} }
public static int getFirePropagationCounter() {
return firePropagationCounter;
}
} }
package model; package model;
public class RockyFactory { import util.Position;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class RockyFactory implements ElementFactory<Rocky>,PositionGenerator{
private final Random random;
private int count;
public RockyFactory(Random random, int count) {
this.random = random;
this.count = count;
}
@Override
public List<Rocky> createElements(int rowCount, int columnCount) {
List<Rocky> rocky = new ArrayList<>();
for (int i = 0; i < count; i++) {
Position randomPosition = generateRandomPosition(rowCount, columnCount);
rocky.add(new Rocky(randomPosition));
}
return rocky;
}
@Override
public int getCount() {
return count;
}
@Override
public Position generateRandomPosition(int rowCount, int columnCount) {
int row = random.nextInt(rowCount);
int column = random.nextInt(columnCount);
return new Position(row, column);
}
} }
...@@ -3,7 +3,7 @@ package view; ...@@ -3,7 +3,7 @@ package view;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
public enum ViewElement { public enum ViewElement {
FIREFIGHTER(Color.BLUE), FIRE(Color.RED), EMPTY(Color.WHITE) , CLOUD(Color.GRAY),MOTORIZED(Color.BLACK) , MOUNTAIN(Color.GREEN), ROCKY(Color.BLACK), FIREFIGHTER(Color.BLUE), FIRE(Color.RED), EMPTY(Color.WHITE) , CLOUD(Color.GRAY),MOTORIZED(Color.BLACK) , MOUNTAIN(Color.GREEN), ROCKY(Color.BISQUE),
ROAD(Color.BROWN); ROAD(Color.BROWN);
final Color color; final Color color;
ViewElement(Color color) { ViewElement(Color color) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment