Files
artloglaby/java/org/artisanlogiciel/games/maze/XYGridIterator.java
philippe lhardy 619e9b9f19 jackson databind import
- and some reowrk to use Position more than (x,y) parameters
2021-11-03 08:30:30 +01:00

45 lines
898 B
Java

package org.artisanlogiciel.games.maze;
public class XYGridIterator {
Position min;
Position max;
Position next;
public XYGridIterator(Position min, Position max) {
this.min = min;
this.max = max;
reset();
}
public void reset()
{
this.next = new Position(min);
}
public boolean hasNext()
{
return next != null;
}
public Position next()
{
if ( next != null)
{
Position current = new Position(next);
next.doTranslate(Position.stepX);
if ( next.getX() >= max.getX()) {
if (next.getY() < max.getY() - 1) {
next.setX(min.getX()).doTranslate(Position.stepY);
} else {
next = null;
}
}
return current;
}
return null;
}
}