diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-06 16:31:11 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-06 16:31:11 +0200 |
commit | ad6e417ec0186ae827d662cd454f575c5d045b27 (patch) | |
tree | 39fc1b9cafd99d71fc6951a97b0dc52cb8f7cf9e | |
parent | 940cf359bdc79875dfd58725eca41f8bf4b6f47a (diff) | |
download | RustAndDust-ad6e417ec0186ae827d662cd454f575c5d045b27.zip RustAndDust-ad6e417ec0186ae827d662cd454f575c5d045b27.tar.gz |
rewrite GameState ...
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java | 27 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/GameStateDirection.java | 22 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/GameStateMove.java (renamed from core/src/ch/asynk/tankontank/game/states/GameStatePath.java) | 62 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/GameStateNone.java | 37 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/GameStateRotate.java | 72 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/GameStateView.java | 39 |
6 files changed, 198 insertions, 61 deletions
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java b/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java new file mode 100644 index 0000000..c4a2dd8 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/states/GameStateAnimation.java @@ -0,0 +1,27 @@ +package ch.asynk.tankontank.game.states; + +public class GameStateAnimation extends GameStateCommon +{ + @Override + public void enter() + { + } + + @Override + public void touchDown() + { + } + + @Override + public void touchUp() + { + } + + @Override + public void abort() + { + unselectHex(); + pawn = null; + super.abort(); + } +} diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java index 39f3743..178185c 100644 --- a/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java +++ b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java @@ -5,6 +5,11 @@ import ch.asynk.tankontank.engine.Orientation; public class GameStateDirection extends GameStateCommon { @Override + public void enter() + { + } + + @Override public void touchDown() { } @@ -35,11 +40,22 @@ public class GameStateDirection extends GameStateCommon } } - if (o != Orientation.KEEP) + if (o != Orientation.KEEP) { map.movePawn(pawn, o); + clear(); + ctrl.setState(State.ANIMATION); + } + } + @Override + public void abort() + { + super.abort(); + clear(); + } + + private void clear() + { map.enableFinalPath(hex, false); - map.resetPaths(); - ctrl.setState(State.NONE, false); } } diff --git a/core/src/ch/asynk/tankontank/game/states/GameStatePath.java b/core/src/ch/asynk/tankontank/game/states/GameStateMove.java index 9ffd111..2bdf52f 100644 --- a/core/src/ch/asynk/tankontank/game/states/GameStatePath.java +++ b/core/src/ch/asynk/tankontank/game/states/GameStateMove.java @@ -2,44 +2,74 @@ package ch.asynk.tankontank.game.states; import com.badlogic.gdx.math.GridPoint2; -public class GameStatePath extends GameStateCommon +public class GameStateMove extends GameStateCommon { + private boolean skipFirst; private GridPoint2 from = new GridPoint2(-1, -1); private GridPoint2 to = new GridPoint2(-1, -1); @Override public void touchDown() { + if (pawn == null) { + super.touchDown(); + if (hexHasUnit()) { + // TODO maybe keep the the previous hex + // FIXME must be one of it's own + setPawn(); + skipFirst = true; + map.buildAndShowPossibleMoves(pawn, hex); + } + } } @Override public void touchUp() { + if (pawn == null) { + unselectHex(); + return; + } + + if (skipFirst) { + skipFirst = false; + return; + } + int s = map.possiblePathsSize(); + if (s == 0) { - s = buildPaths(); + if (map.isInPossibleMoves(upHex)) + s = buildPaths(); } else { - if (map.isInPossiblePaths(downHex)) + if (map.isInPossiblePaths(upHex)) s = togglePoint(); - else - s = reset(); } if (s == 1) { unselectHex(); hex.set(to.x, to.y); map.enableFinalPath(to, true); - ctrl.setState(State.DIRECTION, false); + ctrl.setState(State.DIRECTION); } } + @Override + public void abort() + { + to.set(-1, -1); + from.set(-1, -1); + super.abort(); + } + private int buildPaths() { from.set(hex.x, hex.y); - to.set(downHex.x, downHex.y); + to.set(upHex.x, upHex.y); + map.clearPossiblePaths(); int s = map.buildPossiblePaths(pawn, from, to); + map.togglePathOverlay(downHex); map.enablePossibleMoves(false); - map.toggleDotOverlay(downHex); map.enablePossiblePaths(true, true); return s; } @@ -48,25 +78,15 @@ public class GameStatePath extends GameStateCommon { int s = 0; if ((downHex.x == from.x) && (downHex.y == from.y)) { - s = map.possiblePathsSize(); + // s = map.possiblePathsSize(); } else if ((downHex.x == to.x) && (downHex.y == to.y)) { - s = reset(); + // s = map.possiblePathsSize(); } else { map.enablePossiblePaths(false, true); - map.toggleDotOverlay(downHex); + map.togglePathOverlay(downHex); s = map.possiblePathsPointToggle(downHex); map.enablePossiblePaths(true, true); } return s; } - - private int reset() - { - to.set(-1, -1); - from.set(-1, -1); - map.hidePaths(); - map.resetPaths(); - ctrl.setState(State.NONE, false); - return -1; - } } diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateNone.java b/core/src/ch/asynk/tankontank/game/states/GameStateNone.java deleted file mode 100644 index bec92ee..0000000 --- a/core/src/ch/asynk/tankontank/game/states/GameStateNone.java +++ /dev/null @@ -1,37 +0,0 @@ -package ch.asynk.tankontank.game.states; - -import ch.asynk.tankontank.game.Map; -import ch.asynk.tankontank.game.GameCtrl; - -public class GameStateNone extends GameStateCommon -{ - public GameStateNone(GameCtrl ctrl, Map map) - { - super(ctrl, map); - } - - @Override - public void touchDown() - { - if (map.isInPossibleMoves(downHex)) { - map.enablePossibleTargets(false); - ctrl.setState(State.PATH, true); - } else { - unselectHex(); - setHex(); - selectHex(); - } - } - - @Override - public void touchUp() - { - if (hexHasUnit()) { - setPawn(); - map.showPossibleActions(pawn, hex, true); - } else { - map.showPossibleActions(pawn, hex, false); - unselectHex(); - } - } -} diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java b/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java new file mode 100644 index 0000000..2be7ee3 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java @@ -0,0 +1,72 @@ +package ch.asynk.tankontank.game.states; + +import ch.asynk.tankontank.engine.Orientation; + +public class GameStateRotate extends GameStateCommon +{ + @Override + public void touchDown() + { + if (pawn == null) { + super.touchDown(); + if (hexHasUnit()) { + // TODO maybe keep the the previous hex + // FIXME must be one of it's own + setPawn(); + map.enableDirections(hex, true); + } + } + } + + @Override + public void touchUp() + { + if (pawn == null) { + unselectHex(); + return; + } + + Orientation o = Orientation.KEEP; + + if (downHex.y == hex.y) { + if (downHex.x == (hex.x - 1)) { + o = Orientation.SOUTH; + } else if (downHex.x == (hex.x + 1)) { + o = Orientation.NORTH; + } + } else if (downHex.y == (hex.y - 1)) { + if (downHex.x == (hex.x - 1)) { + o = Orientation.SOUTH_EAST; + } else if (downHex.x == hex.x) { + o = Orientation.NORTH_EAST; + } + + } else if (downHex.y == (hex.y + 1)) { + if (downHex.x == hex.x) { + o = Orientation.SOUTH_WEST; + } else if (downHex.x == (hex.x + 1)) { + o = Orientation.NORTH_WEST; + } + } + + if (o != Orientation.KEEP) { + clear(); + map.rotatePawn(pawn, o); + ctrl.setState(State.ANIMATION); + } + + } + + @Override + public void abort() + { + clear(); + super.abort(); + } + + private void clear() + { + unselectHex(); + map.enableDirections(hex, false); + } +} diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateView.java b/core/src/ch/asynk/tankontank/game/states/GameStateView.java new file mode 100644 index 0000000..f993fa4 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/states/GameStateView.java @@ -0,0 +1,39 @@ +package ch.asynk.tankontank.game.states; + +import ch.asynk.tankontank.game.Map; +import ch.asynk.tankontank.game.GameCtrl; + +public class GameStateView extends GameStateCommon +{ + public GameStateView(GameCtrl ctrl, Map map) + { + super(ctrl, map); + } + + @Override + public void touchUp() + { + if (hexHasUnit()) { + // FIXME must be one of it's own + setPawn(); + map.buildAndShowPossibleMoves(pawn, hex); + map.buildAndShowPossibleTargets(pawn, hex); + } else { + clear(); + } + } + + @Override + public void abort() + { + clear(); + super.abort(); + } + + private void clear() + { + map.enablePossibleMoves(false); + map.enablePossibleTargets(false); + unselectHex(); + } +} |