summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-04 11:07:15 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-04 11:07:15 +0200
commitc5d03a7bc3ec6b23c23d7920485bb222f11903ab (patch)
treecf4073950de195f1d7c78c05ce91aa5b1da888e8 /core/src/ch
parent819788ddd1842755253d723416affd47f1a236af (diff)
downloadRustAndDust-c5d03a7bc3ec6b23c23d7920485bb222f11903ab.zip
RustAndDust-c5d03a7bc3ec6b23c23d7920485bb222f11903ab.tar.gz
Tile: cleanup, add boolean hasTargetsFor(Pawn pawn)
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Pawn.java1
-rw-r--r--core/src/ch/asynk/tankontank/engine/Tile.java35
2 files changed, 26 insertions, 10 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java
index 989c57f..446c3cd 100644
--- a/core/src/ch/asynk/tankontank/engine/Pawn.java
+++ b/core/src/ch/asynk/tankontank/engine/Pawn.java
@@ -32,6 +32,7 @@ public abstract class Pawn implements Drawable, Disposable
public abstract int getRoadMarchBonus();
public abstract boolean isUnit();
public abstract boolean isEnemy(Pawn other);
+ public abstract boolean canAttack(Pawn other);
public abstract int getAngleOfAttack();
public abstract int getAttackRangeFrom(Tile tile);
diff --git a/core/src/ch/asynk/tankontank/engine/Tile.java b/core/src/ch/asynk/tankontank/engine/Tile.java
index 566f0cc..3495ada 100644
--- a/core/src/ch/asynk/tankontank/engine/Tile.java
+++ b/core/src/ch/asynk/tankontank/engine/Tile.java
@@ -1,6 +1,5 @@
package ch.asynk.tankontank.engine;
-import java.util.List;
import java.util.Iterator;
import java.util.ArrayDeque;
@@ -14,14 +13,13 @@ import ch.asynk.tankontank.engine.gfx.StackedImages;
public abstract class Tile implements Drawable
{
- private StackedImages overlays;
- protected ArrayDeque<Pawn> stack;
private Vector2 center;
+ private StackedImages overlays;
+ private ArrayDeque<Pawn> stack;
+ public abstract int costFrom(Pawn pawn, Orientation side, boolean road);
public abstract boolean atLeastOneMove(Pawn pawn);
public abstract boolean road(Orientation side);
- public abstract int costFrom(Pawn pawn, Orientation side, boolean road);
- public abstract boolean hasTargetsFor(Pawn pawn);
public abstract boolean isOffMap();
public abstract boolean blockLineOfSightFrom(Tile tile);
@@ -42,6 +40,17 @@ public abstract class Tile implements Drawable
return center;
}
+ public boolean isEmpty()
+ {
+ if (stack == null) return true;
+ return stack.isEmpty();
+ }
+
+ public Iterator<Pawn> getIterator()
+ {
+ return stack.iterator();
+ }
+
public int push(Pawn pawn)
{
if (stack == null) stack = new ArrayDeque<Pawn>();
@@ -57,14 +66,14 @@ public abstract class Tile implements Drawable
public Pawn getTopPawn()
{
- if ((stack == null) || (stack.size() == 0)) return null;
+ if (isEmpty()) return null;
return stack.getFirst();
}
public boolean hasUnits()
{
if (isEmpty()) return false;
- Iterator<Pawn> itr = stack.iterator();
+ Iterator<Pawn> itr = getIterator();
while(itr.hasNext()) {
if (itr.next().isUnit())
return true;
@@ -72,10 +81,16 @@ public abstract class Tile implements Drawable
return false;
}
- public boolean isEmpty()
+ public boolean hasTargetsFor(Pawn pawn)
{
- if (stack == null) return true;
- return (stack.size() == 0);
+ if (isEmpty()) return false;
+ Iterator<Pawn> itr = getIterator();
+ while(itr.hasNext()) {
+ Pawn target = itr.next();
+ if (pawn.canAttack(target)) return true;
+ }
+
+ return false;
}
public boolean mustBeDrawn()