diff options
Diffstat (limited to 'core/src/ch/asynk/tankontank/engine')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 12 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/PawnSet.java (renamed from core/src/ch/asynk/tankontank/engine/TileList.java) | 31 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/TileSet.java | 2 |
3 files changed, 27 insertions, 18 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 2e78ca0..09cfc7d 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -43,7 +43,17 @@ public abstract class Board implements Disposable public void show(); public void hide(); public void enable(int i, boolean enable); - public void getPawns(Collection<Pawn> pawns); + public void collectPawns(PawnCollection pawns); + public int fromNodes(Collection<SearchBoard.Node> nodes); + } + + public interface PawnCollection extends Collection<Pawn> + { + public Pawn first(); + public void show(); + public void hide(); + public void enable(int i, boolean enable); + public void collectTiles(TileCollection tiles); public int fromNodes(Collection<SearchBoard.Node> nodes); } diff --git a/core/src/ch/asynk/tankontank/engine/TileList.java b/core/src/ch/asynk/tankontank/engine/PawnSet.java index 6c5b2e5..f4e1c27 100644 --- a/core/src/ch/asynk/tankontank/engine/TileList.java +++ b/core/src/ch/asynk/tankontank/engine/PawnSet.java @@ -2,24 +2,24 @@ package ch.asynk.tankontank.engine; import java.util.Iterator; import java.util.Collection; -import java.util.List; -import java.util.ArrayList; +import java.util.LinkedHashSet; -public class TileList extends ArrayList<Tile> implements Board.TileCollection +public class PawnSet extends LinkedHashSet<Pawn> implements Board.PawnCollection { private final Board board; private int overlay; - public TileList(Board board, int overlay, int n) + public PawnSet(Board board, int overlay, int n) { super(n); this.board = board; this.overlay = overlay; } - public Tile first() + public Pawn first() { - return get(0); + if (isEmpty()) return null; + return iterator().next(); } public void show() @@ -34,18 +34,15 @@ public class TileList extends ArrayList<Tile> implements Board.TileCollection public void enable(int i, boolean enable) { - for (Tile tile : this) - board.enableOverlayOn(tile, i, enable); + for (Pawn pawn : this) + pawn.enableOverlay(i, enable); } - public void getPawns(Collection<Pawn> pawns) + public void collectTiles(Board.TileCollection tiles) { - pawns.clear(); - for (Tile tile : this) { - Iterator<Pawn> itr = tile.iterator(); - while(itr.hasNext()) - pawns.add(itr.next()); - } + tiles.clear(); + for (Pawn pawn : this) + tiles.add(pawn.getTile()); } public int fromNodes(Collection<SearchBoard.Node> nodes) @@ -53,7 +50,9 @@ public class TileList extends ArrayList<Tile> implements Board.TileCollection clear(); for (SearchBoard.Node node : nodes) { Tile tile = board.getTile(node.col, node.row); - add(tile); + Iterator<Pawn> pawns = tile.iterator(); + while(pawns.hasNext()) + add(pawns.next()); } return size(); diff --git a/core/src/ch/asynk/tankontank/engine/TileSet.java b/core/src/ch/asynk/tankontank/engine/TileSet.java index 5a75b5d..04f726b 100644 --- a/core/src/ch/asynk/tankontank/engine/TileSet.java +++ b/core/src/ch/asynk/tankontank/engine/TileSet.java @@ -38,7 +38,7 @@ public class TileSet extends LinkedHashSet<Tile> implements Board.TileCollection board.enableOverlayOn(tile, i, enable); } - public void getPawns(Collection<Pawn> pawns) + public void collectPawns(Board.PawnCollection pawns) { pawns.clear(); for (Tile tile : this) { |