From 4b85e3f75e765a4240e2d206636824650074d26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 13 Oct 2014 12:04:38 +0200 Subject: Tile,Hex: add int defenseFor(Pawn, List) --- core/src/ch/asynk/tankontank/engine/Tile.java | 7 ++++-- 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 stack; + public abstract int defenseFor(Pawn target, List 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 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; + } } -- cgit v1.1-2-g2b99