summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateReplay.java83
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;
+ }
+}