diff options
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r-- | core/src/ch/asynk/rustanddust/engine/Move.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/Move.java b/core/src/ch/asynk/rustanddust/engine/Move.java index 077823f..3ff7c54 100644 --- a/core/src/ch/asynk/rustanddust/engine/Move.java +++ b/core/src/ch/asynk/rustanddust/engine/Move.java @@ -7,6 +7,52 @@ import com.badlogic.gdx.math.Vector3; public class Move extends Path implements Iterable<Vector3> { + public class TileIterator implements Iterator<Tile> + { + private int i; + private Tile tile; + private Move move; + + public TileIterator(Move move) + { + this.i = -1; + this.tile = null; + this.move = move; + } + + @Override + public boolean hasNext() + { + if (tile == move.to) + return false; + return true; + } + + @Override + public Tile next() + { + if (tile == move.to) + throw new java.util.NoSuchElementException(); + + if (tile != null) { + i += 1; + if (i < move.tiles.size()) + tile = move.tiles.get(i); + else + tile = move.to; + } else + tile = move.from; + + return tile; + } + + @Override + public void remove() + { + throw new UnsupportedOperationException(); + } + } + public enum MoveType { REGULAR, @@ -141,6 +187,11 @@ public class Move extends Path implements Iterable<Vector3> return steps; } + public Iterator<Tile> tileIterator() + { + return new TileIterator(this); + } + @Override public String toString() { |