diff options
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 21 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Map.java | 24 |
2 files changed, 19 insertions, 26 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 160b8c7..72adfce 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -316,35 +316,32 @@ public abstract class Board implements Disposable points.clear(); } - private int nodesToSet(List<ArrayList<SearchBoard.Node>> nodes, Set<GridPoint2> points) + private int nodesToSet(List<ArrayList<SearchBoard.Node>> nodes, TileList tiles) { - for (GridPoint2 point : points) - gridPoint2Pool.free(point); - points.clear(); + tiles.clear(); for (ArrayList<SearchBoard.Node> path : nodes) { for (int i = 1, n = (path.size() - 1); i < n; i++) { SearchBoard.Node node = path.get(i); - GridPoint2 point = gridPoint2Pool.obtain(); - point.set(node.col, node.row); - if (!points.add(point)) - gridPoint2Pool.free(point); + Tile tile = getTile(node.col, node.row); + if (!tiles.contains(tile)) + tiles.add(tile); } } return nodes.size(); } - protected int buildPossiblePaths(Pawn pawn, GridPoint2 from, GridPoint2 to, Set<GridPoint2> points) + protected int buildPossiblePaths(Pawn pawn, GridPoint2 from, GridPoint2 to, TileList tiles) { paths = searchBoard.possiblePaths(pawn, from.x, from.y, to.x, to.y); - return nodesToSet(paths, points); + return nodesToSet(paths, tiles); } - protected int possiblePathsFilterToggle(GridPoint2 coords, Set<GridPoint2> points) + protected int possiblePathsFilterToggle(GridPoint2 coords, TileList tiles) { paths = searchBoard.possiblePathsFilterToggle(coords.x, coords.y); - return nodesToSet(paths, points); + return nodesToSet(paths, tiles); } protected void clearCoordinateVector(ArrayList<Vector3> points) diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 94b66ca..762b6d9 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -29,7 +29,7 @@ public abstract class Map extends Board private final HexList possibleTargets; private final HexList moveAssists; private final HexList attackAssists; - private final HashSet<GridPoint2> possiblePaths = new HashSet<GridPoint2>(10); + private final HexList possiblePaths; private final ArrayList<Pawn> activablePawns = new ArrayList<Pawn>(7); private final ArrayList<Pawn> activatedPawns = new ArrayList<Pawn>(7); @@ -47,6 +47,7 @@ public abstract class Map extends Board this.explosions = new SpriteAnimation(game.manager.get("data/explosions.png", Texture.class), 16, 8, 15); setup(); possibleMoves = new HexList(this, 40); + possiblePaths = new HexList(this, 10); possibleTargets = new HexList(this, 10); moveAssists = new HexList(this, 6); attackAssists = new HexList(this, 6); @@ -63,17 +64,17 @@ public abstract class Map extends Board { possibleMoves.clear(); possibleTargets.clear(); + possiblePaths.clear(); moveAssists.clear(); attackAssists.clear(); activablePawns.clear(); activatedPawns.clear(); - clearPointSet(possiblePaths); clearCoordinateVector(finalPath); } public void clearPossiblePaths() { - clearPointSet(possiblePaths); + possiblePaths.clear(); } public void clearPossibleTargets() @@ -140,7 +141,7 @@ public abstract class Map extends Board public boolean isInPossiblePaths(GridPoint2 hex) { - return possiblePaths.contains(hex); + return possiblePaths.contains(getHex(hex.x, hex.y)); } public boolean isInPossibleTargets(GridPoint2 hex) @@ -188,22 +189,17 @@ public abstract class Map extends Board public void showPossiblePaths(boolean enable, boolean keepFinal) { if (keepFinal) { - for(GridPoint2 hex : possiblePaths) - enableOverlayOn(hex, Hex.MOVE1, enable); + possiblePaths.enable(Hex.MOVE1, enable); } else { - for(GridPoint2 hex : possiblePaths) { - enableOverlayOn(hex, Hex.MOVE1, enable); - enableOverlayOn(hex, Hex.MOVE2, false); - } + possiblePaths.enable(Hex.MOVE1, enable); + possiblePaths.enable(Hex.MOVE2, false); } } public void showFinalPath(GridPoint2 dst, boolean enable) { - for(GridPoint2 hex : possiblePaths) { - enableOverlayOn(hex, Hex.MOVE1, false); - enableOverlayOn(hex, Hex.MOVE2, enable); - } + possiblePaths.enable(Hex.MOVE1, false); + possiblePaths.enable(Hex.MOVE2, enable); } public void showDirections(GridPoint2 hex, boolean enable) |