summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game/states
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/tankontank/game/states')
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateAnimation.java9
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateAttack.java15
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateBreak.java9
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateCommon.java34
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateMove.java14
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StatePromote.java9
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateReinforcement.java15
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateRotate.java37
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateSelect.java8
9 files changed, 60 insertions, 90 deletions
diff --git a/core/src/ch/asynk/tankontank/game/states/StateAnimation.java b/core/src/ch/asynk/tankontank/game/states/StateAnimation.java
index acd9ceb..e67b56d 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateAnimation.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateAnimation.java
@@ -3,7 +3,7 @@ package ch.asynk.tankontank.game.states;
public class StateAnimation extends StateCommon
{
@Override
- public void enter(boolean flag)
+ public void enter(StateType prevState)
{
}
@@ -23,13 +23,14 @@ public class StateAnimation extends StateCommon
}
@Override
- public void abort()
+ public StateType abort()
{
+ return StateType.ABORT;
}
@Override
- public void done()
+ public StateType done()
{
- super.done();
+ return StateType.DONE;
}
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java
index 7bdb925..37df9f7 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateAttack.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java
@@ -8,14 +8,14 @@ import ch.asynk.tankontank.TankOnTank;
public class StateAttack extends StateCommon
{
@Override
- public void enter(boolean fromSelect)
+ public void enter(StateType prevState)
{
map.possibleTargets.clear();
ctrl.hud.actionButtons.show(Buttons.ATTACK.b | ((ctrl.cfg.canCancel) ? Buttons.ABORT.b : 0));
ctrl.hud.actionButtons.setOn(Buttons.ATTACK);
// activeUnit is the target
- if (fromSelect) {
+ if (prevState == StateType.SELECT) {
activeUnit = null;
// use selectedHex and selectedUnit
map.hidePossibleTargets();
@@ -74,15 +74,16 @@ public class StateAttack extends StateCommon
}
@Override
- public void abort()
+ public StateType abort()
{
map.activatedPawns.clear();
- super.abort();
+ return StateType.ABORT;
}
@Override
- public void done()
+ public StateType done()
{
+ StateType nextState = StateType.DONE;
int d1 = ctrl.player.d6();
int d2 = ctrl.player.d6();
if (map.attackPawn(selectedUnit, activeUnit, d1, d2)) {
@@ -91,7 +92,7 @@ public class StateAttack extends StateCommon
ctrl.opponent.casualty(activeUnit);
if (map.breakPawns.size() > 0) {
ctrl.hud.pushNotify("Break move possible");
- setNextState(StateType.BREAK);
+ nextState = StateType.BREAK;
}
} else {
ctrl.player.lostAttackCount += 1;
@@ -101,6 +102,6 @@ public class StateAttack extends StateCommon
activeUnit.showTarget();
ctrl.setState(StateType.ANIMATION);
- super.done();
+ return nextState;
}
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateBreak.java b/core/src/ch/asynk/tankontank/game/states/StateBreak.java
index be7f460..debc9c1 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateBreak.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateBreak.java
@@ -12,7 +12,7 @@ public class StateBreak extends StateCommon
private Orientation o = Orientation.KEEP;
@Override
- public void enter(boolean flag)
+ public void enter(StateType prevState)
{
done = false;
activeUnit = null;
@@ -62,15 +62,16 @@ public class StateBreak extends StateCommon
}
@Override
- public void abort()
+ public StateType abort()
{
+ return StateType.ABORT;
}
@Override
- public void done()
+ public StateType done()
{
doRotation(o);
- super.done();
+ return StateType.DONE;
}
private void doRotation(Orientation o)
diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java
index 314801b..d88d25b 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateCommon.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateCommon.java
@@ -22,8 +22,6 @@ public abstract class StateCommon implements State
protected static Unit activeUnit;
protected static Unit selectedUnit;
- protected static StateType nextState = StateType.SELECT;
-
protected StateCommon()
{
}
@@ -34,30 +32,6 @@ public abstract class StateCommon implements State
this.map = map;
}
- @Override
- public StateType getNextState()
- {
- return nextState;
- }
-
- @Override
- public void setNextState(StateType state)
- {
- nextState = state;
- }
-
- @Override
- public void abort()
- {
- goToNextState();
- }
-
- @Override
- public void done()
- {
- goToNextState();
- }
-
public void clearAll()
{
to = null;
@@ -66,14 +40,6 @@ public abstract class StateCommon implements State
activeUnit = null;
}
- private void goToNextState()
- {
- ctrl.hud.actionButtons.hide();
- StateType next = nextState;
- nextState = StateType.SELECT;
- ctrl.setState(next, (next == StateType.SELECT));
- }
-
public boolean downInMap(float x, float y)
{
downHex = map.getHexAt(x, y);
diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java
index 2f672c9..02f814e 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateMove.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java
@@ -7,14 +7,14 @@ import ch.asynk.tankontank.game.hud.ActionButtons.Buttons;
public class StateMove extends StateCommon
{
@Override
- public void enter(boolean fromSelect)
+ public void enter(StateType prevState)
{
boolean moreThanOne = ((map.moveablePawns.size() + map.activatedPawns.size()) > 1);
ctrl.hud.actionButtons.show(Buttons.ROTATE.b | Buttons.MOVE.b | ((moreThanOne) ? Buttons.DONE.b : 0) | ((ctrl.cfg.canCancel) ? Buttons.ABORT.b : 0));
ctrl.hud.actionButtons.setOn(Buttons.MOVE);
map.possiblePaths.clear();
- if (fromSelect) {
+ if (prevState == StateType.SELECT) {
// use selectedHex and selectedUnit
activeUnit = selectedUnit;
activeUnit.showMoveable();
@@ -74,12 +74,12 @@ public class StateMove extends StateCommon
}
if (s == 1) {
- ctrl.setState(StateType.ROTATE, false);
+ ctrl.setState(StateType.ROTATE);
}
}
@Override
- public void abort()
+ public StateType abort()
{
hideAssists();
ctrl.setAnimationCount(map.activatedPawns.size());
@@ -88,18 +88,18 @@ public class StateMove extends StateCommon
map.leaveBoard(activeUnit);
ctrl.player.revertUnitEntry(activeUnit);
}
- super.abort();
+ return StateType.ABORT;
}
@Override
- public void done()
+ public StateType done()
{
hideAssists();
// be sure that the hq is activated
if (selectedUnit.canMove() && (map.activatedPawns.size() > 0)) {
selectedUnit.move();
}
- super.done();
+ return StateType.DONE;
}
private void hideAssists()
diff --git a/core/src/ch/asynk/tankontank/game/states/StatePromote.java b/core/src/ch/asynk/tankontank/game/states/StatePromote.java
index 6366d74..49bcad5 100644
--- a/core/src/ch/asynk/tankontank/game/states/StatePromote.java
+++ b/core/src/ch/asynk/tankontank/game/states/StatePromote.java
@@ -5,7 +5,7 @@ import ch.asynk.tankontank.game.Unit;
public class StatePromote extends StateCommon
{
@Override
- public void enter(boolean flag)
+ public void enter(StateType prevState)
{
ctrl.hud.actionButtons.hide();
Unit unit = ctrl.player.promote(selectedUnit);
@@ -32,13 +32,14 @@ public class StatePromote extends StateCommon
}
@Override
- public void abort()
+ public StateType abort()
{
+ return StateType.ABORT;
}
@Override
- public void done()
+ public StateType done()
{
- super.done();
+ return StateType.DONE;
}
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateReinforcement.java b/core/src/ch/asynk/tankontank/game/states/StateReinforcement.java
index aaabb1d..9025c2f 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateReinforcement.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateReinforcement.java
@@ -10,7 +10,7 @@ public class StateReinforcement extends StateCommon
private EntryPoint entryPoint;
@Override
- public void enter(boolean fromSelect)
+ public void enter(StateType prevState)
{
if (selectedHex != null)
map.unselectHex(selectedHex);
@@ -47,15 +47,15 @@ public class StateReinforcement extends StateCommon
}
@Override
- public void abort()
+ public StateType abort()
{
- super.abort();
+ return StateType.ABORT;
}
@Override
- public void done()
+ public StateType done()
{
- super.done();
+ return StateType.DONE;
}
private void changeUnit(Unit unit)
@@ -76,12 +76,11 @@ public class StateReinforcement extends StateCommon
ctrl.player.unitEntry(unit);
if (map.enterBoard(unit, upHex, entryPoint.allowedMoves)) {
if (unit.getMovementPoints() > 0)
- ctrl.setState(StateType.MOVE, true);
+ ctrl.setState(StateType.MOVE);
else
- ctrl.setState(StateType.ROTATE, true);
+ ctrl.setState(StateType.ROTATE);
} else {
ctrl.hud.notify("Impossible to enter map at that position");
- abort();
}
}
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateRotate.java b/core/src/ch/asynk/tankontank/game/states/StateRotate.java
index a5547f9..7390b0d 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateRotate.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateRotate.java
@@ -12,22 +12,19 @@ public class StateRotate extends StateCommon
private Orientation o = Orientation.KEEP;
@Override
- public void enter(boolean rotateOnly)
+ public void enter(StateType prevState)
{
- this.rotateOnly = rotateOnly;
-
ctrl.hud.actionButtons.show(Buttons.ROTATE.b | ((ctrl.cfg.canCancel) ? Buttons.ABORT.b : 0));
ctrl.hud.actionButtons.setOn(Buttons.ROTATE);
- if (rotateOnly) {
- // rotateBtn from Select state
- if (activeUnit == null)
- activeUnit = selectedUnit;
- to = activeUnit.getHex();
- } else {
+ if (prevState == StateType.MOVE) {
+ rotateOnly = false;
if (to == null)
TankOnTank.debug("to is null but should not be");
map.showFinalPath(to);
+ } else {
+ rotateOnly = true;
+ to = activeUnit.getHex();
}
map.selectHex(activeUnit.getHex());
@@ -71,29 +68,29 @@ public class StateRotate extends StateCommon
}
@Override
- public void abort()
+ public StateType abort()
{
+ StateType nextState = StateType.ABORT;
ctrl.hud.actionButtons.hide();
if (activeUnit.move.entryMove) {
map.leaveBoard(activeUnit);
ctrl.player.revertUnitEntry(activeUnit);
- super.abort();
}
if (map.activatedPawns.size() == 0) {
hideAssists();
- super.abort();
} else {
- ctrl.setState(StateType.MOVE, false);
+ nextState = StateType.MOVE;
}
+ return nextState;
}
@Override
- public void done()
+ public StateType done()
{
doRotation(o);
if (selectedUnit.canMove() && (map.activatedPawns.size() > 0))
selectedUnit.move();
- super.done();
+ return StateType.DONE;
}
private void hideAssists()
@@ -105,17 +102,19 @@ public class StateRotate extends StateCommon
{
if (!rotationSet) return;
+ StateType whenDone = StateType.DONE;
+
ctrl.hud.notify("Move " + activeUnit);
if (rotateOnly) {
ctrl.setAnimationCount(1);
if (map.rotatePawn(activeUnit, o) > 0)
- setNextState(StateType.MOVE);
- ctrl.setState(StateType.ANIMATION);
+ whenDone = StateType.MOVE;
} else {
ctrl.setAnimationCount(1);
if (map.movePawn(activeUnit, o) > 0)
- setNextState(StateType.MOVE);
- ctrl.setState(StateType.ANIMATION);
+ whenDone = StateType.MOVE;
}
+
+ ctrl.setState(StateType.ANIMATION, whenDone);
}
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateSelect.java b/core/src/ch/asynk/tankontank/game/states/StateSelect.java
index 19dbc73..13130b0 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateSelect.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateSelect.java
@@ -12,7 +12,7 @@ public class StateSelect extends StateCommon
}
@Override
- public void enter(boolean flag)
+ public void enter(StateType prevState)
{
clearAll();
map.clearAll();
@@ -77,17 +77,19 @@ public class StateSelect extends StateCommon
}
@Override
- public void abort()
+ public StateType abort()
{
if (selectedHex != null)
map.unselectHex(selectedHex);
hidePossibleTargetsMovesAssists();
clearAll();
map.clearAll();
+ return StateType.ABORT;
}
@Override
- public void done()
+ public StateType done()
{
+ return StateType.DONE;
}
}