From 9ab8fe6d661a66e0b6defffd78aa2c609ea8095e Mon Sep 17 00:00:00 2001
From: Yanis O <oualanyanis01@gmail.com>
Date: Tue, 12 Nov 2024 20:47:08 +0100
Subject: [PATCH] =?UTF-8?q?Compl=C3=A9tion=20de=20certaines=20m=C3=A9thode?=
 =?UTF-8?q?s=20de=20FireFighterScenario?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/main/java/model/Fire.java                |  4 +-
 src/main/java/model/FireFighter.java         |  2 +-
 src/main/java/model/FireFighterScenario.java | 51 +++++++++-----------
 src/main/java/util/Matrix.java               |  3 ++
 4 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/src/main/java/model/Fire.java b/src/main/java/model/Fire.java
index 26de9fc..e04c0d7 100644
--- a/src/main/java/model/Fire.java
+++ b/src/main/java/model/Fire.java
@@ -2,9 +2,9 @@ package model;
 import util.Position;
 
 public class Fire implements Entity{
-    
+    Board b;
     private Position position;
-    public Fire(Position position){
+    public Fire(Position position, Board b){
         this.position = position;
     }
 
diff --git a/src/main/java/model/FireFighter.java b/src/main/java/model/FireFighter.java
index 7dc1589..055d0cb 100644
--- a/src/main/java/model/FireFighter.java
+++ b/src/main/java/model/FireFighter.java
@@ -13,7 +13,7 @@ public class FireFighter implements Entity{
         //Sinon
         //Se déplacer vers le feu le plus proche
         //Si un feu est à proximité : éteindre les feux à x + 1 y, x y+1, x+1 y-1, x-1 y+1 
-        // Ajouter un feu à x + 1 y, x y+1, x+1 y-1, x-1 y+1 
+        // Ajouter un feu à x + 1 y, x y+1, x-1 y, x y-1 
     }
 
     
diff --git a/src/main/java/model/FireFighterScenario.java b/src/main/java/model/FireFighterScenario.java
index fc3c5dd..92440f3 100644
--- a/src/main/java/model/FireFighterScenario.java
+++ b/src/main/java/model/FireFighterScenario.java
@@ -1,45 +1,35 @@
 package model;
+import java.util.ArrayList;
 import java.util.List;
 
-import util.*;
+import util.Matrix;
+import util.Position;
+
 
 public class FireFighterScenario implements Board<Entity>{
-    /**
-   * Get the state of the board at a specific position.
-   *
-   * @param position The position on the board for which to retrieve the state.
-   * @return The state at the specified position.
-   */
+  
+  private Matrix<Entity> matrix
+  public FireFighterScenario(int boardSize){
+    this.matrix = new Matrix();
+  }
   public Entity getState(Position position){
-    throw new IllegalStateException("Method not implemented");
+    if(position.x() > matrix.size() || position.y() > matrix.get(0).size()){
+      throw new IllegalArgumentException("The position x:" + position.x() + " y:" + position.y() + " is out of the board.");
+    }
+    return matrix.get(position.x()).get(position.y());
   }
 
-  /**
-   * Set the state of a specific position on the board to the specified state.
-   *
-   * @param state The state to set for the given position.
-   * @param position The position on the board for which to set the state.
-   */
   public void setState(Entity state, Position position){
-    throw new IllegalStateException("Method not implemented");
+    matrix.get(position.x()).set(position.y(), state);
   }
 
-  /**
-   * Get the number of rows in the board.
-   *
-   * @return The number of rows in the board.
-   */
+
   public int rowCount(){
-    throw new IllegalStateException("Method not implemented");
+    return matrix.size();
   }
 
-  /**
-   * Get the number of columns in the board.
-   *
-   * @return The number of columns in the board.
-   */
   public int columnCount(){
-    throw new IllegalStateException("Method not implemented");
+    return matrix.get(0).size();
   }
 
   /**
@@ -50,7 +40,12 @@ public class FireFighterScenario implements Board<Entity>{
    * @return A list of positions that have changed during the update.
    */
   public List<Position> updateToNextGeneration(){
-    throw new IllegalStateException("Method not implemented");
+    for(ArrayList<Entity> l : matrix){
+      for(Entity e : l){
+        e.nextTurn(this);
+      }
+    }
+    return matrix;
   }
 
   /**
diff --git a/src/main/java/util/Matrix.java b/src/main/java/util/Matrix.java
index 3fe027c..a2d05d6 100644
--- a/src/main/java/util/Matrix.java
+++ b/src/main/java/util/Matrix.java
@@ -12,6 +12,9 @@ public class Matrix<E> {
     public E set(int x, int y, E object){
         return matrix.get(x).set(y, object);
     }
+    public void clear(){
+        this.matrix = new ArrayList<ArrayList<E>>();
+    }
     public int size(){
         return matrix != null ? matrix.get(0).size()*matrix.size() : 0;
     }
-- 
GitLab