Skip to content
Snippets Groups Projects
Commit fc3acaba authored by Yanis O's avatar Yanis O
Browse files

[Ajout] Rocaille (Rockery)

parent ea4b8208
No related branches found
No related tags found
No related merge requests found
Pipeline #40634 failed
...@@ -13,10 +13,10 @@ import javafx.stage.Stage; ...@@ -13,10 +13,10 @@ import javafx.stage.Stage;
public class SimulatorApplication extends javafx.application.Application { public class SimulatorApplication extends javafx.application.Application {
private static final String VIEW_RESOURCE_PATH = "/view/view.fxml"; private static final String VIEW_RESOURCE_PATH = "/view/view.fxml";
private static final String APP_NAME = "Firefighter simulator"; private static final String APP_NAME = "Firefighter simulator";
private static final int ROW_COUNT = 80; private static final int ROW_COUNT = 50;
private static final int COLUMN_COUNT = 80; private static final int COLUMN_COUNT = 50;
private static final int BOX_WIDTH = 8; private static final int BOX_WIDTH = 15;
private static final int BOX_HEIGHT = 8; private static final int BOX_HEIGHT = 15;
public static final int INITIAL_FIRE_COUNT = 6; public static final int INITIAL_FIRE_COUNT = 6;
public static final int INITIAL_FIREFIGHTER_COUNT = 32; public static final int INITIAL_FIREFIGHTER_COUNT = 32;
public static final int INITIAL_MOTORIZED_FIREFIGHTER_COUNT = 10; public static final int INITIAL_MOTORIZED_FIREFIGHTER_COUNT = 10;
......
...@@ -27,6 +27,7 @@ import model.FireFighter; ...@@ -27,6 +27,7 @@ import model.FireFighter;
import model.FireFighterScenario; import model.FireFighterScenario;
import model.MotorizedFireFighter; import model.MotorizedFireFighter;
import model.Mountain; import model.Mountain;
import model.Rockery;
import model.Square; import model.Square;
import util.Position; import util.Position;
import view.Grid; import view.Grid;
...@@ -135,6 +136,7 @@ public class Controller { ...@@ -135,6 +136,7 @@ public class Controller {
entityCounts.put((pos, b) -> new MotorizedFireFighter(pos, b), initialMotorizedFirefightersCount); entityCounts.put((pos, b) -> new MotorizedFireFighter(pos, b), initialMotorizedFirefightersCount);
entityCounts.put((pos, b) -> new Cloud(pos, b), initialcloudCount); entityCounts.put((pos, b) -> new Cloud(pos, b), initialcloudCount);
entityCounts.put((pos, b) -> new Mountain(pos), initialmountaincount); entityCounts.put((pos, b) -> new Mountain(pos), initialmountaincount);
entityCounts.put((pos, b) -> new Rockery(pos), 30);
model.placeInitialEntities(entityCounts); model.placeInitialEntities(entityCounts);
this.setModel(model); this.setModel(model);
......
...@@ -3,6 +3,7 @@ package model; ...@@ -3,6 +3,7 @@ package model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import util.Position; import util.Position;
...@@ -59,6 +60,17 @@ public class Fire implements Entity { ...@@ -59,6 +60,17 @@ public class Fire implements Entity {
if (board.doesSquareContainEntity(p, Road.class)) { if (board.doesSquareContainEntity(p, Road.class)) {
continue; continue;
} }
if (board.doesSquareContainEntity(p, Rockery.class)) {
Optional<Entity> e = board.getStates(p).getEntities().stream().findFirst();
if(e != null && e.isPresent() && e.get() instanceof Rockery){
Rockery rockery = (Rockery) e.get();
if(rockery.getBurn() < 4){
rockery.incrementBurn();
continue;
}
}
}
// Add new Fire to the board // Add new Fire to the board
board.addEntityAtSquare(new Fire(p), p); board.addEntityAtSquare(new Fire(p), p);
......
...@@ -79,6 +79,12 @@ public class FireFighter implements Entity { ...@@ -79,6 +79,12 @@ public class FireFighter implements Entity {
List<Position> extinguishedPositions = new ArrayList<>(); List<Position> extinguishedPositions = new ArrayList<>();
for (Position p : adjacentPositions) { for (Position p : adjacentPositions) {
if (b.doesSquareContainEntity(p, Fire.class)) { if (b.doesSquareContainEntity(p, Fire.class)) {
if(b.doesSquareContainEntity(p, Rockery.class)){
Rockery rockery = (Rockery) b.getStates(p).getEntities().stream()
.filter(Rockery.class::isInstance)
.findFirst().get();
rockery.resetBurn();
}
b.getStates(p).getEntities().removeIf(element -> element instanceof Fire); b.getStates(p).getEntities().removeIf(element -> element instanceof Fire);
// Update age for EmptyEntity if needed // Update age for EmptyEntity if needed
b.getStates(p).getEntities().forEach(e -> { b.getStates(p).getEntities().forEach(e -> {
......
...@@ -247,7 +247,7 @@ public class FireFighterScenario extends EntityScenario implements Board<Square> ...@@ -247,7 +247,7 @@ public class FireFighterScenario extends EntityScenario implements Board<Square>
for(Position p : snake){ for(Position p : snake){
List<Entity> entitiesAtSquare = List.copyOf(getStates(p).getEntities()); List<Entity> entitiesAtSquare = List.copyOf(getStates(p).getEntities());
for(Entity e: entitiesAtSquare){ for(Entity e: entitiesAtSquare){
if(e instanceof Mountain){ if(e instanceof Mountain || e instanceof Rockery || e instanceof Fire){
clearCaseFrom(e, e.getPosition()); clearCaseFrom(e, e.getPosition());
} }
} }
......
package model;
import java.util.List;
import javafx.scene.paint.Color;
import util.Position;
public class Rockery implements Entity{
private final int priority = 0;
Position position;
private int age;
private int burn;
private final Color viewColor = Color.LIMEGREEN;
public Rockery(Position p ){
this.position = p;
this.burn = 0;
}
public Rockery(Position p , int age){
System.out.println("age : " + age);
this.position = p;
this.age = age;
}
@Override
public List<Position> nextTurn(Board<Square> board) {
return List.of();
}
@Override
public Position getPosition() {
return this.position;
}
public int getBurn(){
return this.burn;
}
public void incrementBurn(){
this.burn = burn + 1;
}
@Override
public void setPosition(Position p) {
this.position = p;
}
@Override
public int getAge() {
return this.age;
}
@Override
public void setAge(int age) {
this.age = age;
}
@Override
public void incrementAge() {
this.age += 1;
}
@Override
public Color getViewColor() {
return this.viewColor;
}
@Override
public int getPriority() {
return this.priority;
}
public void resetBurn() {
this.burn = 0;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment