Skip to content
Snippets Groups Projects
Commit 2640a150 authored by NGUYEN Thi hang's avatar NGUYEN Thi hang
Browse files

fait à 2/11

parent 1e7af8c0
No related branches found
No related tags found
No related merge requests found
package model;
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 new CellGridIterator();
}
}
package model;
public class CellGridIterator implements Iterator<Cell>{
ArrayGrid grid;
Iterator<Cell> it=grid.iterator();
int indixRow;
int indixColum;
public CellGridIterator(ArrayGrid grid) {
this.grid = grid;
}
public SquareCell next() {
int i = 0;
while (i < grid.getNumberOfRows()) {
while (it.hasNext()) {
return it.next();
}
i++;
}
}
public boolean hasNext( ){
int n;
if(n>= grid.getNumberOfColumns()|| n>= grid.getNumberOfRows()) return false;
}
}
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.
......
package model;
public interface Iterator<Cell> {
}
...@@ -7,7 +7,19 @@ import java.util.List; ...@@ -7,7 +7,19 @@ 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;
}
public SquareCell (){ public SquareCell (){
Cell DEFAULT_CELL_COLOR; Cell DEFAULT_CELL_COLOR;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment