From 4b28bdb354e063d9bddf864d6a902957d01382f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 28 Oct 2014 12:20:12 +0100 Subject: add TileSet extends LinkedHashSet implements Board.TileCollection --- core/src/ch/asynk/tankontank/engine/TileSet.java | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 core/src/ch/asynk/tankontank/engine/TileSet.java diff --git a/core/src/ch/asynk/tankontank/engine/TileSet.java b/core/src/ch/asynk/tankontank/engine/TileSet.java new file mode 100644 index 0000000..71fd39d --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/TileSet.java @@ -0,0 +1,57 @@ +package ch.asynk.tankontank.engine; + +import java.util.Set; +import java.util.LinkedHashSet; +import java.util.Collection; + +public class TileSet extends LinkedHashSet implements Board.TileCollection +{ + private final Board board; + private int overlay; + + public TileSet(Board board, int overlay, int n) + { + super(n); + this.board = board; + this.overlay = overlay; + } + + public Tile first() + { + return iterator().next(); + } + + public void show() + { + enable(overlay, true); + } + + public void hide() + { + enable(overlay, false); + } + + public void enable(int i, boolean enable) + { + for (Tile tile : this) + board.enableOverlayOn(tile, i, enable); + } + + public void getPawns(Collection pawns) + { + pawns.clear(); + for (Tile tile : this) + pawns.add(tile.getTopPawn()); + } + + public int fromNodes(Collection nodes) + { + clear(); + for (SearchBoard.Node node : nodes) { + Tile tile = board.getTile(node.col, node.row); + add(tile); + } + + return size(); + } +} -- cgit v1.1-2-g2b99