From f4e47fdceb73d2fcd5a9d3af9876b9612f8cf8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 4 Jan 2016 21:43:30 +0100 Subject: StateMove: split checkExit() -> inplace | from hex --- .../ch/asynk/rustanddust/game/states/StateMove.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/game/states/StateMove.java b/core/src/ch/asynk/rustanddust/game/states/StateMove.java index 1a088ac..f7597ff 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateMove.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateMove.java @@ -32,7 +32,7 @@ public class StateMove extends StateCommon // quick move -> replay touchUp touch(to); } else - checkExit(activeUnit, activeUnit.getHex()); + checkExit(activeUnit); } else { // back from rotation -> chose next Pawn if (selectedUnit.canMove()) { @@ -142,7 +142,7 @@ public class StateMove extends StateCommon map.movesShow(); map.hexSelect(hex); ctrl.hud.notify(activeUnit.toString(), Position.TOP_CENTER); - checkExit(activeUnit, hex); + checkExit(activeUnit); } private int collectPaths(Hex hex) @@ -172,14 +172,23 @@ public class StateMove extends StateCommon return s; } - private boolean checkExit(Unit unit, Hex hex) + private boolean checkExit(Unit unit) { - if ((hex == unit.getHex()) && (unit.justEntered())) + if (unit.justEntered()) + return false; + Zone exitZone = ctrl.battle.getExitZone(unit); + if ((exitZone == null) || !exitZone.contains(unit.getHex())) return false; + ctrl.setState(StateType.WITHDRAW); + return true; + } + + private boolean checkExit(Unit unit, Hex hex) + { Zone exitZone = ctrl.battle.getExitZone(unit); if ((exitZone == null) || !exitZone.contains(hex)) return false; - if ((unit.getHex() != hex) && !map.pathsCanExit(exitZone.orientation)) + if (!map.pathsCanExit(exitZone.orientation)) return false; ctrl.setState(StateType.WITHDRAW); return true; -- cgit v1.1-2-g2b99