summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-14 12:34:35 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-14 12:34:35 +0200
commitac7a1ccae0ce038c6d92feaba622b72f1a339226 (patch)
treefe75af90d3839f7e700c04939fc8577a9b063a0a /core/src/ch
parent6f1e3eeb6ca3971c3a209ec0dcbd2b5040c7db0b (diff)
downloadRustAndDust-ac7a1ccae0ce038c6d92feaba622b72f1a339226.zip
RustAndDust-ac7a1ccae0ce038c6d92feaba622b72f1a339226.tar.gz
Pawn,Unit: add boolean isHqOf(Pawn), Player add boolean canPromote(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/game/Player.java8
-rw-r--r--core/src/ch/asynk/tankontank/game/Unit.java9
3 files changed, 18 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java
index ef91544..83cd642 100644
--- a/core/src/ch/asynk/tankontank/engine/Pawn.java
+++ b/core/src/ch/asynk/tankontank/engine/Pawn.java
@@ -46,6 +46,7 @@ public abstract class Pawn implements Drawable, Disposable
public abstract int getAttackRangeFrom(Tile tile);
public abstract boolean isHq();
+ public abstract boolean isHqOf(Pawn other);
public abstract boolean isUnit();
public abstract boolean isEnemy(Pawn other);
diff --git a/core/src/ch/asynk/tankontank/game/Player.java b/core/src/ch/asynk/tankontank/game/Player.java
index ca8716c..5646311 100644
--- a/core/src/ch/asynk/tankontank/game/Player.java
+++ b/core/src/ch/asynk/tankontank/game/Player.java
@@ -110,6 +110,14 @@ public class Player implements Drawable, Disposable
return ((Unit) pawn).isEnemy(army);
}
+ public boolean canPromote(Pawn pawn)
+ {
+ if (pawn.isHq()) return false;
+ for (Pawn p: casualties)
+ if (p.isHqOf(pawn)) return true;
+ return false;
+ }
+
public void setPosition(float x, float y)
{
flag.setPosition(x, y);
diff --git a/core/src/ch/asynk/tankontank/game/Unit.java b/core/src/ch/asynk/tankontank/game/Unit.java
index a20891b..bae5fd8 100644
--- a/core/src/ch/asynk/tankontank/game/Unit.java
+++ b/core/src/ch/asynk/tankontank/game/Unit.java
@@ -129,6 +129,15 @@ public class Unit extends HeadedPawn
}
@Override
+ public boolean isHqOf(Pawn other)
+ {
+ if ((id == UnitId.GE_PANZER_IV_HQ) && (((Unit)other).id == UnitId.GE_PANZER_IV)) return true;
+ if ((id == UnitId.US_PERSHING_HQ) && (((Unit)other).id == UnitId.US_PERSHING)) return true;
+ if ((id == UnitId.US_SHERMAN_HQ) && (((Unit)other).id == UnitId.US_SHERMAN)) return true;
+ return false;
+ }
+
+ @Override
public boolean isUnit()
{
return true;