summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-09 16:10:21 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-09 16:10:21 +0200
commitd71752cb7527ffac3fb25aea2c460bc18a3e3a5e (patch)
treed1f8e51dc3aebcb7c6c7888734024d4b72edd40c /core/src
parent7983c8ba5954bd2b6461e69d866b37694810c918 (diff)
downloadRustAndDust-d71752cb7527ffac3fb25aea2c460bc18a3e3a5e.zip
RustAndDust-d71752cb7527ffac3fb25aea2c460bc18a3e3a5e.tar.gz
GameState,GameCtrl: add nextState var => void enter(boolean reset)
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/tankontank/game/GameCtrl.java13
-rw-r--r--core/src/ch/asynk/tankontank/game/GameState.java8
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateCommon.java16
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateDirection.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateMove.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateRotate.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateSelect.java2
8 files changed, 36 insertions, 11 deletions
diff --git a/core/src/ch/asynk/tankontank/game/GameCtrl.java b/core/src/ch/asynk/tankontank/game/GameCtrl.java
index 76f79ab..6202ef4 100644
--- a/core/src/ch/asynk/tankontank/game/GameCtrl.java
+++ b/core/src/ch/asynk/tankontank/game/GameCtrl.java
@@ -87,15 +87,22 @@ public class GameCtrl implements Disposable
public void animationDone()
{
- setState(GameState.State.VIEW);
+ GameState.State next = state.getNextState();
+ state.setNextState(GameState.State.SELECT);
+ setState(next, (next == GameState.State.SELECT));
}
public void setState(GameState.State state)
{
+ setState(state, true);
+ }
+
+ public void setState(GameState.State state, boolean reset)
+ {
this.state.leave();
switch(state) {
- case VIEW:
+ case SELECT:
this.state = selectState;
break;
case MOVE:
@@ -114,7 +121,7 @@ public class GameCtrl implements Disposable
break;
}
- this.state.enter();
+ this.state.enter(reset);
}
public void abort()
diff --git a/core/src/ch/asynk/tankontank/game/GameState.java b/core/src/ch/asynk/tankontank/game/GameState.java
index c64c51e..e8802bf 100644
--- a/core/src/ch/asynk/tankontank/game/GameState.java
+++ b/core/src/ch/asynk/tankontank/game/GameState.java
@@ -3,14 +3,14 @@ package ch.asynk.tankontank.game;
public interface GameState
{
enum State {
- VIEW,
+ SELECT,
MOVE,
DIRECTION,
ROTATE,
ANIMATION
};
- public void enter();
+ public void enter(boolean reset);
public void leave();
@@ -23,4 +23,8 @@ public interface GameState
public boolean downInMap(float x, float y);
public boolean upInMap(float x, float y);
+
+ public GameState.State getNextState();
+
+ public void setNextState(GameState.State next);
}
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java b/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java
index a7e69a3..5bb63fa 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java
@@ -3,7 +3,7 @@ package ch.asynk.tankontank.game.states;
public class GameStateAnimation extends GameStateCommon
{
@Override
- public void enter()
+ public void enter(boolean reset)
{
}
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java b/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java
index d7e17d4..4288ba0 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java
@@ -21,6 +21,8 @@ public abstract class GameStateCommon implements GameState
protected static GridPoint2 from = new GridPoint2(-1, -1);
protected static GridPoint2 to = new GridPoint2(-1, -1);
+ protected static GameState.State nextState = GameState.State.SELECT;
+
protected GameStateCommon()
{
}
@@ -32,13 +34,25 @@ public abstract class GameStateCommon implements GameState
}
@Override
+ public GameState.State getNextState()
+ {
+ return nextState;
+ }
+
+ @Override
+ public void setNextState(GameState.State state)
+ {
+ nextState = state;
+ }
+
+ @Override
public void abort()
{
unselectHex(hex);
hex.set(0, 0);
pawn = null;
ctrl.hud.hide();
- ctrl.setState(State.VIEW);
+ ctrl.setState(State.SELECT);
}
protected static boolean hexInMap(GridPoint2 hex)
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java
index eb6f22c..f1b2bb5 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java
@@ -5,7 +5,7 @@ import ch.asynk.tankontank.engine.Orientation;
public class GameStateDirection extends GameStateCommon
{
@Override
- public void enter()
+ public void enter(boolean reset)
{
map.showFinalPath(to, true);
}
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateMove.java b/core/src/ch/asynk/tankontank/game/states/GameStateMove.java
index 1331adc..8238cd8 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateMove.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateMove.java
@@ -3,7 +3,7 @@ package ch.asynk.tankontank.game.states;
public class GameStateMove extends GameStateCommon
{
@Override
- public void enter()
+ public void enter(boolean reset)
{
map.clearPossiblePaths();
buildAndShowMoves();
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java b/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java
index 75167ad..d3848b0 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java
@@ -5,7 +5,7 @@ import ch.asynk.tankontank.engine.Orientation;
public class GameStateRotate extends GameStateCommon
{
@Override
- public void enter()
+ public void enter(boolean reset)
{
map.showDirections(hex, true);
ctrl.hud.show(true, false, false, ctrl.cfg.mustValidate, ctrl.cfg.canCancel);
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateSelect.java b/core/src/ch/asynk/tankontank/game/states/GameStateSelect.java
index 49c15fc..bb15acc 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateSelect.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateSelect.java
@@ -11,7 +11,7 @@ public class GameStateSelect extends GameStateCommon
}
@Override
- public void enter()
+ public void enter(boolean reset)
{
}