diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-03-29 11:52:16 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-03-29 11:52:16 +0200 |
commit | a562eb32f6c9475925a4326f3dcfe86ffc3d3157 (patch) | |
tree | f65191f21d075cdb73f882f532c012fe2426bf1e /core/src | |
parent | 3fd2744261ee01e5d1a3b322c7e2efe5ee4967c2 (diff) | |
download | RustAndDust-a562eb32f6c9475925a4326f3dcfe86ffc3d3157.zip RustAndDust-a562eb32f6c9475925a4326f3dcfe86ffc3d3157.tar.gz |
add states/StateReplay
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/states/StateReplay.java | 83 |
1 files changed, 83 insertions, 0 deletions
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; + } +} |