Skip to content
Snippets Groups Projects
Commit e08dc9d8 authored by RAKOTOARISOA Andrianinarisaina cy's avatar RAKOTOARISOA Andrianinarisaina cy
Browse files

Tâche 1 : dans la classe MatrixPane, remplacement du constructeur "new...

Tâche 1 : dans la classe MatrixPane, remplacement du constructeur "new GrayGrid(numberOfRows,numberOfColumns)" par "new ArrayGrid(numberOfRows,numberOfColumns)".
parent a39d6d3c
No related branches found
No related tags found
No related merge requests found
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;
}
}
......@@ -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.
*
......
......@@ -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);
/**
......
......@@ -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 ;
......
//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 ;
}
}
......@@ -28,12 +28,14 @@ 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) {
this.controller = controller;
}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment