From 945f3d4a9120b2b83fca477f1d00edcf881a4ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 18 Nov 2014 20:03:27 +0100 Subject: StateCommon: add checkExit(Unit, Hex) --- .../src/ch/asynk/tankontank/game/states/StateCommon.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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; + } } -- cgit v1.1-2-g2b99