Skip to content
Snippets Groups Projects
Commit b38fff22 authored by dragapsy's avatar dragapsy
Browse files

Tache 3 (6.1 + Constructeur CellGridIterator(ArrayGrid grid))

parent 09169c50
Branches
No related tags found
No related merge requests found
package model; package model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
public class ArrayGrid implements Grid{ public class ArrayGrid implements Grid{
private Cell [][] cells; protected Cell [][] cells;
private int numberOfRows; private int numberOfRows;
private int numberOfColumns; private int numberOfColumns;
...@@ -72,14 +73,19 @@ public class ArrayGrid implements Grid{ ...@@ -72,14 +73,19 @@ public class ArrayGrid implements Grid{
@Override @Override
public void color(ColorGenerator colorGenerator) { public void color(ColorGenerator colorGenerator) {
for (int i=0; i<this.numberOfRows;i++){ // for(Cell []cell1D:cells){
for(int j=0; j<this.numberOfColumns;j++){ // for(Cell cell:cell1D){
colorGenerator.nextColor(cells[i][j]); // cell.setColor(colorGenerator.nextColor(cell));
} // }
// }
for(Cell cell:this){
cell.setColor(colorGenerator.nextColor(cell));
} }
} }
======= @Override
>>>>>>> origin/main public Iterator<Cell> iterator() {
return new CellGridIterator(this);
}
} }
package model;
import java.util.Iterator;
public class CellGridIterator implements Iterator<Cell> {
ArrayGrid arrayGrid;
private int rowIndex,columnIndex;
private Cell [][]cells;
public CellGridIterator(ArrayGrid grid) {
arrayGrid=grid;
cells=grid.cells;
}
@Override
public boolean hasNext() {
return false;
}
@Override
public Cell next() {
return null;
}
}
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;
...@@ -45,4 +47,10 @@ public class GrayGrid implements Grid{ ...@@ -45,4 +47,10 @@ public class GrayGrid implements Grid{
public void color(ColorGenerator colorGenerator) { 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.
......
...@@ -8,21 +8,10 @@ public class UniformColorGenerator implements ColorGenerator{ ...@@ -8,21 +8,10 @@ public class UniformColorGenerator implements ColorGenerator{
private Color color; 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 @Override
public Color nextColor(Cell cell) { public Color nextColor(Cell cells) {
// 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; return this.color;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment