summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-28 12:17:10 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-28 12:17:10 +0100
commita97645fa17992b0f87cbb9e9a0801e3b44479ca5 (patch)
treeac28e638b7917be366de73e5a50588951f376dfa /core
parent06ebe421c3b6dbd501a124b234a09ba1940b0b72 (diff)
downloadRustAndDust-a97645fa17992b0f87cbb9e9a0801e3b44479ca5.zip
RustAndDust-a97645fa17992b0f87cbb9e9a0801e3b44479ca5.tar.gz
Add interface Board.TileCollection extends Collection<Tile>
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java27
-rw-r--r--core/src/ch/asynk/tankontank/engine/TileList.java25
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java15
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateMove.java2
4 files changed, 40 insertions, 29 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 7b6a414..2e78ca0 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -5,6 +5,7 @@ import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
+import java.util.Collection;
import com.badlogic.gdx.Gdx;
@@ -36,6 +37,16 @@ public abstract class Board implements Disposable
public Tile getNewTile(float x, float y, int col, int row);
}
+ public interface TileCollection extends Collection<Tile>
+ {
+ public Tile first();
+ public void show();
+ public void hide();
+ public void enable(int i, boolean enable);
+ public void getPawns(Collection<Pawn> pawns);
+ public int fromNodes(Collection<SearchBoard.Node> nodes);
+ }
+
public static class Config
{
public int cols;
@@ -239,21 +250,21 @@ public abstract class Board implements Disposable
debugShapes.setTransformMatrix(prevTransform);
}
- protected int buildPossibleMoves(Pawn pawn, TileList moves)
+ protected int buildPossibleMoves(Pawn pawn, TileCollection moves)
{
Tile from = pawn.getTile();
Set<SearchBoard.Node> nodes = searchBoard.possibleMovesFrom(pawn, from.getCol(), from.getRow());
return moves.fromNodes(nodes);
}
- protected int buildPossibleTargets(Pawn pawn, TileList targets)
+ protected int buildPossibleTargets(Pawn pawn, TileCollection targets)
{
Tile from = pawn.getTile();
List<SearchBoard.Node> nodes = searchBoard.possibleTargetsFrom(pawn, from.getCol(), from.getRow());
return targets.fromNodes(nodes);
}
- protected int buildPossibleTargets(Pawn pawn, Iterator<Pawn> units, TileList targets)
+ protected int buildPossibleTargets(Pawn pawn, Iterator<Pawn> units, TileCollection targets)
{
Tile from = pawn.getTile();
targets.clear();
@@ -267,7 +278,7 @@ public abstract class Board implements Disposable
return targets.size();
}
- protected int buildMoveAssists(Pawn pawn, TileList assists)
+ protected int buildMoveAssists(Pawn pawn, TileCollection assists)
{
assists.clear();
setAdjacentTiles(pawn.getTile(), neighbours);
@@ -283,7 +294,7 @@ public abstract class Board implements Disposable
return assists.size();
}
- protected int buildAttackAssists(Pawn pawn, Pawn target, Iterator<Pawn> units, TileList assists)
+ protected int buildAttackAssists(Pawn pawn, Pawn target, Iterator<Pawn> units, TileCollection assists)
{
assists.clear();
Tile to = target.getTile();
@@ -300,7 +311,7 @@ public abstract class Board implements Disposable
return assists.size();
}
- private int nodesToSet(List<ArrayList<SearchBoard.Node>> nodes, TileList tiles)
+ private int nodesToSet(List<ArrayList<SearchBoard.Node>> nodes, TileCollection tiles)
{
tiles.clear();
@@ -316,14 +327,14 @@ public abstract class Board implements Disposable
return nodes.size();
}
- protected int buildPossiblePaths(Pawn pawn, Tile to, TileList tiles)
+ protected int buildPossiblePaths(Pawn pawn, Tile to, TileCollection tiles)
{
Tile from = pawn.getTile();
paths = searchBoard.possiblePaths(pawn, from.getCol(), from.getRow(), to.getCol(), to.getRow());
return nodesToSet(paths, tiles);
}
- protected int possiblePathsFilterToggle(Tile tile, TileList tiles)
+ protected int possiblePathsFilterToggle(Tile tile, TileCollection tiles)
{
paths = searchBoard.possiblePathsFilterToggle(tile.getCol(), tile.getRow());
return nodesToSet(paths, tiles);
diff --git a/core/src/ch/asynk/tankontank/engine/TileList.java b/core/src/ch/asynk/tankontank/engine/TileList.java
index b26a5e8..0e56aac 100644
--- a/core/src/ch/asynk/tankontank/engine/TileList.java
+++ b/core/src/ch/asynk/tankontank/engine/TileList.java
@@ -4,7 +4,7 @@ import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
-public class TileList extends ArrayList<Tile>
+public class TileList extends ArrayList<Tile> implements Board.TileCollection
{
private final Board board;
private int overlay;
@@ -16,15 +16,9 @@ public class TileList extends ArrayList<Tile>
this.overlay = overlay;
}
- public int fromNodes(Collection<SearchBoard.Node> nodes)
+ public Tile first()
{
- clear();
- for (SearchBoard.Node node : nodes) {
- Tile tile = board.getTile(node.col, node.row);
- add(tile);
- }
-
- return size();
+ return get(0);
}
public void show()
@@ -43,10 +37,21 @@ public class TileList extends ArrayList<Tile>
board.enableOverlayOn(tile, i, enable);
}
- public void getPawns(List<Pawn> pawns)
+ public void getPawns(Collection<Pawn> pawns)
{
pawns.clear();
for (Tile tile : this)
pawns.add(tile.getTopPawn());
}
+
+ public int fromNodes(Collection<SearchBoard.Node> nodes)
+ {
+ clear();
+ for (SearchBoard.Node node : nodes) {
+ Tile tile = board.getTile(node.col, node.row);
+ add(tile);
+ }
+
+ return size();
+ }
}
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 56b5db9..ab8e83c 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -21,11 +21,11 @@ public abstract class Map extends Board
{
private final Ctrl ctrl;
- public final HexList possibleMoves; // HexSet
- public final HexList possibleTargets; // PawnSet
- public final HexList possiblePaths; // class Move
- public final HexList moveAssists; // PawnSet
- public final HexList attackAssists; // PawnSet
+ public final Board.TileCollection possibleMoves;
+ public final Board.TileCollection possibleTargets;
+ public final Board.TileCollection possiblePaths;
+ public final Board.TileCollection moveAssists;
+ public final Board.TileCollection attackAssists;
public final ArrayList<Pawn> activablePawns = new ArrayList<Pawn>(7); // PawnSet
public final ArrayList<Pawn> activatedPawns = new ArrayList<Pawn>(7); // PawnSet
@@ -71,11 +71,6 @@ public abstract class Map extends Board
return (Hex) getTile(col, row);
}
- public Hex getFirstMoveAssist()
- {
- return (Hex) moveAssists.get(0);
- }
-
public void selectHex(Hex hex, boolean enable)
{
enableOverlayOn(hex, Hex.SELECT, enable);
diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java
index 7762c92..eb462db 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateMove.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java
@@ -25,7 +25,7 @@ public class StateMove extends StateCommon
} else {
// back from rotation -> use the above and unmodified activePawn
if ((activePawn == selectedPawn) || !selectedPawn.canMove()) {
- upHex = map.getFirstMoveAssist();
+ upHex = (Hex) map.moveAssists.first();
activePawn = upHex.getTopPawn();
} else {
upHex = selectedHex;