diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-13 12:04:38 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-13 12:04:38 +0200 |
commit | 4b85e3f75e765a4240e2d206636824650074d26b (patch) | |
tree | b5a624a43df174574efc24e1a3ec6fa858b1f2df /core | |
parent | 9f12b0c465f07c110a5f75c032b1943fc1d36080 (diff) | |
download | RustAndDust-4b85e3f75e765a4240e2d206636824650074d26b.zip RustAndDust-4b85e3f75e765a4240e2d206636824650074d26b.tar.gz |
Tile,Hex: add int defenseFor(Pawn, List<Pawn>)
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Tile.java | 7 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Hex.java | 33 |
2 files changed, 38 insertions, 2 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Tile.java b/core/src/ch/asynk/tankontank/engine/Tile.java index fdcc61e..88edd4f 100644 --- a/core/src/ch/asynk/tankontank/engine/Tile.java +++ b/core/src/ch/asynk/tankontank/engine/Tile.java @@ -1,5 +1,6 @@ package ch.asynk.tankontank.engine; +import java.util.List; import java.util.Iterator; import java.util.ArrayDeque; @@ -19,10 +20,12 @@ public abstract class Tile implements Drawable, Disposable private StackedImages overlays; private ArrayDeque<Pawn> stack; + public abstract int defenseFor(Pawn target, List<Pawn> foes); public abstract int costFrom(Pawn pawn, Orientation side, boolean road); - public abstract boolean atLeastOneMove(Pawn pawn); - public abstract boolean road(Orientation side); + public abstract boolean isOffMap(); + public abstract boolean road(Orientation side); + public abstract boolean atLeastOneMove(Pawn pawn); public abstract boolean blockLineOfSightFrom(Tile tile); protected Tile() diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java index d61d601..e54574d 100644 --- a/core/src/ch/asynk/tankontank/game/Hex.java +++ b/core/src/ch/asynk/tankontank/game/Hex.java @@ -1,5 +1,6 @@ package ch.asynk.tankontank.game; +import java.util.List; import java.util.Iterator; import com.badlogic.gdx.graphics.g2d.TextureAtlas; @@ -100,4 +101,36 @@ public class Hex extends Tile return c; } + + @Override + public int defenseFor(Pawn target, List<Pawn> foes) + { + Unit u = (Unit) target; + boolean terrainBonus = true; + + for (Pawn foe : foes) { + if (((Unit) foe).type == Unit.UnitType.INFANTRY) + terrainBonus = false; + } + + int def = u.def; + switch(terrain) { + case HILLS: + if (u.type != Unit.UnitType.HARD_TARGET) + def = u.cdef; + break; + case WOODS: + case TOWN: + if (u.type != Unit.UnitType.HARD_TARGET) + def = u.cdef; + if (terrainBonus) + def += 1; + break; + default: + def = ((Unit) target).def; + break; + } + + return def; + } } |