Skip to content
Snippets Groups Projects
Commit 1a9ef0a5 authored by SAIDI Hatim's avatar SAIDI Hatim
Browse files

test

parent a1929313
Branches
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ public class ArrayGrid implements Grid{
else {
for (int j = 0; j < this.numberOfColumns; j++) {
for (int i = 0; i < this.numberOfRows; i++) {
cells[i][j] = new SquareCell();
cells[j][i] = new SquareCell();
}
}
}
......@@ -37,11 +37,11 @@ public class ArrayGrid implements Grid{
public void color(ColorGenerator colorGenerator){
for(Cell cell : this)
cell.setColor(colorGenerator.nextColor(new SquareCell()));
cell.setColor(colorGenerator.nextColor(cell));
}
public Iterator<Cell> iterator(){
return null ;
return new CellGridIterator(new ArrayGrid(numberOfColumns,numberOfRows));
}
......
package model;
import javafx.scene.paint.Color;
import java.util.Iterator;
public class CellGridIterator implements Iterator<Cell> {
private ArrayGrid grid;
private int x ;
private int y ;
public CellGridIterator(ArrayGrid grid){
this.grid = grid;
}
@Override
public boolean hasNext() {
if(x< grid.getNumberOfColumns()-1 ||y< grid.getNumberOfRows()-1){
return true;
}
else {
return false;
}
}
public Cell next(){
Cell cell = grid.getCell(y, x);
if (x< grid.getNumberOfRows()-1){
x = x + 1;
}
else {
y = y + 1;
x = 0;
}
return cell;
}
}
package model;
import java.util.Iterator;
public class GrayGrid implements Grid{
private final int numberOfRows;
......@@ -44,4 +46,7 @@ public class GrayGrid implements Grid{
public void color(ColorGenerator colorGenerator){
}
public Iterator<Cell> iterator(){
return null;
}
}
......@@ -30,3 +30,4 @@ public interface Grid extends Iterable<Cell>{
void color(ColorGenerator colorGenerator);
}
......@@ -3,12 +3,14 @@ package model;
import javafx.scene.paint.Color;
public class UniformColorGenerator implements ColorGenerator{
private Color color;
public UniformColorGenerator(Color color){
this.color = color;
}
public Color nextColor(Cell cell){
return cell.getColor();
return color;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment