Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
1 result

Target

Select target project
  • travers.c/flooding-template
  • g20031427/flooding-template
  • p20006624/flooding-template
  • b21221851/tp-6
  • n19028187/flooding-template
  • e21221636/tp-6-flood
  • saddem.r/flooding-template
  • r20029383/flooding-template
  • s21226517/flooding-template
  • r20004714/flooding-template
  • e20026270/flooding-template-el-ghaouti-aymane
  • o21205600/flooding-template
12 results
Select Git revision
  • main
1 result
Show changes
Commits on Source (6)
......@@ -6,5 +6,5 @@ Il s'agit d'implémenter une version du jeu "inondation" (voir par exemple [ici]
## Membre du projet
- NOM, prénom
- NOM, prénom
- EL Gaoual, Zaid e21221636
- BELKHALIFA, Mohamed Amine b21221851
package model;
public class ArrayGrid implements Grid{
public Cell[][] cells;
public ArrayGrid(int numberOfRows, int numberOfColumns) {
if(numberOfRows <= 0 || numberOfColumns <= 0)
throw new IllegalArgumentException("Le nombre de lignes ou de colonnes ne peut pas être nul ou négatif.");
Cell[][] cells = new Cell[numberOfRows][numberOfColumns];
for(Cell[] column : cells ) {
for(Cell cell : column) {
cell = new SquareCell();
}
}
}
@Override
public Cell getCell(int row, int column) {
return cells[row][column];
}
@Override
public int getNumberOfRows() {
return cells.length;
}
@Override
public int getNumberOfColumns() {
return cells[0].length;
}
@Override
public void color(ColorGenerator colorGenerator) {
for(Cell[] column : cells ) {
for(Cell cell : column) {
cell.setColor(colorGenerator.nextColor(cell));
}
}
}
}
......@@ -27,5 +27,8 @@ public interface Grid {
* @param colorGenerator the generator used to determine the color of each cell.
* The new color of {@code cell} is obtained by calling the method {@code nextColor}
*/
void color(ColorGenerator colorGenerator);
}
......@@ -6,9 +6,25 @@ import java.util.Iterator;
import java.util.List;
public class SquareCell extends AbstractCell{
public List<Cell>neighbours;
public SquareCell() {
Color DEFAULT_CELL_COLOR;
List<Cell> neighbours;
}
public SquareCell(Color color) {
this.setColor(color);
List<Cell> neighbours;
}
public SquareCell(Color color, List<Cell> neighbours) {
this.setColor(color);
this.setNeighbours(neighbours);
}
/**
* A cell is placed somewhere on a grid. Its neighbours thus depend on the underlying grid.
......@@ -16,10 +32,7 @@ public class SquareCell extends AbstractCell{
* @return the list of cell that are neighbours of this{@code Cell}.
*/
@Override
public List<Cell> getNeighbours() {
return null;
}
public List<Cell> getNeighbours() {return this.neighbours;}
/**
* Update the list of neighbours of this {@code Cell}.
*
......@@ -28,7 +41,7 @@ public class SquareCell extends AbstractCell{
*/
@Override
public void setNeighbours(List<Cell> cells) {
this.neighbours=cells;
}
......
......@@ -8,6 +8,7 @@ import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;
import model.ArrayGrid;
import model.Cell;
import model.GrayGrid;
import model.Grid;
......@@ -29,7 +30,7 @@ public class MatrixPane extends GridPane {
this.numberOfColumns = numberOfColumns;
this.numberOfRows = numberOfRows;
// TODO replace by new ArrayGrid(numberOfRows, numberOfColumns)
cellGrid = new GrayGrid(numberOfRows, numberOfColumns);
cellGrid = new ArrayGrid(numberOfRows, numberOfColumns);
initMatrix();
}
......
......@@ -19,13 +19,13 @@ class SquareCellTest {
private final Cell centralCell = new SquareCell(Color.CHOCOLATE);
@BeforeEach
/* @BeforeEach
void testInitializeNeighbourhood(){
centralCell.setNeighbours(List.of(northCell,southCell,westCell,eastCell));
westCell.setNeighbours(List.of(centralCell));
eastCell.setNeighbours(List.of(centralCell));
southCell.setNeighbours(List.of(centralCell));
northCell.setNeighbours(List.of(centralCell));
northCell.setNeighbours(List.of(centralCell));*/
}
@Test
void testIterator() {
......