Skip to content
Snippets Groups Projects
Commit 6d57abb9 authored by MAAZOUZ Ilyas's avatar MAAZOUZ Ilyas
Browse files

nk

parent 26e5a9d9
No related branches found
No related tags found
No related merge requests found
Pipeline #25008 passed
File deleted
File deleted
No preview for this file type
......@@ -105,6 +105,9 @@ public class Controller {
if (squareState.contains(ModelElement.FIRE)){
return ViewElement.FIRE;
}
if(squareState.contains(ModelElement.NUAGE)){
return ViewElement.NUAGE;
}
return ViewElement.EMPTY;
}
......@@ -154,6 +157,7 @@ public class Controller {
List<item> items= new ArrayList<>();
items.add(new Fire(initialFireCount));
items.add(new FireFighter(initialFirefighterCount));
items.add(new Nuage(initialFirefighterCount));
Fboard b=new Fboard(columnCount,rowCount,items);
b.initializeElements();
this.setModel(b);
......
......@@ -2,5 +2,5 @@ package model;
//this class represents two types of constant Firefighter or fire
public enum ModelElement {
FIREFIGHTER, FIRE ,NOT
FIREFIGHTER, FIRE ,NOT ,NUAGE
}
......@@ -5,7 +5,7 @@ import util.Position;
import java.util.List;
public abstract class Extinguisher implements item {
protected static final int ID = 0 ;
public abstract List<Position> update(Fboard board);
public abstract void extinguish(Position position,Fboard board);
......
......@@ -65,6 +65,10 @@ public class Fboard {
}
}
public List<item> getItems(){
return this.items;
}
public Fire getFire() {
for (item e : items) {
......
......@@ -10,7 +10,7 @@ public class Fire implements item {
private final int initialFireCount;
private List<Position> firePositions;
private ModelElement state;
private final ModelElement state;
private final Random randomGenerator = new Random();
private final int ID=1;
......
......@@ -7,13 +7,12 @@ import java.util.Random;
public class FireFighter extends Extinguisher {
private ModelElement state;
private final ModelElement state;
private List<Position> firefighterPositions;
private final Random randomGenerator = new Random();
private List<Position> neighborFirePositions;
private final int initialFirefighterCount;
private final int ID=0;
public FireFighter(int initialFirefighterCount){
this.initialFirefighterCount=initialFirefighterCount;
......@@ -55,7 +54,6 @@ public class FireFighter extends Extinguisher {
return modifiedPositions;
}
//modifiedPosition contient Last fire fighter positions and New Firefighterpositions with neighbor of every new firefighter
......@@ -68,9 +66,8 @@ public class FireFighter extends Extinguisher {
return this.state;
}
// implementi liha pattern visiteur
public int getID() {
return this.ID;
return super.ID;
}
public void initialize() {
......
package newmodel;
import model.ModelElement;
import util.Position;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Nuage extends Extinguisher {
private final ModelElement state;
private List<Position> NuagePositions;
private final Random randomGenerator = new Random();
private final int initialNuageCount;
public Nuage(int initialNuageCount) {
this.state = ModelElement.NUAGE;
this.initialNuageCount=initialNuageCount;
}
public List<Position> update(Fboard board) {
int i = 0;
List<Position> result = new ArrayList<>();
while (i < this.initialNuageCount) {
Position pos = randomPosition();
boolean positionIsValid = true;
for (item it : board.getItems()) {
if (it.getID() == 0 && it.getPositions().contains(pos)) {
positionIsValid = false;
break;
}
}
if (positionIsValid) {
i++;
result.add(pos);
}
}
for(Position p : result){
extinguish(p,board);
}
this.NuagePositions=result;
return this.NuagePositions;
}
private Position randomPosition() {
return new Position(randomGenerator.nextInt(Fboard.rowCount), randomGenerator.nextInt(Fboard.columnCount));
}
public void extinguish(Position position,Fboard board) {
board.getFire().extinguish(position);
}
public ModelElement getState() {
return this.state;
}
public int getID() {
return ID;
}
// A modifier pour ne pas avoir une superpositione entre firefighter et nuage
public void initialize() {
NuagePositions = new ArrayList<>();
for (int index = 0; index < initialNuageCount; index++)
NuagePositions.add(randomPosition());
}
@Override
public List<Position> getPositions() {
return NuagePositions;
}
}
......@@ -4,7 +4,7 @@ import javafx.scene.paint.Color;
//this class declare three constants with each constants is related to a specified color like fire to red
public enum ViewElement {
FIREFIGHTER(Color.BLUE), FIRE(Color.RED), EMPTY(Color.WHITE);
FIREFIGHTER(Color.DARKBLUE), FIRE(Color.RED), EMPTY(Color.WHITE) ,NUAGE(Color.LIGHTBLUE);
final Color color;
ViewElement(Color color) {
this.color = color;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment