summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-01-17 00:35:20 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-01-17 00:35:20 +0100
commitb005d66da410166cf88e7f38f5df587a0f07e0b0 (patch)
treea831a60dc83d4ca472a3d1931edd165bec9bbb77 /core/src
parent6175c0888b2519e39dafbc202925325a181cd39e (diff)
downloadRustAndDust-b005d66da410166cf88e7f38f5df587a0f07e0b0.zip
RustAndDust-b005d66da410166cf88e7f38f5df587a0f07e0b0.tar.gz
PossiblePaths: extract Vector3Iterator into self class PathIterator
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/tankontank/engine/PathIterator.java73
-rw-r--r--core/src/ch/asynk/tankontank/engine/PossiblePaths.java68
2 files changed, 74 insertions, 67 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/PathIterator.java b/core/src/ch/asynk/tankontank/engine/PathIterator.java
new file mode 100644
index 0000000..083f9c2
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/engine/PathIterator.java
@@ -0,0 +1,73 @@
+package ch.asynk.tankontank.engine;
+
+import java.util.List;
+import java.util.Iterator;
+
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.math.Vector3;
+
+public class PathIterator implements Iterator<Vector3>
+{
+ private Pawn pawn;
+ private Tile to;
+ private Orientation o;
+ private Orientation orientation;
+ private Tile tile;
+ private Vector2 pos = new Vector2();
+ private Vector3 v = new Vector3();
+ private int i;
+ private List<Tile> path;
+
+ public PathIterator(Pawn pawn, Tile from, Tile to, Orientation orientation, List<Tile> path)
+ {
+ this.pawn = pawn;
+ this.to = to;
+ this.tile = from;
+ this.orientation = orientation;
+ this.path = path;
+ this.o = pawn.getOrientation();
+ this.v.set(pawn.getPosition().x, pawn.getPosition().y, o.r());
+ this.i = 0;
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ if ((tile == to) && (o == orientation))
+ return false;
+ return true;
+ }
+
+ @Override
+ public Vector3 next()
+ {
+ if (tile == to) {
+ v.z = orientation.r();
+ o = orientation;
+ return v;
+ }
+ Tile nextTile;
+ if (i < path.size())
+ nextTile = path.get(i);
+ else
+ nextTile = to;
+ Orientation nextO = Orientation.fromMove(tile.col, tile.row, nextTile.col, nextTile.row);
+ if (nextO != o) {
+ v.z = nextO.r();
+ o = nextO;
+ return v;
+ }
+ pawn.getPosAt(nextTile, pos);
+ v.x = pos.x;
+ v.y = pos.y;
+ tile = nextTile;
+ i += 1;
+ return v;
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java
index 6fb31e9..fa27033 100644
--- a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java
+++ b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java
@@ -244,7 +244,7 @@ public class PossiblePaths implements Disposable, Iterable<Vector3>
@Override
public Iterator<Vector3> iterator()
{
- return new Vector3Iterator(pawn, from, to, orientation, getPath(0).tiles);
+ return new PathIterator(pawn, from, to, orientation, getPath(0).tiles);
}
private void printToErr(String what, List<Path> paths)
@@ -258,69 +258,3 @@ public class PossiblePaths implements Disposable, Iterable<Vector3>
System.err.println();
}
}
-
-class Vector3Iterator implements Iterator<Vector3>
-{
- private Pawn pawn;
- private Tile to;
- private Orientation o;
- private Orientation orientation;
- private Tile tile;
- private Vector2 pos = new Vector2();
- private Vector3 v = new Vector3();
- private int i;
- private List<Tile> path;
-
- public Vector3Iterator(Pawn pawn, Tile from, Tile to, Orientation orientation, List<Tile> path)
- {
- this.pawn = pawn;
- this.to = to;
- this.tile = from;
- this.orientation = orientation;
- this.path = path;
- this.o = pawn.getOrientation();
- this.v.set(pawn.getPosition().x, pawn.getPosition().y, o.r());
- this.i = 0;
- }
-
- @Override
- public boolean hasNext()
- {
- if ((tile == to) && (o == orientation))
- return false;
- return true;
- }
-
- @Override
- public Vector3 next()
- {
- if (tile == to) {
- v.z = orientation.r();
- o = orientation;
- return v;
- }
- Tile nextTile;
- if (i < path.size())
- nextTile = path.get(i);
- else
- nextTile = to;
- Orientation nextO = Orientation.fromMove(tile.col, tile.row, nextTile.col, nextTile.row);
- if (nextO != o) {
- v.z = nextO.r();
- o = nextO;
- return v;
- }
- pawn.getPosAt(nextTile, pos);
- v.x = pos.x;
- v.y = pos.y;
- tile = nextTile;
- i += 1;
- return v;
- }
-
- @Override
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-}