summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-18 20:03:27 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-18 20:03:27 +0100
commit945f3d4a9120b2b83fca477f1d00edcf881a4ad6 (patch)
tree5d589bc726489cfcffea4180e41b606283e9583e /core
parent2b0b92f2b3135fd06a809be3ee94ec8e103ab51a (diff)
downloadRustAndDust-945f3d4a9120b2b83fca477f1d00edcf881a4ad6.zip
RustAndDust-945f3d4a9120b2b83fca477f1d00edcf881a4ad6.tar.gz
StateCommon: add checkExit(Unit, Hex)
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateCommon.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java
index 33d5343..e702ce4 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateCommon.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateCommon.java
@@ -1,5 +1,6 @@
package ch.asynk.tankontank.game.states;
+import ch.asynk.tankontank.engine.Zone;
import ch.asynk.tankontank.game.Map;
import ch.asynk.tankontank.game.Hex;
import ch.asynk.tankontank.game.Unit;
@@ -76,4 +77,19 @@ public abstract class StateCommon implements State
map.hidePossibleTargets();
map.hideMoveablePawns();
}
+
+ protected boolean checkExit(Unit unit, Hex hex)
+ {
+ Zone exitZone = ctrl.battle.getExitZone(unit);
+ if ((exitZone == null) || !exitZone.contains(hex))
+ return false;
+ if (map.possiblePaths.size() == 1) {
+ // TODO pathCost called with applayToPawn from Board it updates Pawn.move
+ int left = (unit.getMovementPoints() - map.possiblePaths.pathCost(0));
+ if (left < 1)
+ return false;
+ }
+ ctrl.setState(StateType.ESCAPE);
+ return true;
+ }
}