From f734dd5230921f1e42a8c102c8974f49e0803935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 21 Jan 2015 22:40:02 +0100 Subject: StateExit -> StateWithdraw --- core/src/ch/asynk/tankontank/game/Ctrl.java | 10 +-- core/src/ch/asynk/tankontank/game/State.java | 2 +- .../ch/asynk/tankontank/game/states/StateExit.java | 71 ---------------------- .../ch/asynk/tankontank/game/states/StateMove.java | 6 +- .../tankontank/game/states/StateWithdraw.java | 71 ++++++++++++++++++++++ 5 files changed, 80 insertions(+), 80 deletions(-) delete mode 100644 core/src/ch/asynk/tankontank/game/states/StateExit.java create mode 100644 core/src/ch/asynk/tankontank/game/states/StateWithdraw.java diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java index 4ca116f..09b5c5d 100644 --- a/core/src/ch/asynk/tankontank/game/Ctrl.java +++ b/core/src/ch/asynk/tankontank/game/Ctrl.java @@ -16,7 +16,7 @@ import ch.asynk.tankontank.game.states.StateBreak; import ch.asynk.tankontank.game.states.StateAnimation; import ch.asynk.tankontank.game.states.StateReinforcement; import ch.asynk.tankontank.game.states.StateDeployment; -import ch.asynk.tankontank.game.states.StateExit; +import ch.asynk.tankontank.game.states.StateWithdraw; public class Ctrl implements Disposable { @@ -43,7 +43,7 @@ public class Ctrl implements Disposable private State animationState; private State reinforcementState; private State deploymentState; - private State exitState; + private State withdrawState; private int animationCount = 0; @@ -74,7 +74,7 @@ public class Ctrl implements Disposable this.animationState = new StateAnimation(); this.reinforcementState = new StateReinforcement(); this.deploymentState = new StateDeployment(); - this.exitState = new StateExit(); + this.withdrawState = new StateWithdraw(); this.state = selectState; this.stateType = StateType.DONE; @@ -229,8 +229,8 @@ public class Ctrl implements Disposable case BREAK: this.state = breakState; break; - case ESCAPE: - this.state = exitState; + case WITHDRAW: + this.state = withdrawState; break; case ANIMATION: this.blockMap = true; diff --git a/core/src/ch/asynk/tankontank/game/State.java b/core/src/ch/asynk/tankontank/game/State.java index 76f5b99..efbf7f9 100644 --- a/core/src/ch/asynk/tankontank/game/State.java +++ b/core/src/ch/asynk/tankontank/game/State.java @@ -12,7 +12,7 @@ public interface State ANIMATION, REINFORCEMENT, DEPLOYMENT, - ESCAPE, + WITHDRAW, ABORT, DONE }; diff --git a/core/src/ch/asynk/tankontank/game/states/StateExit.java b/core/src/ch/asynk/tankontank/game/states/StateExit.java deleted file mode 100644 index f8edf03..0000000 --- a/core/src/ch/asynk/tankontank/game/states/StateExit.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.asynk.tankontank.game.states; - -import ch.asynk.tankontank.game.Zone; -import ch.asynk.tankontank.game.Hex; -import ch.asynk.tankontank.game.Unit; - -public class StateExit extends StateCommon -{ - @Override - public void enter(StateType prevState) - { - ctrl.hud.askExitBoard(); - } - - @Override - public void leave(StateType nextState) - { - } - - @Override - public StateType abort() - { - return StateType.MOVE; - } - - @Override - public StateType execute() - { - if (activeUnit == null) - activeUnit = selectedUnit; - - ctrl.setAnimationCount(1); - ctrl.setAfterAnimationState(escape(activeUnit)); - return StateType.ANIMATION; - } - - @Override - public void touchDown() - { - } - - @Override - public void touchUp() - { - } - - private StateType escape(Unit unit) - { - Zone exitZone = ctrl.battle.getExitZone(unit); - Hex hex = unit.getHex(); - - if (selectedHex == hex) - map.pathBuilder.build(hex); - - Hex exitHex = (Hex) map.pathBuilder.to; - if (!exitZone.contains(exitHex)) - throw new RuntimeException(String.format("%s not in exitZone", exitHex)); - - map.pathBuilder.setExit(exitZone.orientation); - - unit.hideMoveable(); - if (to != null) - map.hidePath(to); - map.hidePossibleMoves(); - map.unselectHex(hex); - - if (map.exitBoard(unit) > 0) - return StateType.MOVE; - return StateType.DONE; - } -} diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java index 27bc6af..f81035d 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateMove.java +++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java @@ -14,7 +14,7 @@ public class StateMove extends StateCommon ((map.activatedUnits.size() > 0) ? Buttons.DONE.b : 0) | (ctrl.cfg.canCancel ? Buttons.ABORT.b : 0)); - if (prevState == StateType.ESCAPE) { + if (prevState == StateType.WITHDRAW) { if (map.pathBuilder.size() == 1) ctrl.setState(StateType.ROTATE); return; @@ -49,7 +49,7 @@ public class StateMove extends StateCommon @Override public void leave(StateType nextState) { - if (nextState == StateType.ESCAPE) + if (nextState == StateType.WITHDRAW) return; // hide all but assists : want them when in rotation @@ -188,7 +188,7 @@ public class StateMove extends StateCommon return false; if ((unit.getHex() != hex) && !map.pathBuilder.canExit(exitZone.orientation)) return false; - ctrl.setState(StateType.ESCAPE); + ctrl.setState(StateType.WITHDRAW); return true; } } diff --git a/core/src/ch/asynk/tankontank/game/states/StateWithdraw.java b/core/src/ch/asynk/tankontank/game/states/StateWithdraw.java new file mode 100644 index 0000000..20ba80d --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/states/StateWithdraw.java @@ -0,0 +1,71 @@ +package ch.asynk.tankontank.game.states; + +import ch.asynk.tankontank.game.Zone; +import ch.asynk.tankontank.game.Hex; +import ch.asynk.tankontank.game.Unit; + +public class StateWithdraw extends StateCommon +{ + @Override + public void enter(StateType prevState) + { + ctrl.hud.askExitBoard(); + } + + @Override + public void leave(StateType nextState) + { + } + + @Override + public StateType abort() + { + return StateType.MOVE; + } + + @Override + public StateType execute() + { + if (activeUnit == null) + activeUnit = selectedUnit; + + ctrl.setAnimationCount(1); + ctrl.setAfterAnimationState(escape(activeUnit)); + return StateType.ANIMATION; + } + + @Override + public void touchDown() + { + } + + @Override + public void touchUp() + { + } + + private StateType escape(Unit unit) + { + Zone exitZone = ctrl.battle.getExitZone(unit); + Hex hex = unit.getHex(); + + if (selectedHex == hex) + map.pathBuilder.build(hex); + + Hex exitHex = (Hex) map.pathBuilder.to; + if (!exitZone.contains(exitHex)) + throw new RuntimeException(String.format("%s not in exitZone", exitHex)); + + map.pathBuilder.setExit(exitZone.orientation); + + unit.hideMoveable(); + if (to != null) + map.hidePath(to); + map.hidePossibleMoves(); + map.unselectHex(hex); + + if (map.exitBoard(unit) > 0) + return StateType.MOVE; + return StateType.DONE; + } +} -- cgit v1.1-2-g2b99