summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-12-28 17:57:53 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-12-28 17:57:53 +0100
commit34d611a9a342a8f311ed51fab1c9eb8cc84abcaa (patch)
tree8c267572451973b0114f9691ce94d40c63ecec10 /core
parentaecdc3c1d331c774650ed17013c8143a73717aaf (diff)
downloadRustAndDust-34d611a9a342a8f311ed51fab1c9eb8cc84abcaa.zip
RustAndDust-34d611a9a342a8f311ed51fab1c9eb8cc84abcaa.tar.gz
Move: add TileIterator
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/Move.java51
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()
{