summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-08 20:26:21 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-08 20:26:21 +0200
commit428f1b0bf6218d105415dac0530cac9ea74b3def (patch)
tree1a93af346594113b3e632f6c84fc06b5becb0dd0 /core/src/ch/asynk/tankontank/game
parentad70685c05f6a7098c3fd703417f2d6e21ad01a1 (diff)
downloadRustAndDust-428f1b0bf6218d105415dac0530cac9ea74b3def.zip
RustAndDust-428f1b0bf6218d105415dac0530cac9ea74b3def.tar.gz
GameState*: add leave() called before switching, cleanup all
Diffstat (limited to 'core/src/ch/asynk/tankontank/game')
-rw-r--r--core/src/ch/asynk/tankontank/game/GameCtrl.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/GameState.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java5
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateCommon.java5
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateDirection.java30
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateMove.java65
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateRotate.java29
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateSelect.java26
8 files changed, 76 insertions, 90 deletions
diff --git a/core/src/ch/asynk/tankontank/game/GameCtrl.java b/core/src/ch/asynk/tankontank/game/GameCtrl.java
index 6e8fc6c..7951f80 100644
--- a/core/src/ch/asynk/tankontank/game/GameCtrl.java
+++ b/core/src/ch/asynk/tankontank/game/GameCtrl.java
@@ -83,12 +83,13 @@ public class GameCtrl implements Disposable
public void animationDone()
{
- hud.reset();
setState(GameState.State.VIEW);
}
public void setState(GameState.State state)
{
+ this.state.leave();
+
switch(state) {
case VIEW:
this.state = selectState;
@@ -104,7 +105,6 @@ public class GameCtrl implements Disposable
break;
case ANIMATION:
this.state = animationState;
- hud.disableCancel();
break;
default:
break;
diff --git a/core/src/ch/asynk/tankontank/game/GameState.java b/core/src/ch/asynk/tankontank/game/GameState.java
index 316129e..c64c51e 100644
--- a/core/src/ch/asynk/tankontank/game/GameState.java
+++ b/core/src/ch/asynk/tankontank/game/GameState.java
@@ -12,6 +12,8 @@ public interface GameState
public void enter();
+ public void leave();
+
public void abort();
public void touchDown();
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java b/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java
index 435a066..a7e69a3 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java
@@ -8,6 +8,11 @@ public class GameStateAnimation extends GameStateCommon
}
@Override
+ public void leave()
+ {
+ }
+
+ @Override
public void touchDown()
{
}
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java b/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java
index 8c52b83..04708f8 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java
@@ -14,7 +14,6 @@ public abstract class GameStateCommon implements GameState
protected static Map map;
protected static Pawn pawn;
protected static GridPoint2 hex = new GridPoint2(0, 0);
- protected static GridPoint2 tmp = new GridPoint2(0, 0);
protected static GridPoint2 downHex = new GridPoint2(-1, -1);
protected static GridPoint2 upHex = new GridPoint2(-1, -1);
@@ -35,6 +34,10 @@ public abstract class GameStateCommon implements GameState
@Override
public void abort()
{
+ unselectHex(hex);
+ hex.set(0, 0);
+ pawn = null;
+ ctrl.hud.hide();
ctrl.setState(State.VIEW);
}
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java
index e6a05f3..7687e91 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java
@@ -7,6 +7,18 @@ public class GameStateDirection extends GameStateCommon
@Override
public void enter()
{
+ map.enableFinalPath(to, true);
+ }
+
+ @Override
+ public void leave()
+ {
+ map.enableMoveAssists(false);
+ map.enableFinalPath(to, false);
+ if (to.x != -1) unselectHex(to);
+ if (from.x != -1) unselectHex(from);
+ to.set(-1, -1);
+ from.set(-1, -1);
}
@Override
@@ -17,14 +29,11 @@ public class GameStateDirection extends GameStateCommon
@Override
public void touchUp()
{
- Orientation o = Orientation.fromAdj(tmp.x, tmp.y, downHex.x, downHex.y);
+ Orientation o = Orientation.fromAdj(to.x, to.y, downHex.x, downHex.y);
if (o != Orientation.KEEP) {
map.movePawn(pawn, o);
- clear();
- unselectHex(hex);
- hex.set(tmp.x, tmp.y);
- unselectHex(hex);
+ ctrl.hud.hide();
ctrl.setState(State.ANIMATION);
}
}
@@ -32,17 +41,6 @@ public class GameStateDirection extends GameStateCommon
@Override
public void abort()
{
- clear();
super.abort();
}
-
- private void clear()
- {
- map.enableFinalPath(tmp, false);
- if (ctrl.cfg.showMoveAssists) map.enableMoveAssists(false);
- if (to.x != -1) unselectHex(to);
- if (from.x != -1) unselectHex(to);
- to.set(-1, -1);
- from.set(-1, -1);
- }
}
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateMove.java b/core/src/ch/asynk/tankontank/game/states/GameStateMove.java
index 91ce9e1..7e69676 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateMove.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateMove.java
@@ -2,47 +2,27 @@ package ch.asynk.tankontank.game.states;
public class GameStateMove extends GameStateCommon
{
- private boolean skipFirst;
-
@Override
public void enter()
{
- map.enablePossibleTargets(false);
- map.enablePossiblePaths(false, false);
- if (hasPawn()) {
- selectHex(hex);
- skipFirst = false;
- map.clearPossiblePaths();
- buildAndShowMoves();
- }
+ map.clearPossiblePaths();
+ buildAndShowMoves();
+ ctrl.hud.show(false, true, false, true, true);
+ }
+
+ @Override
+ public void leave()
+ {
}
@Override
public void touchDown()
{
- if (!hasPawn()) {
- reselectHex();
- if (hasPawn()) {
- skipFirst = true;
- map.clearPossiblePaths();
- buildAndShowMoves();
- }
- }
}
@Override
public void touchUp()
{
- if (!hasPawn()) {
- unselectHex(hex);
- return;
- }
-
- if (skipFirst) {
- skipFirst = false;
- return;
- }
-
int s = map.possiblePathsSize();
if (s == 0) {
@@ -53,17 +33,24 @@ public class GameStateMove extends GameStateCommon
s = togglePoint(s);
}
- if (s == 1) {
- tmp.set(to.x, to.y);
- map.enableFinalPath(to, true);
+ if (s == 1)
ctrl.setState(State.DIRECTION);
- }
}
@Override
public void abort()
{
- clear();
+ map.enableMoveAssists(false);
+ map.enablePossibleMoves(false);
+ if (from.x != -1) {
+ unselectHex(from);
+ from.set(-1, -1);
+ }
+ if (to.x != -1) {
+ unselectHex(to);
+ map.enableFinalPath(to, false);
+ to.set(-1, -1);
+ }
super.abort();
}
@@ -77,22 +64,10 @@ public class GameStateMove extends GameStateCommon
map.enableMoveAssists(true);
}
- private void clear()
- {
- map.enableMoveAssists(false);
- map.enablePossibleMoves(false);
- map.enableFinalPath(tmp, false);
- if (to.x != -1) unselectHex(to);
- if (from.x != -1) unselectHex(to);
- to.set(-1, -1);
- from.set(-1, -1);
- }
-
private int buildPaths()
{
from.set(hex.x, hex.y);
to.set(upHex.x, upHex.y);
- map.clearPossiblePaths();
int s = map.buildPossiblePaths(pawn, from, to);
selectHex(to);
map.enablePossibleMoves(false);
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java b/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java
index 17e40f2..9296157 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java
@@ -7,43 +7,35 @@ public class GameStateRotate extends GameStateCommon
@Override
public void enter()
{
- showPossibleTargetsMovesAssists(false);
- if (hasPawn()) {
- selectHex(hex);
- map.enableDirections(hex, true);
- }
+ map.enableDirections(hex, true);
+ ctrl.hud.show(true, false, false, true, true);
+ }
+
+ @Override
+ public void leave()
+ {
+ unselectHex(hex);
+ map.enableDirections(hex, false);
}
@Override
public void touchDown()
{
- if (!hasPawn()) {
- reselectHex();
- if (hasPawn()) {
- map.enableDirections(hex, true);
- }
- }
}
@Override
public void touchUp()
{
- if (!hasPawn()) {
- unselectHex(hex);
- return;
- }
-
Orientation o = Orientation.fromAdj(hex.x, hex.y, downHex.x, downHex.y);
if (o != Orientation.KEEP) {
- unselectHex(hex);
- map.enableDirections(hex, false);
if (pawn.getOrientation() != o) {
map.rotatePawn(pawn, o);
ctrl.setState(State.ANIMATION);
} else {
ctrl.animationDone();
}
+ ctrl.hud.hide();
}
}
@@ -51,7 +43,6 @@ public class GameStateRotate extends GameStateCommon
@Override
public void abort()
{
- map.enableDirections(hex, false);
super.abort();
}
}
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateSelect.java b/core/src/ch/asynk/tankontank/game/states/GameStateSelect.java
index be96afd..5ec9240 100644
--- a/core/src/ch/asynk/tankontank/game/states/GameStateSelect.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateSelect.java
@@ -16,6 +16,12 @@ public class GameStateSelect extends GameStateCommon
}
@Override
+ public void leave()
+ {
+ showPossibleTargetsMovesAssists(false);
+ }
+
+ @Override
public void touchDown()
{
reselectHex();
@@ -24,17 +30,23 @@ public class GameStateSelect extends GameStateCommon
@Override
public void touchUp()
{
- int moves = 0;
- int targets = 0;
- int assists = 0;
showPossibleTargetsMovesAssists(false);
if (hasPawn()) {
- moves = map.buildPossibleMoves(pawn, hex);
- targets = map.buildPossibleTargets(pawn, hex);
- assists = map.buildMoveAssists(pawn, hex);
+ int moves = map.buildPossibleMoves(pawn, hex);
+ int targets = map.buildPossibleTargets(pawn, hex);
+ int assists = map.buildMoveAssists(pawn, hex);
showPossibleTargetsMovesAssists(true);
- } else
+ ctrl.hud.show(
+ pawn.canMove(),
+ (pawn.canMove() && (moves > 0)),
+ (pawn.canAttack() && (targets > 0)),
+ false,
+ false
+ );
+ } else {
+ ctrl.hud.hide();
map.clearPossibleTargetsMovesAssists();
+ }
}
@Override