diff options
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Ctrl.java | 14 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Hud.java | 11 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/State.java | 1 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateEscape.java | 68 |
4 files changed, 94 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java index 901a36d..234b1f9 100644 --- a/core/src/ch/asynk/tankontank/game/Ctrl.java +++ b/core/src/ch/asynk/tankontank/game/Ctrl.java @@ -14,6 +14,7 @@ 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.game.states.StateEscape; import ch.asynk.tankontank.screens.OptionsScreen; @@ -39,6 +40,7 @@ public class Ctrl implements Disposable private State animationState; private State reinforcementState; private State deploymentState; + private State escapeState; private int animationCount = 0; @@ -67,6 +69,7 @@ public class Ctrl implements Disposable this.animationState = new StateAnimation(); this.reinforcementState = new StateReinforcement(); this.deploymentState = new StateDeployment(); + this.escapeState = new StateEscape(); this.state = selectState; this.stateType = StateType.DONE; @@ -226,6 +229,9 @@ public class Ctrl implements Disposable case BREAK: this.state = breakState; break; + case ESCAPE: + this.state = escapeState; + break; case ANIMATION: this.state = animationState; break; @@ -305,4 +311,12 @@ public class Ctrl implements Disposable state.abort(); switchPlayer(); } + + public void exitBoard(boolean doit) + { + if (doit) + setState(StateType.DONE); + else + setState(StateType.ABORT); + } } diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java index 57d96fb..0c503bf 100644 --- a/core/src/ch/asynk/tankontank/game/Hud.java +++ b/core/src/ch/asynk/tankontank/game/Hud.java @@ -37,6 +37,7 @@ public class Hud implements Disposable enum DialogAction { + EXIT_BOARD, END_TURN, END_DEPLOYMENT, END_GAME @@ -165,6 +166,9 @@ public class Hud implements Disposable boolean ok = okCancel.ok; switch(dialogAction) { + case EXIT_BOARD: + ctrl.exitBoard(ok); + break; case END_TURN: if (ok) ctrl.abortPlayerTurn(); @@ -189,6 +193,13 @@ public class Hud implements Disposable okCancel.show("You have no more Action Points left.", Position.MIDDLE_CENTER, false); } + public void askExitBoard() + { + ctrl.blockMap = true; + dialogAction = DialogAction.EXIT_BOARD; + okCancel.show("Do you want this unit to escape the battle fierd ?", Position.MIDDLE_CENTER); + } + public void askEndOfTurn() { ctrl.blockMap = true; diff --git a/core/src/ch/asynk/tankontank/game/State.java b/core/src/ch/asynk/tankontank/game/State.java index dc6854c..2c19955 100644 --- a/core/src/ch/asynk/tankontank/game/State.java +++ b/core/src/ch/asynk/tankontank/game/State.java @@ -12,6 +12,7 @@ public interface State ANIMATION, REINFORCEMENT, DEPLOYMENT, + ESCAPE, ABORT, DONE }; diff --git a/core/src/ch/asynk/tankontank/game/states/StateEscape.java b/core/src/ch/asynk/tankontank/game/states/StateEscape.java new file mode 100644 index 0000000..7ff9fa8 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/states/StateEscape.java @@ -0,0 +1,68 @@ +package ch.asynk.tankontank.game.states; + +import ch.asynk.tankontank.engine.Zone; +import ch.asynk.tankontank.game.Unit; + +public class StateEscape extends StateCommon +{ + @Override + public void enter(StateType prevState) + { + ctrl.hud.askExitBoard(); + } + + @Override + public void leave(StateType nextState) + { + } + + @Override + public StateType abort() + { + return StateType.MOVE; + } + + @Override + public StateType done() + { + if (activeUnit == null) + activeUnit = selectedUnit; + + ctrl.setAnimationCount(1); + ctrl.setAfterAnimationState(escape(activeUnit)); + return StateType.ANIMATION; + } + + @Override + public void touchDown() + { + } + + @Override + public void touchUp() + { + } + + private StateType escape(Unit unit) + { + ctrl.hud.notify("Escape " + unit); + + Zone exitZone = ctrl.battle.getExitZone(unit); + + if (map.possiblePaths.size() == 1) + map.possiblePaths.setExit(exitZone.orientation); + else + map.possiblePaths.build(map.getAdjTileAt(unit.getTile(), exitZone.orientation)); + + unit.hideMoveable(); + map.hidePossibleMoves(); + map.unselectHex(unit.getHex()); + + map.leaveBoard(unit); + ctrl.player.unitEscape(unit); + + if (map.movePawn(activeUnit, exitZone.orientation) > 0) + return StateType.MOVE; + return StateType.DONE; + } +} |