summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-02-18 16:53:57 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-02-18 16:53:57 +0100
commitcb191cd106c289e5db9835a473a59919b240c303 (patch)
tree3922436519bcb2c9588c030eab6f3e45310c7f29 /core/src/ch/asynk/tankontank
parentb66b04cbbd0ce67f8d7fb8aa588807ea93b1295f (diff)
downloadRustAndDust-cb191cd106c289e5db9835a473a59919b240c303.zip
RustAndDust-cb191cd106c289e5db9835a473a59919b240c303.tar.gz
Map: wrap move into Command before processing them
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java38
1 files changed, 32 insertions, 6 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index cc60e81..aa14ea4 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -269,7 +269,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
private int process(Unit unit, Move move)
{
- TankOnTank.debug("Process", String.format("%s %s", move.type, move.toString()));
+ TankOnTank.debug(" Move", String.format("%s %s", move.type, move.toString()));
int r = 1;
@@ -298,7 +298,26 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
claim((Hex) move.to, unit.getArmy());
break;
default:
- System.err.println(String.format("process wrong type %s", move.type));
+ System.err.println(String.format("process wrong Move type %s", move.type));
+ r = -1;
+ break;
+ }
+
+ return r;
+ }
+
+ private int process(Command cmd)
+ {
+ TankOnTank.debug("Command", cmd.toString());
+
+ int r = 1;
+
+ switch(cmd.type) {
+ case MOVE:
+ r = process(cmd.unit, cmd.move);
+ break;
+ default:
+ System.err.println(String.format("process wrong Command type %s", cmd.type));
r = -1;
break;
}
@@ -339,7 +358,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
public boolean setOnBoard(Unit unit, Hex to, Orientation entry)
{
- return (process(unit, Move.getSet(unit, to, entry)) == 1);
+ return (process(getMoveCommand(unit, Move.getSet(unit, to, entry))) == 1);
}
public boolean enterBoard(Unit unit, Hex to, int allowedMoves)
@@ -348,17 +367,17 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
if (entry == Orientation.KEEP)
return false;
- return (process(unit, Move.getEnter(unit, to, entry)) == 1);
+ return (process(getMoveCommand(unit, Move.getEnter(unit, to, entry))) == 1);
}
public int exitBoard(Unit unit)
{
- return process(unit, pathBuilder.getExitMove());
+ return process(getMoveCommand(unit, pathBuilder.getExitMove()));
}
public int moveUnit(Unit unit)
{
- return process(unit, pathBuilder.getMove());
+ return process(getMoveCommand(unit, pathBuilder.getMove()));
}
public void revertMoves()
@@ -408,6 +427,13 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
// STATES ENTRY <-
+ private Command getMoveCommand(Unit unit, Move move)
+ {
+ Command cmd = Command.get(ctrl.player);
+ cmd.setMove(unit, move);
+ return cmd;
+ }
+
private void initMove(Unit unit)
{
moveableUnits.remove(unit);