summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-25 22:45:48 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-25 22:45:48 +0200
commit22dc5fc68ef5e260fc85562fdf3bc875d009e121 (patch)
treeac88bbb181048c6d2df57b48abce2380b69480fb /core
parenteb7a9137c72d4c1681f7f7aae32e0dabfa83f6e3 (diff)
downloadRustAndDust-22dc5fc68ef5e260fc85562fdf3bc875d009e121.zip
RustAndDust-22dc5fc68ef5e260fc85562fdf3bc875d009e121.tar.gz
Tile, Hex: add hasTargetsFor(Pawn)
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Tile.java3
-rw-r--r--core/src/ch/asynk/tankontank/game/Hex.java14
2 files changed, 16 insertions, 1 deletions
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<Pawn> stack;
+ protected ArrayDeque<Pawn> 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<Pawn> itr = stack.iterator();
+ while(itr.hasNext())
+ if (itr.next().isEnemy(pawn)) return true;
+
+ return false;
+ }
}