diff options
Diffstat (limited to 'core')
5 files changed, 51 insertions, 109 deletions
diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java b/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java index 524b28f..249288e 100644 --- a/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java +++ b/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java @@ -3,7 +3,6 @@ package ch.asynk.tankontank.game.states; import com.badlogic.gdx.math.GridPoint2; import ch.asynk.tankontank.engine.Pawn; -import ch.asynk.tankontank.engine.Tile; import ch.asynk.tankontank.game.Map; import ch.asynk.tankontank.game.Hex; import ch.asynk.tankontank.game.GameCtrl; @@ -14,8 +13,8 @@ public abstract class GameStateCommon implements GameState protected static GameCtrl ctrl; protected static Map map; protected static Pawn pawn; - protected static Tile tile; 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); @@ -31,27 +30,11 @@ public abstract class GameStateCommon implements GameState } @Override - public void enter() - { - map.hidePossibles(); - unselectHex(); - pawn = null; - } - - @Override public void abort() { ctrl.setState(State.VIEW); } - @Override - public void touchDown() - { - unselectHex(); - setHex(); - selectHex(); - } - protected static boolean hexInMap(GridPoint2 hex) { if (hex.x == -1) return false; @@ -70,20 +53,16 @@ public abstract class GameStateCommon implements GameState return hexInMap(upHex); } - protected void setPawn() + protected void setHexAndPawn(GridPoint2 point) { + hex.set(point.x, point.y); + // TODO : is an enemy or not ? pawn = map.getTopPawnAt(hex); } - protected void setHex() + protected boolean hasPawn() { - hex.set(downHex.x, downHex.y); - pawn = null; - } - - protected boolean hexHasUnit() - { - return map.hasUnits(hex); + return (pawn != null); } protected void unselectHex() @@ -96,6 +75,13 @@ public abstract class GameStateCommon implements GameState map.enableOverlayOn(hex, Hex.BLUE, true); } + protected void reselect() + { + unselectHex(); + setHexAndPawn(downHex); + selectHex(); + } + protected boolean sameHexes(GridPoint2 a, GridPoint2 b) { return ((a.x == b.x) && (a.y == b.y)); diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java index 178185c..4615075 100644 --- a/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java +++ b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java @@ -17,32 +17,14 @@ public class GameStateDirection extends GameStateCommon @Override public void touchUp() { - 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; - } - } + Orientation o = Orientation.fromAdj(tmp.x, tmp.y, downHex.x, downHex.y); if (o != Orientation.KEEP) { map.movePawn(pawn, o); clear(); + unselectHex(); + hex.set(tmp.x, tmp.y); + selectHex(); ctrl.setState(State.ANIMATION); } } @@ -56,6 +38,6 @@ public class GameStateDirection extends GameStateCommon private void clear() { - map.enableFinalPath(hex, false); + map.enableFinalPath(tmp, false); } } diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateMove.java b/core/src/ch/asynk/tankontank/game/states/GameStateMove.java index f99dc75..0cb880e 100644 --- a/core/src/ch/asynk/tankontank/game/states/GameStateMove.java +++ b/core/src/ch/asynk/tankontank/game/states/GameStateMove.java @@ -13,8 +13,7 @@ public class GameStateMove extends GameStateCommon { map.enablePossibleTargets(false); map.enablePossiblePaths(false, false); - if (pawn != null) { - // FIXME must be one of it's own + if (hasPawn()) { skipFirst = false; map.clearPossiblePaths(); map.buildAndShowPossibleMoves(pawn, hex); @@ -24,11 +23,9 @@ public class GameStateMove extends GameStateCommon @Override public void touchDown() { - if (pawn == null) { - super.touchDown(); - if (hexHasUnit()) { - // FIXME must be one of it's own - setPawn(); + if (!hasPawn()) { + reselect(); + if (hasPawn()) { skipFirst = true; map.clearPossiblePaths(); map.buildAndShowPossibleMoves(pawn, hex); @@ -39,7 +36,7 @@ public class GameStateMove extends GameStateCommon @Override public void touchUp() { - if (pawn == null) { + if (!hasPawn()) { unselectHex(); return; } @@ -56,12 +53,11 @@ public class GameStateMove extends GameStateCommon s = buildPaths(); } else { if (map.isInPossiblePaths(upHex)) - s = togglePoint(); + s = togglePoint(s); } if (s == 1) { - unselectHex(); - hex.set(to.x, to.y); + tmp.set(to.x, to.y); map.enableFinalPath(to, true); ctrl.setState(State.DIRECTION); } @@ -87,19 +83,19 @@ public class GameStateMove extends GameStateCommon return s; } - private int togglePoint() + private int togglePoint(int s) { - int s = 0; - if ((downHex.x == from.x) && (downHex.y == from.y)) { - // s = map.possiblePathsSize(); - } else if ((downHex.x == to.x) && (downHex.y == to.y)) { - // s = map.possiblePathsSize(); + if (sameHexes(downHex, from)) { + // + } else if (sameHexes(downHex, to)) { + // } else { map.enablePossiblePaths(false, true); map.togglePathOverlay(downHex); s = map.possiblePathsPointToggle(downHex); map.enablePossiblePaths(true, true); } + return s; } } diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java b/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java index 14fd2a8..4d36e22 100644 --- a/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java +++ b/core/src/ch/asynk/tankontank/game/states/GameStateRotate.java @@ -8,8 +8,7 @@ public class GameStateRotate extends GameStateCommon public void enter() { map.hidePossibles(); - if (pawn != null) { - // FIXME must be one of it's own + if (hasPawn()) { map.enableDirections(hex, true); } } @@ -17,11 +16,9 @@ public class GameStateRotate extends GameStateCommon @Override public void touchDown() { - if (pawn == null) { - super.touchDown(); - if (hexHasUnit()) { - // FIXME must be one of it's own - setPawn(); + if (!hasPawn()) { + reselect(); + if (hasPawn()) { map.enableDirections(hex, true); } } @@ -30,36 +27,15 @@ public class GameStateRotate extends GameStateCommon @Override public void touchUp() { - if (pawn == null) { + if (!hasPawn()) { 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; - } - } + Orientation o = Orientation.fromAdj(hex.x, hex.y, downHex.x, downHex.y); if (o != Orientation.KEEP) { - clear(); + map.enableDirections(hex, false); if (pawn.getOrientation() != o) { map.rotatePawn(pawn, o); ctrl.setState(State.ANIMATION); @@ -73,13 +49,7 @@ public class GameStateRotate extends GameStateCommon @Override public void abort() { - clear(); - super.abort(); - } - - private void clear() - { - unselectHex(); map.enableDirections(hex, false); + super.abort(); } } diff --git a/core/src/ch/asynk/tankontank/game/states/GameStateView.java b/core/src/ch/asynk/tankontank/game/states/GameStateView.java index f993fa4..74f1ca3 100644 --- a/core/src/ch/asynk/tankontank/game/states/GameStateView.java +++ b/core/src/ch/asynk/tankontank/game/states/GameStateView.java @@ -11,11 +11,20 @@ public class GameStateView extends GameStateCommon } @Override + public void enter() + { + } + + @Override + public void touchDown() + { + reselect(); + } + + @Override public void touchUp() { - if (hexHasUnit()) { - // FIXME must be one of it's own - setPawn(); + if (hasPawn()) { map.buildAndShowPossibleMoves(pawn, hex); map.buildAndShowPossibleTargets(pawn, hex); } else { @@ -34,6 +43,5 @@ public class GameStateView extends GameStateCommon { map.enablePossibleMoves(false); map.enablePossibleTargets(false); - unselectHex(); } } |