diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-17 15:18:32 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-17 15:18:32 +0100 |
commit | 793af2956fc0daa67585cae95489075788f72713 (patch) | |
tree | ce372ecbd83dabceb01844b495a9eced3c6af7df /core/src | |
parent | ac99957ad09592e422f3e3cd0752f3e00d610ed5 (diff) | |
download | RustAndDust-793af2956fc0daa67585cae95489075788f72713.zip RustAndDust-793af2956fc0daa67585cae95489075788f72713.tar.gz |
Pawn,Unit: add interface Pawn.PawnId, boolean isA(PawnId i)
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Pawn.java | 5 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Unit.java | 14 |
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; } |