From 543b5a90e4b3e534a0769c1c07074189dc125b53 Mon Sep 17 00:00:00 2001
From: Yanis O <oualanyanis01@gmail.com>
Date: Thu, 14 Nov 2024 22:02:35 +0100
Subject: [PATCH] =?UTF-8?q?[Fix]=20Correction=20du=20probl=C3=A8me=20de=20?=
 =?UTF-8?q?stockage=20d'=C3=A2ge=20pour=20les=20cases=20vides?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/main/java/model/EmptyEntity.java         | 59 ++++++++++++++++++++
 src/main/java/model/Entity.java              |  1 +
 src/main/java/model/EntityScenario.java      |  3 +-
 src/main/java/model/Fire.java                |  4 ++
 src/main/java/model/FireFighter.java         |  5 +-
 src/main/java/model/FireFighterScenario.java |  5 +-
 src/main/java/model/Square.java              |  2 +-
 7 files changed, 75 insertions(+), 4 deletions(-)
 create mode 100644 src/main/java/model/EmptyEntity.java

diff --git a/src/main/java/model/EmptyEntity.java b/src/main/java/model/EmptyEntity.java
new file mode 100644
index 0000000..6a916b8
--- /dev/null
+++ b/src/main/java/model/EmptyEntity.java
@@ -0,0 +1,59 @@
+package model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javafx.scene.paint.Color;
+import util.Position;
+
+public class EmptyEntity implements Entity{
+
+
+    private Position position;
+    private int age;
+    public EmptyEntity(Position position){
+        this.position = position;
+        this.age = 0;
+    }
+    public EmptyEntity(Position position, int age){
+        this.position = position;
+        this.age = age;
+    }
+    @Override
+    public List<Position> nextTurn(Board<Square> board) {
+        return new ArrayList<Position>();
+    }
+
+    @Override
+    public Position getPosition() {
+        return this.position;
+    }
+
+    @Override
+    public void setPosition(Position p) {
+        this.position = p;
+    }
+
+    @Override
+    public int getAge() {
+        return age;
+    }
+
+    @Override 
+    public void setAge(int age){
+        this.age = age;
+    }
+
+    @Override
+    public void incrementAge() {
+        this.age = age + 1;
+    }
+
+
+
+    @Override
+    public Color getViewColor() {
+        return Color.WHITE;
+    }
+    
+}
\ No newline at end of file
diff --git a/src/main/java/model/Entity.java b/src/main/java/model/Entity.java
index e45030a..a14b34a 100644
--- a/src/main/java/model/Entity.java
+++ b/src/main/java/model/Entity.java
@@ -16,6 +16,7 @@ public interface Entity {
     public Position getPosition();
     public void setPosition(Position p);
     public int getAge();
+    public void setAge(int age);
     public void incrementAge();
     public Color getViewColor();
 }
diff --git a/src/main/java/model/EntityScenario.java b/src/main/java/model/EntityScenario.java
index 3845fb5..e6c9bd3 100644
--- a/src/main/java/model/EntityScenario.java
+++ b/src/main/java/model/EntityScenario.java
@@ -7,7 +7,8 @@ public abstract class EntityScenario implements Scenario{
     public void initScenario(Matrix<Square> matrix){
         for(int x = 0; x < matrix.getRows(); x++){
             for(int y = 0; y < matrix.getColumns(); y++){
-                matrix.set(x,y, new Square(new Position(x, y)));
+                Square s = new Square(new Position(x, y), new EmptyEntity(new Position(x,y)));
+                matrix.set(x,y, s);
             }
         }
     }
diff --git a/src/main/java/model/Fire.java b/src/main/java/model/Fire.java
index 5019b7b..75756ca 100644
--- a/src/main/java/model/Fire.java
+++ b/src/main/java/model/Fire.java
@@ -64,4 +64,8 @@ public class Fire implements Entity{
     public void incrementAge() {
         this.age = age + 1 ;
     }
+    @Override
+    public void setAge(int age) {
+        this.age = age;
+    }
 }
diff --git a/src/main/java/model/FireFighter.java b/src/main/java/model/FireFighter.java
index 0816e56..16f0d7d 100644
--- a/src/main/java/model/FireFighter.java
+++ b/src/main/java/model/FireFighter.java
@@ -129,5 +129,8 @@ public class FireFighter implements Entity{
         this.age = age + 1 ;
     }
 
-    
+    @Override
+    public void setAge(int age) {
+        this.age = age;
+    }
 }
diff --git a/src/main/java/model/FireFighterScenario.java b/src/main/java/model/FireFighterScenario.java
index 987ceda..b450177 100644
--- a/src/main/java/model/FireFighterScenario.java
+++ b/src/main/java/model/FireFighterScenario.java
@@ -41,6 +41,7 @@ public class FireFighterScenario extends EntityScenario implements Board<Square>
     }
 
     while (fireCount < initialFireCount || fireFighterCount < initialFireFightersCount) {
+      System.out.println("aaa");
       Collections.shuffle(positions); // Mélange les positions pour un parcours aléatoire
 
       for (Position pos : positions) {
@@ -121,7 +122,9 @@ public class FireFighterScenario extends EntityScenario implements Board<Square>
 
   @Override
   public void clearCase(Position position) {
-    setSquare(new Square(position), position, true);
+    Square s = new Square(position);
+    s.addEntity(new EmptyEntity(position, step+1));
+    setSquare(s, position, true);
   }
 
   public List<Position> updateToNextGeneration() {
diff --git a/src/main/java/model/Square.java b/src/main/java/model/Square.java
index 98c37e2..67a68b6 100644
--- a/src/main/java/model/Square.java
+++ b/src/main/java/model/Square.java
@@ -40,7 +40,7 @@ public class Square {
     }
 
     public boolean isEmpty(){
-        return entities.isEmpty();
+        return entities.isEmpty() ||(entities.size() == 1 && entities.get(0) instanceof EmptyEntity);
     }
 
     public int getMinimalAge(){
-- 
GitLab