From 65b9fba33f138f7ebadd2bb13b2505157e225a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 18 Feb 2015 17:20:55 +0100 Subject: Map,Command: promoteUnit uses Command processing --- core/src/ch/asynk/tankontank/game/Command.java | 6 ++++ core/src/ch/asynk/tankontank/game/Map.java | 41 ++++++++++++++-------- .../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); -- cgit v1.1-2-g2b99