summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java70
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java4
2 files changed, 34 insertions, 40 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 6505ee8..9015394 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -28,6 +28,7 @@ import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation;
public abstract class Board implements Disposable
{
private final GridPoint2 neighbours[] = new GridPoint2[6];
+ protected List<ArrayList<SearchBoard.Node>> paths;
public interface TileBuilder
{
@@ -64,8 +65,7 @@ public abstract class Board implements Disposable
private Config cfg;
private Tile[] tiles;
- // protected for tests
- protected SearchBoard searchBoard;
+ private SearchBoard searchBoard;
private Image image;
private boolean transform;
@@ -80,10 +80,11 @@ public abstract class Board implements Disposable
private final LinkedHashSet<Tile> tilesToDraw = new LinkedHashSet<Tile>();
private final LinkedHashSet<Pawn> pawnsToDraw = new LinkedHashSet<Pawn>();
- protected Board()
+ protected Board(int cols, int rows)
{
for (int i = 0; i < 6; i++)
neighbours[i] = new GridPoint2(-1, -1);
+ searchBoard = new SearchBoard(this, cols, rows);
}
@Override
@@ -128,6 +129,28 @@ public abstract class Board implements Disposable
neighbours[i] = new GridPoint2(-1, -1);
}
+ public float getWidth()
+ {
+ return image.getWidth();
+ }
+
+ public float getHeight()
+ {
+ return image.getHeight();
+ }
+
+ public void setPosition(float x, float y)
+ {
+ image.setPosition(x, y);
+ if ((x != 0.0f) || (y != 0.0f)) {
+ transform = true;
+ prevTransform = new Matrix4();
+ nextTransform = new Matrix4();
+ nextTransform.translate(x, y, 0);
+ } else
+ transform = false;
+ }
+
public Tile getTile(GridPoint2 coords)
{
return getTile(coords.x, coords.y);
@@ -174,28 +197,6 @@ public abstract class Board implements Disposable
neighbours[5].set((coords.x - 1), (coords.y - 1));
}
- public float getWidth()
- {
- return image.getWidth();
- }
-
- public float getHeight()
- {
- return image.getHeight();
- }
-
- public void setPosition(float x, float y)
- {
- image.setPosition(x, y);
- if ((x != 0.0f) || (y != 0.0f)) {
- transform = true;
- prevTransform = new Matrix4();
- nextTransform = new Matrix4();
- nextTransform.translate(x, y, 0);
- } else
- transform = false;
- }
-
private void addPawnAnimation(Pawn pawn, AnimationSequence seq)
{
pawnsToDraw.add(pawn);
@@ -367,17 +368,15 @@ public abstract class Board implements Disposable
return nodes.size();
}
- // public for tests
- public int possiblePaths(Pawn pawn, GridPoint2 from, GridPoint2 to, Set<GridPoint2> points)
+ protected int buildPossiblePaths(Pawn pawn, GridPoint2 from, GridPoint2 to, Set<GridPoint2> points)
{
- List<ArrayList<SearchBoard.Node>> paths = searchBoard.possiblePaths(pawn, from.x, from.y, to.x, to.y);
+ paths = searchBoard.possiblePaths(pawn, from.x, from.y, to.x, to.y);
return nodesToSet(paths, points);
}
- // public for tests
- public int possiblePathsFilterToggle(GridPoint2 coords, Set<GridPoint2> points)
+ protected int possiblePathsFilterToggle(GridPoint2 coords, Set<GridPoint2> points)
{
- List<ArrayList<SearchBoard.Node>> paths = searchBoard.possiblePathsFilterToggle(coords.x, coords.y);
+ paths = searchBoard.possiblePathsFilterToggle(coords.x, coords.y);
return nodesToSet(paths, points);
}
@@ -388,15 +387,10 @@ public abstract class Board implements Disposable
points.clear();
}
- protected int getCoordinatePath(Pawn pawn, ArrayList<Vector3> path, Orientation finalOrientation)
+ protected int getCoordinatePath(Pawn pawn, int idx, ArrayList<Vector3> path, Orientation finalOrientation)
{
- List<ArrayList<SearchBoard.Node>> paths = searchBoard.possiblePaths();
-
clearCoordinateVector(path);
- if (paths.size() != 1)
- return 0;
-
Vector2 tmpCoords = new Vector2();
GridPoint2 tmpHex = gridPoint2Pool.obtain();
@@ -405,7 +399,7 @@ public abstract class Board implements Disposable
v.set(p.x, p.y, 0f);
Orientation prevOrientation = pawn.getOrientation();
- ArrayList<SearchBoard.Node> nodes = paths.get(0);
+ ArrayList<SearchBoard.Node> nodes = paths.get(idx);
SearchBoard.Node prevNode = nodes.get(0);
// Gdx.app.debug("Board", "getCoordinatePath()");
// Gdx.app.debug("Board", " " + prevNode);
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index ae859eb..351701f 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -150,7 +150,7 @@ public abstract class Map extends Board
public int buildPossiblePaths(Pawn pawn, GridPoint2 from, GridPoint2 to)
{
- return possiblePaths(pawn, from, to, possiblePaths);
+ return buildPossiblePaths(pawn, from, to, possiblePaths);
}
public int possiblePathsPointToggle(GridPoint2 hex)
@@ -172,7 +172,7 @@ public abstract class Map extends Board
public void movePawn(Pawn pawn, Orientation o)
{
- int s = getCoordinatePath(pawn, finalPath, o);
+ int s = getCoordinatePath(pawn, 0, finalPath, o);
if (s > 0) {
movePawn(pawn, finalPath, RunnableAnimation.get(pawn, new Runnable() {
@Override