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

Add mountains to the grid

parent 7c1439de
Branches
No related tags found
No related merge requests found
Pipeline #41520 passed
Showing
with 96 additions and 5 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
...@@ -18,7 +18,7 @@ public class SimulatorApplication extends javafx.application.Application { ...@@ -18,7 +18,7 @@ public class SimulatorApplication extends javafx.application.Application {
private static final int BOX_WIDTH = 50; private static final int BOX_WIDTH = 50;
private static final int BOX_HEIGHT = 50; private static final int BOX_HEIGHT = 50;
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 = 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;
......
...@@ -93,6 +93,10 @@ public class Controller { ...@@ -93,6 +93,10 @@ public class Controller {
{ {
return ViewElement.MOTORIZED; return ViewElement.MOTORIZED;
} }
if(element instanceof Mountain)
{
return ViewElement.MOUNTAIN;
}
} }
return ViewElement.EMPTY; return ViewElement.EMPTY;
......
...@@ -16,10 +16,6 @@ public abstract class BoardElement implements ModelElement{ ...@@ -16,10 +16,6 @@ public abstract class BoardElement implements ModelElement{
public void setPosition(Position position) { public void setPosition(Position position) {
this.position = position; this.position = position;
} }
public boolean isAtPosition(Position position) {
return this.position.equals(position);
}
public abstract String getType(); // Ajout de la méthode abstraite public abstract String getType(); // Ajout de la méthode abstraite
......
...@@ -16,6 +16,7 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -16,6 +16,7 @@ public class BoardFireFighterBehavior implements BoardBehavior{
private final ElementFactory<Cloud> cloudFactory; private final ElementFactory<Cloud> cloudFactory;
private final ElementFactory<MotorizedFireFighter> motorizedFactory; private final ElementFactory<MotorizedFireFighter> motorizedFactory;
private List<Position> cloudPositions; private List<Position> cloudPositions;
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,
...@@ -55,6 +56,7 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -55,6 +56,7 @@ public class BoardFireFighterBehavior implements BoardBehavior{
for (MotorizedFireFighter motorizedFirefighter : motorizedFirefighters) { for (MotorizedFireFighter motorizedFirefighter : motorizedFirefighters) {
motorizedFighters.add(motorizedFirefighter.getPosition()); motorizedFighters.add(motorizedFirefighter.getPosition());
} }
generateMountainBlocks(rowCount, columnCount);
} }
...@@ -218,4 +220,49 @@ public class BoardFireFighterBehavior implements BoardBehavior{ ...@@ -218,4 +220,49 @@ public class BoardFireFighterBehavior implements BoardBehavior{
public List<Position> getMotorizedFighters() { public List<Position> getMotorizedFighters() {
return motorizedFighters; return motorizedFighters;
} }
private void generateMountainBlocks(int rowCount, int columnCount) {
Random random = new Random();
int maxMountains = 5; // Par exemple, générer 5 blocs de montagnes
int blockSize = 4; // Taille du bloc de montagnes (4 cases)
for (int i = 0; i < maxMountains; i++) {
// Générer un coin aléatoire pour chaque bloc de montagne (en s'assurant que les blocs ne dépassent pas la grille)
int startRow = random.nextInt(rowCount - 1); // -1 pour éviter le débordement
int startCol = random.nextInt(columnCount - 1);
// Vérifier si les cases sont libres avant d'y placer une montagne
if (canPlaceMountainBlock(startRow, startCol)) {
// Placer les montagnes sur la grille
placeMountainBlock(startRow, startCol);
}
}
}
private boolean canPlaceMountainBlock(int startRow, int startCol) {
// Vérifier si les 4 cases sont libres
for (int row = startRow; row < startRow + 2; row++) {
for (int col = startCol; col < startCol + 2; col++) {
Position pos = new Position(row, col);
if (terrainMap.containsKey(pos)) {
return false; // Une case est déjà occupée
}
}
}
return true; // Toutes les cases sont libres
}
private void placeMountainBlock(int startRow, int startCol) {
// Placer les 4 cases de montagne
for (int row = startRow; row < startRow + 2; row++) {
for (int col = startCol; col < startCol + 2; col++) {
Position pos = new Position(row, col);
terrainMap.put(pos, new Mountain(pos));
}
}
}
public Map<Position, Terrain> getTerrainMap() {
return terrainMap;
}
} }
...@@ -64,6 +64,12 @@ public class FirefighterBoard implements Board<List<ModelElement>> { ...@@ -64,6 +64,12 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
.filter(pos -> pos.isAtPosition(position)) .filter(pos -> pos.isAtPosition(position))
.forEach(pos -> result.add(new MotorizedFireFighter(pos))); .forEach(pos -> result.add(new MotorizedFireFighter(pos)));
behavior.getTerrainMap().forEach((pos, value) -> {
if (pos.isAtPosition(position) && value instanceof Mountain) {
result.add((Mountain) value); // Ajouter uniquement un objet Mountain
}
});
return result; return result;
} }
......
...@@ -11,6 +11,7 @@ public class MotorizedFireFighter extends BoardElement{ ...@@ -11,6 +11,7 @@ public class MotorizedFireFighter extends BoardElement{
super(position); super(position);
} }
@Override @Override
public String getType() { public String getType() {
return "MotorizedFireFighter"; return "MotorizedFireFighter";
......
package model;
import util.Position;
public class Mountain extends BoardElement implements Terrain {
public Mountain(Position position) {
super(position);
}
@Override
public String getType() {
return null;
}
@Override
public String toString() {
return null;
}
@Override
public boolean isTraversableByFire() {
return false; // Les montagnes ne sont pas franchissables par le feu
}
@Override
public boolean isTraversableByFirefighter() {
return false; // Les pompiers ne peuvent pas passer non plus
}
}
package model;
public interface Terrain {
boolean isTraversableByFire();
boolean isTraversableByFirefighter();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment