summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-16 01:33:42 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-16 01:33:42 +0100
commit86015f2832c8ef6f0c8b5e313eda467c20684a1c (patch)
tree48c219b532318d9f500724845d64953cc07857c3 /core/src/ch/asynk/tankontank
parent6c03056512877637d3c01e0cbe89c5daf2d13408 (diff)
downloadRustAndDust-86015f2832c8ef6f0c8b5e313eda467c20684a1c.zip
RustAndDust-86015f2832c8ef6f0c8b5e313eda467c20684a1c.tar.gz
add StateDeployment
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/game/Ctrl.java6
-rw-r--r--core/src/ch/asynk/tankontank/game/State.java1
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateDeployment.java136
3 files changed, 143 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java
index b596b29..dbe8817 100644
--- a/core/src/ch/asynk/tankontank/game/Ctrl.java
+++ b/core/src/ch/asynk/tankontank/game/Ctrl.java
@@ -13,6 +13,7 @@ import ch.asynk.tankontank.game.states.StateEngage;
import ch.asynk.tankontank.game.states.StateBreak;
import ch.asynk.tankontank.game.states.StateAnimation;
import ch.asynk.tankontank.game.states.StateReinforcement;
+import ch.asynk.tankontank.game.states.StateDeployment;
import ch.asynk.tankontank.screens.OptionsScreen;
@@ -37,6 +38,7 @@ public class Ctrl implements Disposable
private State breakState;
private State animationState;
private State reinforcementState;
+ private State deploymentState;
private int animationCount = 0;
@@ -64,6 +66,7 @@ public class Ctrl implements Disposable
this.breakState = new StateBreak();
this.animationState = new StateAnimation();
this.reinforcementState = new StateReinforcement();
+ this.deploymentState = new StateDeployment();
this.state = selectState;
this.stateType = StateType.DONE;
@@ -203,6 +206,9 @@ public class Ctrl implements Disposable
case REINFORCEMENT:
this.state = reinforcementState;
break;
+ case DEPLOYMENT:
+ this.state = deploymentState;
+ break;
default:
break;
}
diff --git a/core/src/ch/asynk/tankontank/game/State.java b/core/src/ch/asynk/tankontank/game/State.java
index 4b96156..dc6854c 100644
--- a/core/src/ch/asynk/tankontank/game/State.java
+++ b/core/src/ch/asynk/tankontank/game/State.java
@@ -11,6 +11,7 @@ public interface State
PROMOTE,
ANIMATION,
REINFORCEMENT,
+ DEPLOYMENT,
ABORT,
DONE
};
diff --git a/core/src/ch/asynk/tankontank/game/states/StateDeployment.java b/core/src/ch/asynk/tankontank/game/states/StateDeployment.java
new file mode 100644
index 0000000..222ea67
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/states/StateDeployment.java
@@ -0,0 +1,136 @@
+package ch.asynk.tankontank.game.states;
+
+import ch.asynk.tankontank.engine.Orientation;
+import ch.asynk.tankontank.engine.EntryPoint;
+import ch.asynk.tankontank.engine.PawnSet;
+import ch.asynk.tankontank.game.Hex;
+import ch.asynk.tankontank.game.Unit;
+import ch.asynk.tankontank.game.hud.ActionButtons.Buttons;
+
+import ch.asynk.tankontank.TankOnTank;
+
+public class StateDeployment extends StateCommon
+{
+ private boolean done;
+ private EntryPoint entryPoint;
+ private PawnSet deployedUnits = new PawnSet(map, 10);
+
+ @Override
+ public void enter(StateType prevState)
+ {
+ if (selectedHex != null)
+ map.unselectHex(selectedHex);
+ done = false;
+ entryPoint = null;
+ selectedHex = null;
+ ctrl.hud.actionButtons.hide();
+ ctrl.hud.playerInfo.unitDock.show();
+ ctrl.hud.playerInfo.blockEndOfTurn(true);
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ if (selectedHex != null)
+ map.unselectHex(selectedHex);
+ if (entryPoint != null)
+ entryPoint.enable(Hex.AREA, false);
+ ctrl.hud.playerInfo.unitDock.hide();
+ }
+
+ @Override
+ public StateType abort()
+ {
+ undo();
+ return StateType.DEPLOYMENT;
+ }
+
+ @Override
+ public StateType done()
+ {
+ deployedUnits.clear();
+ ctrl.hud.playerInfo.blockEndOfTurn(false);
+ return StateType.DONE;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ Unit unit = ctrl.hud.playerInfo.getDockUnit();
+ if (!done && (unit != null) && (unit != activeUnit)) {
+ changeUnit(unit);
+ } else if (selectedUnit != null) {
+ Orientation o = Orientation.fromAdj(selectedHex, upHex);
+ if (o != Orientation.KEEP)
+ doRotation(o);
+ } else if (!done && (entryPoint != null) && (upHex != null)) {
+ if (upHex.isEmpty() && entryPoint.contains(upHex))
+ unitEnter(activeUnit);
+ } else {
+ unit = downHex.getUnit();
+ if (deployedUnits.contains(unit)) {
+ selectedUnit = unit;
+ selectedHex = downHex;
+ showRotation();
+ }
+ }
+ }
+
+ private void changeUnit(Unit unit)
+ {
+ activeUnit = unit;
+ if (entryPoint != null) entryPoint.enable(Hex.AREA, false);
+ entryPoint = ctrl.battle.getEntryPoint(activeUnit);
+ entryPoint.enable(Hex.AREA, true);
+ }
+
+ private void undo()
+ {
+ map.unselectHex(selectedHex);
+ map.hideDirections(selectedHex);
+ map.leaveBoard(selectedUnit);
+ ctrl.player.revertUnitEntry(selectedUnit);
+ activeUnit = null;
+ selectedUnit = null;
+ }
+
+ private void unitEnter(Unit unit)
+ {
+ selectedUnit = unit;
+ selectedHex = upHex;
+ ctrl.player.unitEntry(unit);
+ map.enterBoard(unit, upHex, entryPoint.orientation);
+ deployedUnits.add(unit);
+ entryPoint.enable(Hex.AREA, false);
+ showRotation();
+ }
+
+ private void showRotation()
+ {
+ map.selectHex(selectedHex);
+ map.showDirections(selectedHex);
+ ctrl.hud.playerInfo.unitDock.hide();
+ ctrl.hud.actionButtons.show(Buttons.ROTATE.b | Buttons.ABORT.b);
+ ctrl.hud.actionButtons.setOn(Buttons.ROTATE);
+ }
+
+ private void doRotation(Orientation o)
+ {
+ map.unselectHex(selectedHex);
+ map.hideDirections(selectedHex);
+ selectedUnit.setRotation(o.r());
+ ctrl.hud.actionButtons.hide();
+ ctrl.hud.playerInfo.unitDock.show();
+ entryPoint = null;
+ activeUnit = null;
+ selectedUnit = null;
+ if (ctrl.checkDeploymentDone()) {
+ done = true;
+ }
+ }
+}