diff options
Diffstat (limited to 'core/src/ch/asynk/tankontank/game')
11 files changed, 105 insertions, 119 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java index b65547c..cee17d8 100644 --- a/core/src/ch/asynk/tankontank/game/Ctrl.java +++ b/core/src/ch/asynk/tankontank/game/Ctrl.java @@ -42,6 +42,7 @@ public class Ctrl implements Disposable private State state; private State.StateType stateType; + private State.StateType stateAfterAnimation; public Ctrl(final TankOnTank game, final Battle battle) { @@ -65,16 +66,15 @@ public class Ctrl implements Disposable this.reinforcementState = new StateReinforcement(); this.state = selectState; - this.stateType = State.StateType.SELECT; + this.stateType = State.StateType.DONE; this.hud = new Hud(this, game); this.blockMap = false; this.blockHud = false; - player.turnStart(); - hud.playerInfo.update(player, battle.getHudPosition(player)); - hud.notify(battle.toString(), 2, Position.MIDDLE_CENTER, false); + startPlayerTurn(); + setState(battle.getState(player)); } @Override @@ -103,7 +103,7 @@ public class Ctrl implements Disposable { animationCount -= 1; if (animationCount == 0) - state.done(); + setState(stateAfterAnimation); if (animationCount < 0) TankOnTank.debug(" animationCount < 0"); } @@ -134,14 +134,33 @@ public class Ctrl implements Disposable startPlayerTurn(); } - private void checkTurnEnd() + private State.StateType actionAborted() + { + hud.notify("Action canceled"); + State.StateType nextState = this.state.abort(); + + if (nextState == State.StateType.ABORT) + nextState = battle.getState(player); + + return nextState; + } + + private State.StateType actionDone() { + State.StateType nextState = this.state.done(); + if (map.activatedPawns.size() > 0) { player.burnDownOneAp(); hud.playerInfo.update(player, battle.getHudPosition(player)); } + if (player.apExhausted()) swicthPlayer(); + + if (nextState == State.StateType.DONE) + nextState = battle.getState(player); + + return nextState; } public void stateTouchUp() @@ -160,27 +179,27 @@ public class Ctrl implements Disposable } } - public void setState(State.StateType state) + public void setState(State.StateType nextState) { - if (state == State.StateType.ABORT) { - hud.notify("Action canceled"); - this.state.abort(); - } - else if (state == State.StateType.DONE) - this.state.done(); - else - setState(state, true); + setState(nextState, battle.getState(player)); } - public void setState(State.StateType state, boolean normal) + public void setState(State.StateType nextState, State.StateType whenDone) { - this.state.leave(state); + if (nextState == State.StateType.ABORT) + nextState = actionAborted(); + else if (nextState == State.StateType.DONE) + nextState = actionDone(); + else if (nextState == State.StateType.ANIMATION) + stateAfterAnimation = whenDone; + + this.state.leave(nextState); - TankOnTank.debug(" switch to : " + state + " " + normal); - switch(state) { + TankOnTank.debug(" switch to : " + nextState); + + switch(nextState) { case SELECT: this.state = selectState; - checkTurnEnd(); break; case MOVE: this.state = pathState; @@ -206,9 +225,10 @@ public class Ctrl implements Disposable default: break; } - stateType = state; - this.state.enter(normal); + this.state.enter(stateType); + + stateType = nextState; } public void touchDown(float hx, float hy, float mx, float my) diff --git a/core/src/ch/asynk/tankontank/game/State.java b/core/src/ch/asynk/tankontank/game/State.java index 70cc08b..eeecdd7 100644 --- a/core/src/ch/asynk/tankontank/game/State.java +++ b/core/src/ch/asynk/tankontank/game/State.java @@ -15,13 +15,13 @@ public interface State DONE }; - public void enter(boolean flag); + public void enter(StateType prevState); public void leave(StateType nextState); - public void abort(); + public StateType abort(); - public void done(); + public StateType done(); public void touchDown(); @@ -30,8 +30,4 @@ public interface State public boolean downInMap(float x, float y); public boolean upInMap(float x, float y); - - public StateType getNextState(); - - public void setNextState(StateType next); } 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; } } |