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
No results found
Select Git revision
  • main
1 result
Show changes

Commits on Source 16

10 files
+ 1165
33
Compare changes
  • Side-by-side
  • Inline

Files

+1 −1
Original line number Original line Diff line number Diff line
@@ -6,5 +6,5 @@ Il s'agit d'implémenter une version du jeu "inondation" (voir par exemple [ici]


## Membre du projet
## Membre du projet


- NOM, prénom
- EL GHAOUTI , Aymane
- NOM, prénom 
- NOM, prénom 

app/hs_err_pid7403.log

0 → 100644
+1004 −0

File added.

Preview size limit exceeded, changes collapsed.

+85 −0
Original line number Original line Diff line number Diff line
package model;

import java.util.ArrayList;
import java.util.List;


public class ArrayGrid implements Grid{

    private Cell [][] cells;
    private int numberOfRows;
    private int numberOfColumns;


    public ArrayGrid(int numberOfRows, int numberOfColumns) throws Exception{
            if(numberOfRows <= 0 || numberOfColumns <= 0){ throw new IllegalArgumentException("taille nulle ou négative");}
            this.numberOfRows = numberOfRows;
            this.numberOfColumns = numberOfColumns;
            this.cells = new Cell[numberOfRows][numberOfColumns];
            for (int i = 0; i < numberOfRows; i++){
                for (int j = 0; j < numberOfColumns; j++){
                    cells[i][j] = new SquareCell();
                }
            }

            for (int i = 0; i < numberOfRows; i++) {
                for (int j = 0; j < numberOfColumns; j++) {
                    calculateNeighbours(i,j);
                }
            }

        }
    public void calculateNeighbours( int rowIndex, int columnIndex){
        List<Cell> neighbours = new ArrayList<>();
        if (rowIndex==0){ neighbours.add(getCell(rowIndex+1,columnIndex));}
        else if (rowIndex<this.getNumberOfRows()-1) {
            neighbours.add(getCell(rowIndex-1,columnIndex));
            neighbours.add(getCell(rowIndex+1,columnIndex));
        }

        if (rowIndex==this.getNumberOfRows()-1){  neighbours.add(getCell(rowIndex-1,columnIndex)); }


        if (columnIndex==0){ neighbours.add(getCell(rowIndex,columnIndex+1));}
        else if (columnIndex<this.getNumberOfColumns()-1 ) {
            neighbours.add(getCell(rowIndex,columnIndex-1));
            neighbours.add(getCell(rowIndex,columnIndex+1));
        }
        if (columnIndex==this.getNumberOfColumns()-1){ neighbours.add(getCell(rowIndex,columnIndex-1));}


        getCell(rowIndex,columnIndex).setNeighbours(neighbours);

    }




    @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;
    }

    @Override
    public void color(ColorGenerator colorGenerator) {
        for (int i=0; i<this.numberOfRows;i++){
            for(int j=0; j<this.numberOfColumns;j++){
                colorGenerator.nextColor(cells[i][j]);
            }
        }
    }


=======
>>>>>>> origin/main
}
Original line number Original line Diff line number Diff line
@@ -40,4 +40,9 @@ public class GrayGrid implements Grid{
    public int getNumberOfColumns() {
    public int getNumberOfColumns() {
        return numnberOfColumns;
        return numnberOfColumns;
    }
    }

    @Override
    public void color(ColorGenerator colorGenerator) {

    }
}
}
Original line number Original line Diff line number Diff line
@@ -27,5 +27,5 @@ 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);
}
}
Original line number Original line Diff line number Diff line
@@ -2,6 +2,7 @@ package model;


import javafx.scene.paint.Color;
import javafx.scene.paint.Color;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.Iterator;
import java.util.List;
import java.util.List;


@@ -10,6 +11,24 @@ public class SquareCell extends AbstractCell{
    List<Cell> neighbours;
    List<Cell> neighbours;




    public SquareCell(){
        setColor(AbstractCell.DEFAULT_CELL_COLOR);
        this.neighbours= new ArrayList<Cell>();


    }
    public SquareCell( Color color){
        setColor(color);
        this.neighbours= new ArrayList<Cell>();


    }
    public SquareCell(Color color,List<Cell>neighbours){
        SquareCell Cell=new SquareCell(color);
        setNeighbours(neighbours);
    }


    /**
    /**
     * A cell is placed somewhere on a grid. Its neighbours thus depend on the underlying grid.
     * A cell is placed somewhere on a grid. Its neighbours thus depend on the underlying grid.
     *
     *
@@ -17,7 +36,7 @@ public class SquareCell extends AbstractCell{
     */
     */
    @Override
    @Override
    public List<Cell> getNeighbours() {
    public List<Cell> getNeighbours() {
        return null;
        return neighbours;
    }
    }


    /**
    /**
@@ -28,6 +47,8 @@ public class SquareCell extends AbstractCell{
     */
     */
    @Override
    @Override
    public void setNeighbours(List<Cell> cells) {
    public void setNeighbours(List<Cell> cells) {
        this.neighbours=cells;



    }
    }


Original line number Original line Diff line number Diff line
package model;

import javafx.scene.paint.Color;

import java.util.Random;

public class UniformColorGenerator implements ColorGenerator{

    private Color color;

    //code of color generator found on stackOverFlow;
    // link : https://stackoverflow.com/questions/4246351/creating-random-colour-in-java
    // but the color constructor with 3 parameter is not public, so I checked in the documentation of Color, and
    // I found that there is a constructor with 4 parameter that is public since java 8;
    // Link of the doc : https://docs.oracle.com/javase/8/javafx/api/javafx/scene/paint/Color.html
    @Override
   public Color nextColor(Cell cell) {
//        Random rand = new Random();
//        double red = rand.nextFloat();
//        double green = rand.nextFloat();
//        double blue = rand.nextFloat();
//        double opacity=rand.nextFloat();
//        Color randomColor = new Color(red, green, blue,opacity);
//        cell.setColor(randomColor);
//        return randomColor;
        return this.color;

    }
   
}
Original line number Original line Diff line number Diff line
@@ -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;
@@ -23,13 +24,12 @@ public class MatrixPane extends GridPane {
    public MatrixPane(@NamedArg("tileWidth") Double tileWidth,
    public MatrixPane(@NamedArg("tileWidth") Double tileWidth,
                      @NamedArg("tileHeight") Double tileHeight,
                      @NamedArg("tileHeight") Double tileHeight,
                      @NamedArg("numberOfColumns") Integer numberOfColumns,
                      @NamedArg("numberOfColumns") Integer numberOfColumns,
                      @NamedArg("numberOfRows") Integer numberOfRows) {
                      @NamedArg("numberOfRows") Integer numberOfRows) throws Exception {
        this.tileWidth = tileWidth;
        this.tileWidth = tileWidth;
        this.tileHeight = tileHeight;
        this.tileHeight = tileHeight;
        this.numberOfColumns = numberOfColumns;
        this.numberOfColumns = numberOfColumns;
        this.numberOfRows = numberOfRows;
        this.numberOfRows = numberOfRows;
        // TODO replace by new ArrayGrid(numberOfRows, numberOfColumns)
        cellGrid = new ArrayGrid(numberOfRows, numberOfColumns);
        cellGrid = new GrayGrid(numberOfRows, numberOfColumns);
        initMatrix();
        initMatrix();
    }
    }


Original line number Original line Diff line number Diff line
@@ -11,35 +11,25 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;


class ArrayGridTest {
class ArrayGridTest {


    // TODO

    //  uncomment
/*
    private  ArrayGrid arrayGridThreeFour;
    private  ArrayGrid arrayGridThreeFour;
    private final ArrayGrid arrayGridTwoTwo = new ArrayGrid(2,2);
    private final ArrayGrid arrayGridTwoTwo = new ArrayGrid(2,2);


    ArrayGridTest() throws Exception {
    }

    @BeforeEach
    @BeforeEach
    void initializeArrayGridThreeFour(){
    void initializeArrayGridThreeFour() throws Exception {
        arrayGridThreeFour = new ArrayGrid(3,4);
        arrayGridThreeFour = new ArrayGrid(3,4);
    }
    }




    @Test
    @Test
    void testGetCellAndGridInitialization() {
    void testGetCellAndGridInitialization() {
        assertThat(arrayGridThreeFour.getCell(0,0).getNeighbours())
        assertThat(arrayGridThreeFour.getCell(0,0).getNeighbours()).hasSize(2).containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,0), arrayGridThreeFour.getCell(0,1));
                .hasSize(2)
        assertThat(arrayGridThreeFour.getCell(1,1).getNeighbours()).hasSize(4).containsExactlyInAnyOrder(arrayGridThreeFour.getCell(0,1), arrayGridThreeFour.getCell(2,1),arrayGridThreeFour.getCell(1,2),arrayGridThreeFour.getCell(1,0));
                .containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,0), arrayGridThreeFour.getCell(0,1));
        assertThat(arrayGridThreeFour.getCell(2,3).getNeighbours()).hasSize(2).containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,3), arrayGridThreeFour.getCell(2,2));
        assertThat(arrayGridThreeFour.getCell(1,1).getNeighbours()).hasSize(4)
        assertThat(arrayGridThreeFour.getCell(2,2).getNeighbours()).hasSize(3).containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,2), arrayGridThreeFour.getCell(2,1), arrayGridThreeFour.getCell(2,3));
                .containsExactlyInAnyOrder(arrayGridThreeFour.getCell(0,1),
                        arrayGridThreeFour.getCell(2,1),
                        arrayGridThreeFour.getCell(1,2),
                        arrayGridThreeFour.getCell(1,0));
        assertThat(arrayGridThreeFour.getCell(2,3).getNeighbours()).hasSize(2)
                .containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,3),
                        arrayGridThreeFour.getCell(2,2));
        assertThat(arrayGridThreeFour.getCell(2,2).getNeighbours()).hasSize(3)
                .containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,2),
                        arrayGridThreeFour.getCell(2,1),
                        arrayGridThreeFour.getCell(2,3));
    }
    }


    @Test
    @Test
@@ -49,12 +39,12 @@ class ArrayGridTest {


    }
    }
    @Test
    @Test
    void testGetNumberOfRows() {
    void testGetNumberOfRows() throws Exception {
        assertThat(new ArrayGrid(100,200).getNumberOfRows()).isEqualTo(100);
        assertThat(new ArrayGrid(100,200).getNumberOfRows()).isEqualTo(100);
    }
    }


    @Test
    @Test
    void testGetNumberOfColumns() {
    void testGetNumberOfColumns() throws Exception {
        assertThat(new ArrayGrid(100,200).getNumberOfColumns()).isEqualTo(200);
        assertThat(new ArrayGrid(100,200).getNumberOfColumns()).isEqualTo(200);
    }
    }


@@ -76,8 +66,8 @@ class ArrayGridTest {
        }
        }
    }
    }


    @Test
   //@Test
    void testIterator() {
   /* void testIterator() {
        Iterator<Cell> iterator = arrayGridTwoTwo.iterator();
        Iterator<Cell> iterator = arrayGridTwoTwo.iterator();
        assertThat(iterator.hasNext()).isTrue();
        assertThat(iterator.hasNext()).isTrue();
        assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,0));
        assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,0));
Original line number Original line Diff line number Diff line
@@ -11,9 +11,6 @@ import static org.assertj.core.api.Assertions.assertThat;


class SquareCellTest {
class SquareCellTest {


    // TODO
    //  uncomment
    /*
    private final Cell northCell = new SquareCell(Color.NAVY);
    private final Cell northCell = new SquareCell(Color.NAVY);
    private final Cell southCell = new SquareCell(Color.SALMON);
    private final Cell southCell = new SquareCell(Color.SALMON);
    private final Cell westCell = new SquareCell(Color.WHEAT);
    private final Cell westCell = new SquareCell(Color.WHEAT);
@@ -51,5 +48,5 @@ class SquareCellTest {
        assertThat(centralCell.getNeighbours()).containsExactlyInAnyOrder(northCell,southCell);
        assertThat(centralCell.getNeighbours()).containsExactlyInAnyOrder(northCell,southCell);
    }
    }


     */

}
}
 No newline at end of file