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
No related branches found
No related tags found
No related merge requests found
package model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ArrayGrid implements Grid{
private Cell [][] cells;
protected Cell [][] cells;
private int numberOfRows;
private int numberOfColumns;
......@@ -72,14 +73,19 @@ public class ArrayGrid implements Grid{
@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]);
}
// for(Cell []cell1D:cells){
// for(Cell cell:cell1D){
// cell.setColor(colorGenerator.nextColor(cell));
// }
// }
for(Cell cell:this){
cell.setColor(colorGenerator.nextColor(cell));
}
}
=======
>>>>>>> origin/main
@Override
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;
import java.util.Iterator;
public class GrayGrid implements Grid {
private final int numberOfRows;
......@@ -45,4 +47,10 @@ public class GrayGrid implements Grid{
public void color(ColorGenerator colorGenerator) {
}
@Override
public Iterator<Cell> iterator() {
return null;
}
}
package model;
public interface Grid {
public interface Grid extends Iterable<Cell>{
/**
* Return the cell located at the given coordinates in the grid.
......
......@@ -8,21 +8,10 @@ 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;
public Color nextColor(Cell cells) {
return this.color;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment