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

THN

parent 2640a150
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,6 @@ public class ArrayGrid implements Grid{ ...@@ -33,6 +33,6 @@ public class ArrayGrid implements Grid{
} }
} }
public Iterator<Cell> iterator(){ public Iterator<Cell> iterator(){
return new CellGridIterator(); return new CellGridIterator(this);
} }
} }
...@@ -2,29 +2,25 @@ package model; ...@@ -2,29 +2,25 @@ package model;
public class CellGridIterator implements Iterator<Cell>{ public class CellGridIterator implements Iterator<Cell>{
ArrayGrid grid; ArrayGrid grid;
Iterator<Cell> it=grid.iterator();
int indixRow; int indixRow;
int indixColum; int indixColum;
public CellGridIterator(ArrayGrid grid) { public CellGridIterator(ArrayGrid grid) {
this.grid = grid; this.grid = grid;
this.indixColum=0;
this.indixRow=0;
} }
public SquareCell next() { public Cell next() {
int i = 0; final Cell result = grid.getCell(indixRow, indixColum);
while (i < grid.getNumberOfRows()) { indixColum = (indixColum +1) % grid.getNumberOfColumns();
if(indixColum == 0){
while (it.hasNext()) { indixRow++;
return it.next();
}
i++;
} }
} return result;
public boolean hasNext( ){
int n;
if(n>= grid.getNumberOfColumns()|| n>= grid.getNumberOfRows()) return false;
} }
public boolean hasNext(){
return this.indixColum < this.grid.getNumberOfColumns() && indixRow < this.grid.getNumberOfRows();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment