diff options
Diffstat (limited to 'core/src/ch/asynk/tankontank/game')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Command.java | 6 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Map.java | 41 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StatePromote.java | 2 |
3 files changed, 33 insertions, 16 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Command.java b/core/src/ch/asynk/tankontank/game/Command.java index 903c18b..ab809af 100644 --- a/core/src/ch/asynk/tankontank/game/Command.java +++ b/core/src/ch/asynk/tankontank/game/Command.java @@ -74,6 +74,12 @@ public class Command extends Order this.move = move; } + public void setPromote(Unit unit) + { + this.type = CommandType.PROMOTE; + this.unit = unit; + } + @Override public void write(Json json) { diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 20076b1..471b9f0 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -310,6 +310,25 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS return r; } + private int promoteUnit(final Unit unit, final Player player) + { + // FIXME promoteUnit : ctrl.mapTouch. is not network safe + activatedUnits.add(unit); + + Hex hex = unit.getHex(); + AnimationSequence seq = AnimationSequence.get(2); + seq.addAnimation(PromoteAnimation.get((unit.getArmy() == Army.US), ctrl.mapTouch.x, ctrl.mapTouch.y, hex.getX(), hex.getY(), ctrl.cfg.fxVolume)); + seq.addAnimation ( RunnableAnimation.get(unit, new Runnable() { + @Override + public void run() { + player.promote(unit); + animationDone(); + } + })); + addAnimation(seq); + return 1; + } + private int process(Command cmd) { TankOnTank.debug("Command", cmd.toString()); @@ -320,6 +339,9 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS case MOVE: r = process(cmd.unit, cmd.move); break; + case PROMOTE: + r = promoteUnit(cmd.unit, cmd.player); + break; default: System.err.println(String.format("process wrong Command type %s", cmd.type)); r = -1; @@ -420,22 +442,11 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS return engage(unit, target, engagement); } - public void promoteUnit(final Player player, final Unit unit) + public void promoteUnit(final Unit unit) { - // FIXME promoteUnit -> process - activatedUnits.add(unit); - - Hex hex = unit.getHex(); - AnimationSequence seq = AnimationSequence.get(2); - seq.addAnimation(PromoteAnimation.get((unit.getArmy() == Army.US), ctrl.mapTouch.x, ctrl.mapTouch.y, hex.getX(), hex.getY(), ctrl.cfg.fxVolume)); - seq.addAnimation ( RunnableAnimation.get(unit, new Runnable() { - @Override - public void run() { - player.promote(unit); - animationDone(); - } - })); - addAnimation(seq); + Command cmd = Command.get(ctrl.player); + cmd.setPromote(unit); + process(cmd); } // STATES ENTRY <- diff --git a/core/src/ch/asynk/tankontank/game/states/StatePromote.java b/core/src/ch/asynk/tankontank/game/states/StatePromote.java index 340cb7b..1950847 100644 --- a/core/src/ch/asynk/tankontank/game/states/StatePromote.java +++ b/core/src/ch/asynk/tankontank/game/states/StatePromote.java @@ -7,7 +7,7 @@ public class StatePromote extends StateCommon @Override public void enter(StateType prevState) { - map.promoteUnit(ctrl.player, selectedUnit); + map.promoteUnit(selectedUnit); ctrl.setAnimationCount(1); ctrl.setAfterAnimationState(StateType.SELECT); ctrl.setState(StateType.ANIMATION); |