summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-01-19 00:22:58 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-01-19 00:22:58 +0100
commit1860b7d50173e73f977ffaaa26a4a2fecb55bb38 (patch)
treef4fea4f97e0c62a28fe2f1e0b5e885fd516a9e7b /core
parentcde58b301288d64439d4432c3c244f767d737364 (diff)
downloadRustAndDust-1860b7d50173e73f977ffaaa26a4a2fecb55bb38.zip
RustAndDust-1860b7d50173e73f977ffaaa26a4a2fecb55bb38.tar.gz
Map: add private process(Unit, Move)
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java54
1 files changed, 37 insertions, 17 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index be97c7f..cb22baf 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -260,6 +260,38 @@ public abstract class Map extends Board
return 0;
}
+ private int process(Unit unit, Move move)
+ {
+ TankOnTank.debug("Process", String.format("%s %s", move.type, move.toString()));
+
+ int r = 1;
+
+ switch(move.type) {
+ case REGULAR:
+ case EXIT:
+ initMove(unit);
+ movePawn(unit, move, notifyDoneAnimation(unit), objectives);
+ r = moveableUnits.size();
+ break;
+ case SET:
+ // FIXME SET -> activatedUnits.add(unit); ??
+ setPawnOnto(unit, move);
+ objectives.claim((Hex) move.to, unit.getArmy());
+ break;
+ case ENTER:
+ // FIXME ENTER -> activatedUnits.add(unit); ??
+ enterPawn(unit, move);
+ objectives.claim((Hex) move.to, unit.getArmy());
+ break;
+ default:
+ System.err.println(String.format("process wrong type %s", move.type));
+ r = -1;
+ break;
+ }
+
+ return r;
+ }
+
// STATES ENTRY ->
public void actionDone()
@@ -273,19 +305,12 @@ public abstract class Map extends Board
if (entry == Orientation.KEEP)
return false;
-
- enterPawn(unit, Move.getEnter(unit, to, entry));
- objectives.claim(to, unit.getArmy());
- return true;
+ return (process(unit, Move.getEnter(unit, to, entry)) == 1);
}
public boolean setOnBoard(Unit unit, Hex to, Orientation entry)
{
- TankOnTank.debug("Map", String.format("set %s %s %s", to.toShort(), unit, entry));
-
- setPawnOnto(unit, Move.getSet(unit, to, entry));
- objectives.claim(to, unit.getArmy());
- return true;
+ return (process(unit, Move.getSet(unit, to, entry)) == 1);
}
public int exitBoard(Unit unit)
@@ -295,9 +320,7 @@ public abstract class Map extends Board
// unit.reset();
// }
- movePawn(unit, possiblePaths.getExitMove(), notifyDoneAnimation(unit), objectives);
-
- return startMove(unit);
+ return process(unit, possiblePaths.getExitMove());
}
public void promoteUnit(final Player player, final Unit unit)
@@ -319,9 +342,7 @@ public abstract class Map extends Board
public int moveUnit(Unit unit)
{
- movePawn(unit, possiblePaths.getMove(), notifyDoneAnimation(unit), objectives);
-
- return startMove(unit);
+ return process(unit, possiblePaths.getMove());
}
public void revertMoves()
@@ -344,12 +365,11 @@ public abstract class Map extends Board
// STATES ENTRY <-
- private int startMove(Unit unit)
+ private void initMove(Unit unit)
{
moveableUnits.remove(unit);
activatedUnits.add(unit);
playMoveSound(unit);
- return moveableUnits.size();
}
private void playMoveSound(Unit unit)