Skip to content
Snippets Groups Projects
CellGridIterator.java 725 B
Newer Older
  • Learn to ignore specific revisions
  • SAIDI Hatim's avatar
    SAIDI Hatim committed
    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;
    
       }
    }