Skip to content
Snippets Groups Projects
Commit dca57913 authored by melizzzz's avatar melizzzz
Browse files

Cloud (petits soucis)

parent e545624c
No related branches found
No related tags found
No related merge requests found
Pipeline #39629 passed
......@@ -13,8 +13,8 @@ import javafx.stage.Stage;
public class SimulatorApplication extends javafx.application.Application {
private static final String VIEW_RESOURCE_PATH = "/view/view.fxml";
private static final String APP_NAME = "Firefighter simulator";
private static final int ROW_COUNT = 20;
private static final int COLUMN_COUNT = 20;
private static final int ROW_COUNT = 22;
private static final int COLUMN_COUNT = 22;
private static final int BOX_WIDTH = 25;
private static final int BOX_HEIGHT = 25;
public static final int INITIAL_FIRE_COUNT = 3;
......
......@@ -31,22 +31,27 @@ public class Cloud implements Entity{
@Override
public List<Position> nextTurn(Board<Square> b) {
List<Position> adjacentPositions = PositionUtil.generateAdjacentPositions(position, b);
Position next_position = adjacentPositions.get(new Random().nextInt(adjacentPositions.size()));
// Filtrer pour obtenir uniquement les positions qui ne contiennent pas de pompier
adjacentPositions.removeIf(p -> b.doesSquareContainEntity(p, FireFighter.class));
// Choisir une position aléatoire parmi les mouvements possibles
Position next_position = adjacentPositions.get(new Random().nextInt(adjacentPositions.size()));
// Si la nouvelle position contient un feu, éteindre le feu
if (b.getStates(next_position).getEntities().stream().anyMatch(element -> element instanceof Fire) ){
extinguish(next_position, b);
}
Position old_position = this.position;
this.position = next_position;
b.addEntityAtSquare(this, position);
b.addEntityAtSquare(this, next_position);
b.clearCaseFrom(this, old_position);
return List.of(old_position, this.position);
}
private Position extinguish(Position p, Board<Square> b) {
b.getStates(p).getEntities().removeIf(element -> element instanceof Fire);
List<Entity> entities = b.getStates(p).getEntities();
......
......@@ -32,7 +32,7 @@ public class Fire implements Entity {
return new ArrayList<Position>();
List<Position> positions = PositionUtil.generateAdjacentPositions(position, board);
for (Position p : positions) {
if (b.getStates(p).isEmpty()) {
if (b.getStates(p).isEmpty() && !b.getStates(p).getEntities().contains(Cloud.class)) {
if (b.getStates(p).getMaxAge() < b.getStepNumber()
&& PositionUtil.getManhattanDistance(position, p) == 1) {
board.addEntityAtSquare(new Fire(p, board), p);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment