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 4

...@@ -6,5 +6,4 @@ Il s'agit d'implémenter une version du jeu "inondation" (voir par exemple [ici] ...@@ -6,5 +6,4 @@ Il s'agit d'implémenter une version du jeu "inondation" (voir par exemple [ici]
## Membre du projet ## Membre du projet
- NOM, prénom - Nguyen thi hang groupe 3
- NOM, prénom
package model;
import java.util.Iterator;
public class ArrayGrid implements Grid{
private Cell[][] cells;
private int numberOfRows;
private int numberOfColumns;
public ArrayGrid(int numberOfRows, int numberOfColumns){
this.cells=new SquareCell[numberOfRows][numberOfColumns];
if (numberOfRows <= 0 || numberOfColumns <= 0)
throw new IllegalArgumentException();
}
@Override
public Cell getCell(int row, int column) {
return this.cells[row][column];
}
@Override
public int getNumberOfRows() {
return this.numberOfRows;
}
@Override
public int getNumberOfColumns() {
return this.numberOfColumns;
}
public void color(ColorGenerator colorGenerator) {
for (int i=0; i < this.getNumberOfRows();i++){
for(int j=0; j< this.getNumberOfColumns();j++){
this.getCell(i,j).setColor(colorGenerator.nextColor(this.getCell(i,j)));
}
}
}
public Iterator<Cell> iterator(){
return (Iterator<Cell>) new CellGridIterator(this);
}
}
package model;
public class CellGridIterator {
ArrayGrid grid;
int indixRow;
int indixColum;
public CellGridIterator(ArrayGrid grid) {
this.grid = grid;
this.indixColum=0;
this.indixRow=0;
}
public Cell next() {
final Cell result = grid.getCell(indixRow, indixColum);
indixColum = (indixColum +1) % grid.getNumberOfColumns();
if(indixColum == 0){
indixRow++;
}
return result;
}
public boolean hasNext(){
return this.indixColum < this.grid.getNumberOfColumns() && indixRow < this.grid.getNumberOfRows();
}
}
package model;
import java.awt.*;
import javafx.scene.paint.Color;
import java.util.List;
public class CyclicColorGenerator implements ColorGenerator {
List<Color> colors;
public CyclicColorGenerator(List<Color> colors){
this.colors=colors;
}
int count=0;
@Override
public Color nextColor(Cell cell) {
count++;
return this.colors.get(count-1);
}
}
package model; package model;
import java.util.Iterator;
public class GrayGrid implements Grid{ public class GrayGrid implements Grid{
private final int numberOfRows; private final int numberOfRows;
...@@ -40,4 +42,14 @@ public class GrayGrid implements Grid{ ...@@ -40,4 +42,14 @@ public class GrayGrid implements Grid{
public int getNumberOfColumns() { public int getNumberOfColumns() {
return numnberOfColumns; return numnberOfColumns;
} }
@Override
public void color(ColorGenerator colorGenerator) {
}
@Override
public Iterator<Cell> iterator() {
return null;
}
} }
package model; package model;
public interface Grid { public interface Grid extends Iterable<Cell> {
/** /**
* Return the cell located at the given coordinates in the grid. * Return the cell located at the given coordinates in the grid.
...@@ -27,5 +27,6 @@ public interface Grid { ...@@ -27,5 +27,6 @@ public interface Grid {
* @param colorGenerator the generator used to determine the color of each cell. * @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} * The new color of {@code cell} is obtained by calling the method {@code nextColor}
*/ */
void color(ColorGenerator colorGenerator);
} }
package model;
import javafx.scene.paint.Color;
import util.RandomUtil;
import java.util.List;
import java.util.Random;
public class RandomColorGenerator implements ColorGenerator{
List<Color> colors;
Random radomGenerator;
public RandomColorGenerator(List<Color>colors,Random radomGenerator){
this.colors=colors;
this.radomGenerator=radomGenerator;
}
@Override
public Color nextColor(Cell cell) {
return RandomUtil.randomElement(this.colors, this.radomGenerator);
}
}
...@@ -7,7 +7,20 @@ import java.util.List; ...@@ -7,7 +7,20 @@ import java.util.List;
public class SquareCell extends AbstractCell{ public class SquareCell extends AbstractCell{
List<Cell> neighbours; private List<Cell> neighbours;
public SquareCell (){
Cell DEFAULT_CELL_COLOR;
}
public SquareCell(Color color){
this.setColor(color);
}
public SquareCell(Color color,List<Cell> neighbours ){
this.setColor(color);
this.neighbours= neighbours;
}
/** /**
...@@ -17,7 +30,7 @@ public class SquareCell extends AbstractCell{ ...@@ -17,7 +30,7 @@ public class SquareCell extends AbstractCell{
*/ */
@Override @Override
public List<Cell> getNeighbours() { public List<Cell> getNeighbours() {
return null; return this.neighbours;
} }
/** /**
...@@ -28,6 +41,9 @@ public class SquareCell extends AbstractCell{ ...@@ -28,6 +41,9 @@ public class SquareCell extends AbstractCell{
*/ */
@Override @Override
public void setNeighbours(List<Cell> cells) { public void setNeighbours(List<Cell> cells) {
this.neighbours=cells;
} }
......
package model;
import javafx.scene.paint.Color;
public class UniformColorGenerator implements ColorGenerator{
Color color;
public UniformColorGenerator(Color color){
this.color=color;
}
@Override
public Color nextColor(Cell cell) {
return this.color;
}
}
package model;
import javafx.scene.paint.Color;
public class UniformExceptOneGenerator implements ColorGenerator{
Color uniformColor;
Color exceptionColor;
public UniformExceptOneGenerator(Color uniformColor, Color exceptionColor){
this.uniformColor=uniformColor;
this.exceptionColor=exceptionColor;
}
int count=0;
public Color nextColor(Cell cell) {
count++;
if(count==2){
return this.exceptionColor;
}
return this.uniformColor;
}
}
package util;
import java.util.List;
import java.util.Random;
public class RandomUtil {
private RandomUtil(){};
public static <T> T randomElement(T[] elements, Random random){
return elements[random.nextInt(elements.length)];
}
public static <T> T randomElement(List<T> elements, Random random){
return elements.get(random.nextInt(elements.size()));
}
}
...@@ -8,6 +8,7 @@ import javafx.scene.layout.GridPane; ...@@ -8,6 +8,7 @@ import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.util.Duration; import javafx.util.Duration;
import model.ArrayGrid;
import model.Cell; import model.Cell;
import model.GrayGrid; import model.GrayGrid;
import model.Grid; import model.Grid;
...@@ -29,7 +30,7 @@ public class MatrixPane extends GridPane { ...@@ -29,7 +30,7 @@ public class MatrixPane extends GridPane {
this.numberOfColumns = numberOfColumns; this.numberOfColumns = numberOfColumns;
this.numberOfRows = numberOfRows; this.numberOfRows = numberOfRows;
// TODO replace by new ArrayGrid(numberOfRows, numberOfColumns) // TODO replace by new ArrayGrid(numberOfRows, numberOfColumns)
cellGrid = new GrayGrid(numberOfRows, numberOfColumns); cellGrid = new ArrayGrid(numberOfRows, numberOfColumns);
initMatrix(); initMatrix();
} }
......