From 12e32f31e5b450d5feb2bdf567317604f9a52edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 9 Dec 2015 23:20:57 +0100 Subject: Ctrl: improve code readability --- core/src/ch/asynk/rustanddust/game/Ctrl.java | 87 +++++++++++++++------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/game/Ctrl.java b/core/src/ch/asynk/rustanddust/game/Ctrl.java index 2b638a6..7dd29d5 100644 --- a/core/src/ch/asynk/rustanddust/game/Ctrl.java +++ b/core/src/ch/asynk/rustanddust/game/Ctrl.java @@ -219,50 +219,14 @@ public class Ctrl implements Disposable nextState = completeAction(); } - if (stateType == StateType.ANIMATION) { + if (stateType == StateType.ANIMATION) this.blockMap = hud.dialogActive(); - } + hud.playerInfo.blockEndOfTurn(nextState != StateType.SELECT); this.state.leave(nextState); - RustAndDust.debug("Ctrl", String.format(" %s -> %s : %s", stateType, nextState, battle.getPlayer())); - - switch(nextState) { - case SELECT: - this.state = selectState; - break; - case MOVE: - this.state = pathState; - break; - case ROTATE: - this.state = rotateState; - break; - case PROMOTE: - this.state = promoteState; - break; - case ENGAGE: - this.state = engageState; - break; - case BREAK: - this.state = breakState; - break; - case WITHDRAW: - this.state = withdrawState; - break; - case ANIMATION: - this.blockMap = true; - this.state = animationState; - break; - case REINFORCEMENT: - this.state = reinforcementState; - break; - case DEPLOYMENT: - this.state = deploymentState; - break; - default: - break; - } + this.state = getNextState(nextState); StateType tmp = stateType; stateType = nextState; @@ -304,4 +268,49 @@ public class Ctrl implements Disposable return nextState; } + + private State getNextState(StateType nextState) + { + RustAndDust.debug("Ctrl", String.format(" %s -> %s : %s", stateType, nextState, battle.getPlayer())); + + State state = this.state; + + switch(nextState) { + case SELECT: + state = selectState; + break; + case MOVE: + state = pathState; + break; + case ROTATE: + state = rotateState; + break; + case PROMOTE: + state = promoteState; + break; + case ENGAGE: + state = engageState; + break; + case BREAK: + state = breakState; + break; + case WITHDRAW: + state = withdrawState; + break; + case ANIMATION: + state = animationState; + this.blockMap = true; + break; + case REINFORCEMENT: + state = reinforcementState; + break; + case DEPLOYMENT: + state = deploymentState; + break; + default: + break; + } + + return state; + } } -- cgit v1.1-2-g2b99