From a562eb32f6c9475925a4326f3dcfe86ffc3d3157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 29 Mar 2016 11:52:16 +0200 Subject: add states/StateReplay --- .../asynk/rustanddust/game/states/StateReplay.java | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 core/src/ch/asynk/rustanddust/game/states/StateReplay.java diff --git a/core/src/ch/asynk/rustanddust/game/states/StateReplay.java b/core/src/ch/asynk/rustanddust/game/states/StateReplay.java new file mode 100644 index 0000000..c7b95c1 --- /dev/null +++ b/core/src/ch/asynk/rustanddust/game/states/StateReplay.java @@ -0,0 +1,83 @@ +package ch.asynk.rustanddust.game.states; + +import ch.asynk.rustanddust.game.Order; + +public class StateReplay extends StateCommon +{ + Order order; + + @Override + public void enterFrom(StateType prevState) + { + Order o = map.stepReplay(); + if (o == null) { + ctrl.setState(nextState()); + } else { + this.order = o; + setup(); + map.replay(order); + ctrl.setAfterAnimationState(StateType.REPLAY); + ctrl.setState(StateType.ANIMATION); + } + } + + private void setup() + { + switch (order.type) { + case MOVE: + selectedUnit = order.activable.get(order.activable.size() - 1); + break; + case ENGAGE: + to = order.engagement.defender.getHex(); + if (order.engagement.success) { + ctrl.battle.getPlayer().engagementWon += 1; + ctrl.battle.getOpponent().casualty(order.engagement.defender); + } else { + ctrl.battle.getPlayer().engagementLost += 1; + } + break; + case PROMOTE: + break; + default: + break; + } + } + + private StateType nextState() + { + StateType next = StateType.DONE; + + if (map.unitsActivableSize() <= 0) + return next; + + switch (order.type) { + case MOVE: + next = StateType.MOVE; + break; + case ENGAGE: + next = StateType.BREAK; + break; + default: + break; + } + + return next; + } + + @Override + public void leaveFor(StateType nextState) + { + } + + @Override + public StateType abort() + { + return StateType.ABORT; + } + + @Override + public StateType execute() + { + return StateType.DONE; + } +} -- cgit v1.1-2-g2b99