summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-31 15:43:03 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-31 15:43:03 +0100
commitf2b3e093d2602bafa0669ef90a376a75cf4b7489 (patch)
treebce1e0dc50c2a9a418372ae2278c05abc071407a /core/src/ch
parentaf674395951f8bca1effe8be36f9941d7d575678 (diff)
downloadRustAndDust-f2b3e093d2602bafa0669ef90a376a75cf4b7489.zip
RustAndDust-f2b3e093d2602bafa0669ef90a376a75cf4b7489.tar.gz
add game/states/StateBreak
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateBreak.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/states/StateBreak.java b/core/src/ch/asynk/tankontank/game/states/StateBreak.java
new file mode 100644
index 0000000..55478a8
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/states/StateBreak.java
@@ -0,0 +1,88 @@
+package ch.asynk.tankontank.game.states;
+
+import ch.asynk.tankontank.engine.Orientation;
+import ch.asynk.tankontank.game.Unit;
+import ch.asynk.tankontank.game.State.StateType;
+
+public class StateBreak extends StateCommon
+{
+ private boolean done;
+ private Orientation o = Orientation.KEEP;
+
+ @Override
+ public void enter(boolean flag)
+ {
+ done = false;
+ activeUnit = null;
+ ctrl.hud.hide();
+ ctrl.hud.show(false, false, false, false, true, false);
+ map.showBreakPawns();
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ map.hideBreakPawns();
+ map.unselectHex(to);
+ map.hideDirections(to);
+ map.hideOrientation(to);
+ if (activeUnit != null) map.unselectHex(activeUnit.getHex());
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ if (activeUnit == null) {
+ Unit unit = upHex.getUnit();
+ if (map.breakPawns.contains(unit)) {
+ activeUnit = unit;
+ map.selectHex(upHex);
+ map.selectHex(to);
+ map.showDirections(to);
+ map.hideBreakPawns();
+ }
+ } else {
+ o = Orientation.fromAdj(to.getCol(), to.getRow(), downHex.getCol(), downHex.getRow());
+
+ if (o == Orientation.KEEP) return;
+
+ if (ctrl.cfg.mustValidate) {
+ map.hideDirections(to);
+ map.showOrientation(to, o);
+ ctrl.hud.show(false, false, false, false, true, false);
+ } else
+ doRotation(o);
+ }
+ }
+
+ @Override
+ public void abort()
+ {
+ }
+
+ @Override
+ public void done()
+ {
+ doRotation(o);
+ super.done();
+ }
+
+ private void doRotation(Orientation o)
+ {
+ if (done || (activeUnit == null)) return;
+ done = true;
+
+ if (map.collectPossiblePaths(activeUnit, to) == 1) {
+ map.possiblePaths.orientation = o;
+ map.movePawn(activeUnit, o);
+ ctrl.setAnimationCount(1);
+ ctrl.setState(StateType.ANIMATION);
+ } else
+ System.err.println("That's very wrong there should be only one path");
+ }
+}