summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/ch/asynk/tankontank/engine/Pawn.java5
-rw-r--r--core/src/ch/asynk/tankontank/game/Unit.java14
2 files changed, 15 insertions, 4 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java
index 991e97e..16a74e6 100644
--- a/core/src/ch/asynk/tankontank/engine/Pawn.java
+++ b/core/src/ch/asynk/tankontank/engine/Pawn.java
@@ -25,6 +25,10 @@ public abstract class Pawn implements Moveable, Disposable
{
}
+ public interface PawnId
+ {
+ }
+
public class Engagement
{
Pawn target;
@@ -108,6 +112,7 @@ public abstract class Pawn implements Moveable, Disposable
public abstract int getEngagementRangeFrom(Tile tile);
public abstract boolean isUnit();
+ public abstract boolean isA(PawnId id);
public abstract boolean isA(PawnType type);
public abstract boolean isHq();
public abstract boolean isHqOf(Pawn other);
diff --git a/core/src/ch/asynk/tankontank/game/Unit.java b/core/src/ch/asynk/tankontank/game/Unit.java
index bcb9e3c..468589e 100644
--- a/core/src/ch/asynk/tankontank/game/Unit.java
+++ b/core/src/ch/asynk/tankontank/game/Unit.java
@@ -27,7 +27,7 @@ public class Unit extends HeadedPawn
ARTILLERY
}
- public enum UnitId
+ public enum UnitId implements Pawn.PawnId
{
GE_AT_GUN("German Anti-Tank Gun"),
GE_INFANTRY("German Infantry"),
@@ -154,6 +154,12 @@ public class Unit extends HeadedPawn
}
@Override
+ public boolean isA(PawnId i)
+ {
+ return (id == i);
+ }
+
+ @Override
public boolean isA(PawnType t)
{
return (type == t);
@@ -168,9 +174,9 @@ 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;
+ if (isA(UnitId.GE_PANZER_IV_HQ) && other.isA(UnitId.GE_PANZER_IV)) return true;
+ if (isA(UnitId.US_PERSHING_HQ) && other.isA(UnitId.US_PERSHING)) return true;
+ if (isA(UnitId.US_SHERMAN_HQ) && other.isA(UnitId.US_SHERMAN)) return true;
return false;
}