From e08dc9d89322c31b002ec323a6b5a2cdb4a33ef6 Mon Sep 17 00:00:00 2001
From: r20004714 <andrianinarisaina-cy.RAKOTOARISOA@etu.univ-amu.fr>
Date: Mon, 14 Nov 2022 17:36:50 +0100
Subject: [PATCH] =?UTF-8?q?T=C3=A2che=201=20:=20dans=20la=20classe=20Matri?=
 =?UTF-8?q?xPane,=20remplacement=20du=20constructeur=20"new=20GrayGrid(num?=
 =?UTF-8?q?berOfRows,numberOfColumns)"=20par=20"new=20ArrayGrid(numberOfRo?=
 =?UTF-8?q?ws,numberOfColumns)".?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/src/main/java/model/ArrayGrid.java        | 35 +++++++++++++++++--
 app/src/main/java/model/GrayGrid.java         |  6 ++++
 app/src/main/java/model/Grid.java             |  4 +++
 app/src/main/java/model/SquareCell.java       |  1 +
 .../java/model/UniformColorGenerator.java     | 20 +++++++++++
 app/src/main/java/view/MatrixPane.java        |  8 +++--
 app/src/test/java/model/ArrayGridTest.java    |  8 ++---
 7 files changed, 71 insertions(+), 11 deletions(-)
 create mode 100644 app/src/main/java/model/UniformColorGenerator.java

diff --git a/app/src/main/java/model/ArrayGrid.java b/app/src/main/java/model/ArrayGrid.java
index f6d943d..30ec1d0 100644
--- a/app/src/main/java/model/ArrayGrid.java
+++ b/app/src/main/java/model/ArrayGrid.java
@@ -1,9 +1,9 @@
 package model;
 
-public abstract class ArrayGrid implements Grid {
+public class ArrayGrid implements model.Grid {
 
     //Tableau pour stocker les cellules
-    Cell[][] cells ;
+    model.Cell[][] cells ;
 
     //Nombre de lignes
     int numberOfRows ;
@@ -14,7 +14,7 @@ public abstract class ArrayGrid implements Grid {
     //Constructeur
     //Une grille avec les nombres de lignes et de colonnes passés en arguments
     //Ce constructeur initialise le tableau cells aux bonnes dimensions et remplit les cases avec des instances de SquareCell
-    public void ArrayGrid(int numberOfRows, int numberOfColumns) {
+    public ArrayGrid(int numberOfRows, int numberOfColumns) {
         //Traitement des exceptions pour eviter que le programme se termine non connecté
             if (numberOfRows <= 0 && numberOfColumns <= 0)
                 throw new IllegalArgumentException("valeur argument négatif ou nul");
@@ -24,4 +24,33 @@ public abstract class ArrayGrid implements Grid {
                         cells[i][j] = new SquareCell() ;
     }
 
+    //Demander par l'exercice
+    public void color(ColorGenerator[] colorGenerator) {
+        for (int i = 0 ; i < numberOfRows ; i++)
+            for (int j = 0 ; j < numberOfColumns ; j++) {
+                colorGenerator = new ColorGenerator[]{} ;
+                //cells[i][j].setColor(colorGenerator.nextColor());
+            }
+    }
+
+    @Override
+    public void color(ColorGenerator colorGenerator) {
+    }
+
+    @Override
+    public model.Cell getCell(int row, int column) {
+        return null;
+    }
+
+    @Override
+    public int getNumberOfRows() {
+        return 0;
+    }
+
+    @Override
+    public int getNumberOfColumns() {
+        return 0;
+    }
+
+
 }
diff --git a/app/src/main/java/model/GrayGrid.java b/app/src/main/java/model/GrayGrid.java
index 02cb8ee..b3078cc 100644
--- a/app/src/main/java/model/GrayGrid.java
+++ b/app/src/main/java/model/GrayGrid.java
@@ -9,6 +9,12 @@ public class GrayGrid implements Grid{
         this.numberOfRows = numberOfRows;
         this.numnberOfColumns = numberOfColumns;
     }
+
+    @Override
+    public void color(ColorGenerator colorGenerator) {
+
+    }
+
     /**
      * Return the cell located at the given coordinates in the grid.
      *
diff --git a/app/src/main/java/model/Grid.java b/app/src/main/java/model/Grid.java
index 64341b4..cedbaca 100644
--- a/app/src/main/java/model/Grid.java
+++ b/app/src/main/java/model/Grid.java
@@ -8,6 +8,10 @@ public interface  Grid  {
      * @param column the column of the returned cell
      * @return the cell located in row {@code row} and in column {@code column}
      */
+
+    //Méthode demandée par l'exercice
+    public void color (ColorGenerator colorGenerator);
+
     Cell getCell(int row, int column);
 
     /**
diff --git a/app/src/main/java/model/SquareCell.java b/app/src/main/java/model/SquareCell.java
index 679509b..411fbdf 100644
--- a/app/src/main/java/model/SquareCell.java
+++ b/app/src/main/java/model/SquareCell.java
@@ -27,6 +27,7 @@ public class SquareCell extends AbstractCell{
 
     //Constructeur 3 : un constructeur avec deux paramètres : "Color color" et "ArrayList<Cell> neighbours
     //qui consrtuit une cellule de couleur color et dont les cellules voisines sont neighours
+    //@Override
     public void SquareCell(Color color, List<Cell> neighbours) {
         this.neighbours = neighbours ;
         this.color = color ;
diff --git a/app/src/main/java/model/UniformColorGenerator.java b/app/src/main/java/model/UniformColorGenerator.java
new file mode 100644
index 0000000..5177960
--- /dev/null
+++ b/app/src/main/java/model/UniformColorGenerator.java
@@ -0,0 +1,20 @@
+//7.2 Classe UniformColorGenerator
+// Cette classe correspong à un coloriage uniforme de la grille
+
+package model;
+import javafx.scene.paint.Color;
+
+public class UniformColorGenerator implements ColorGenerator{
+
+    Color couleur ;
+
+    //Constructeur de la classe
+    public void UniformColorGenerator(Color couleur) {
+        this.couleur = couleur ;
+    }
+
+    @Override
+    public Color nextColor(Cell cell) {
+        return this.couleur ;
+    }
+}
diff --git a/app/src/main/java/view/MatrixPane.java b/app/src/main/java/view/MatrixPane.java
index f20ed03..e43d3ef 100644
--- a/app/src/main/java/view/MatrixPane.java
+++ b/app/src/main/java/view/MatrixPane.java
@@ -28,13 +28,15 @@ public class MatrixPane extends GridPane {
         this.tileHeight = tileHeight;
         this.numberOfColumns = numberOfColumns;
         this.numberOfRows = numberOfRows;
+
         // TODO replace by new ArrayGrid(numberOfRows, numberOfColumns)
-        cellGrid = new GrayGrid(numberOfRows, numberOfColumns);
+        //Changement du constructeur "GrayGrid" en "ArrayGrid"
+        //cellGrid = new GrayGrid(numberOfRows, numberOfColumns);
+        cellGrid = new model.ArrayGrid(numberOfRows, numberOfColumns);
         initMatrix();
     }
 
-
-    public void setGameController(GameController controller){
+    public void setGameController(GameController controller) {
         this.controller = controller;
     }
 
diff --git a/app/src/test/java/model/ArrayGridTest.java b/app/src/test/java/model/ArrayGridTest.java
index b63b2e3..67f01c9 100644
--- a/app/src/test/java/model/ArrayGridTest.java
+++ b/app/src/test/java/model/ArrayGridTest.java
@@ -11,12 +11,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 class ArrayGridTest {
 
-    // TODO
-    //  uncomment
-/*
+
     private  ArrayGrid arrayGridThreeFour;
     private final ArrayGrid arrayGridTwoTwo = new ArrayGrid(2,2);
-
+public static void(String arg[]) {}
     @BeforeEach
     void initializeArrayGridThreeFour(){
         arrayGridThreeFour = new ArrayGrid(3,4);
@@ -89,5 +87,5 @@ class ArrayGridTest {
         assertThat(iterator.hasNext()).isFalse();
 
     }
- */
+
 }
\ No newline at end of file
-- 
GitLab