From 22dc5fc68ef5e260fc85562fdf3bc875d009e121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 25 Sep 2014 22:45:48 +0200 Subject: Tile, Hex: add hasTargetsFor(Pawn) --- core/src/ch/asynk/tankontank/engine/Tile.java | 3 ++- core/src/ch/asynk/tankontank/game/Hex.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/ch/asynk/tankontank/engine/Tile.java b/core/src/ch/asynk/tankontank/engine/Tile.java index 9db279f..7998827 100644 --- a/core/src/ch/asynk/tankontank/engine/Tile.java +++ b/core/src/ch/asynk/tankontank/engine/Tile.java @@ -13,12 +13,13 @@ import ch.asynk.tankontank.engine.gfx.StackedImages; public abstract class Tile implements BasicDrawable { private StackedImages overlays; - private ArrayDeque stack; + protected ArrayDeque stack; public abstract Tile getNewAt(float x, float y); public abstract boolean atLeastOneMove(Pawn pawn); public abstract boolean road(Board.Orientation side); public abstract int costFrom(Pawn pawn, Board.Orientation side, boolean road); + public abstract boolean hasTargetsFor(Pawn pawn); public Tile(TextureAtlas atlas) { diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java index 161ed44..c8c7361 100644 --- a/core/src/ch/asynk/tankontank/game/Hex.java +++ b/core/src/ch/asynk/tankontank/game/Hex.java @@ -1,5 +1,7 @@ package ch.asynk.tankontank.game; +import java.util.Iterator; + import com.badlogic.gdx.graphics.g2d.TextureAtlas; import ch.asynk.tankontank.engine.Pawn; @@ -82,4 +84,16 @@ public class Hex extends Tile return c; } + + @Override + public boolean hasTargetsFor(Pawn pawn) + { + if (!occupied()) return false; + + Iterator itr = stack.iterator(); + while(itr.hasNext()) + if (itr.next().isEnemy(pawn)) return true; + + return false; + } } -- cgit v1.1-2-g2b99