summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java177
1 files changed, 63 insertions, 114 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 908007a..47fbff7 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -14,24 +14,6 @@ import ch.asynk.tankontank.engine.Pawn;
public abstract class Map extends Board
{
- enum Action {
- NONE,
- DRAG,
- PATH,
- DIRECTION,
- ATTACK
- };
-
- private Action action = Action.NONE;
-
- private Pawn pawn;
- private Pawn touchPawn;
- private GridPoint2 hex = new GridPoint2(-1, -1);
- private GridPoint2 touchHex = new GridPoint2(-1, -1);
-
- private GridPoint2 from = new GridPoint2(-1, -1);
- private GridPoint2 to = new GridPoint2(-1, -1);
-
private final Vector<GridPoint2> possibleMoves = new Vector<GridPoint2>(20);
private final Vector<GridPoint2> possibleTargets = new Vector<GridPoint2>(10);
private final HashSet<GridPoint2> possiblePaths = new HashSet<GridPoint2>(10);
@@ -49,129 +31,96 @@ public abstract class Map extends Board
return (Hex) getTile(col, row);
}
- public boolean drag(float dx, float dy)
+ public boolean isInPossibleMoves(GridPoint2 hex)
{
- if (pawn == null) return false;
- pawn.translate(dx, dy);
- return true;
+ return possibleMoves.contains(hex);
}
- public void touchDown(float x, float y)
+ public boolean isInPossiblePaths(GridPoint2 hex)
{
- if (hex.x != -1)
- enableOverlayOn(hex.x, hex.y, Hex.BLUE, false);
-
- getHexAt(touchHex, x, y);
- if (touchHex.x != -1) {
- enableOverlayOn(touchHex.x, touchHex.y, Hex.BLUE, true);
- touchPawn = removeTopPawnFrom(touchHex);
- if (action == Action.DIRECTION) {
- System.out.println("DIRECTION");
- enableFinalPath(false);
- action = Action.NONE;
- } else {
- if (touchPawn != null) {
- action = Action.DRAG;
- enablePossiblePaths(false, false);
- enablePossibleMoves(false);
- enablePossibleTargets(false);
- possiblePaths.clear();
- pawnsToDraw.add(touchPawn);
- pawn = touchPawn;
- } else if (possibleMoves.contains(touchHex)) {
- int paths = 0;
- action = Action.PATH;
- if (possiblePaths.size() > 0) {
- enablePossiblePaths(false, true);
- paths = possiblePathsFilterToggle(touchHex.x, touchHex.y, possiblePaths);
- toggleDotOverlay(touchHex.x, touchHex.y);
- } else {
- enablePossibleMoves(false);
- from.set(hex.x, hex.y);
- to.set(touchHex.x, touchHex.y);
- paths = possiblePaths(pawn, from.x, from.y, to.x, to.y, possiblePaths);
- enableOverlayOn(touchHex.x, touchHex.y, Hex.DOT, true);
- }
- if (paths != 1)
- enablePossiblePaths(true, true);
- else {
- enableFinalPath(true);
- action = Action.DIRECTION;
- }
- }
- }
- hex.set(touchHex.x, touchHex.y);
- } else {
- // touch out of map
- hex.set(-1, -1);
- }
+ return possiblePaths.contains(hex);
}
- public void touchUp(float x, float y)
+ public boolean isInPossibleTargets(GridPoint2 hex)
{
- if (hex.x != -1)
- enableOverlayOn(hex.x, hex.y, Hex.BLUE, false);
-
- getHexAt(touchHex, x, y);
- if (touchHex.x != -1) {
- hex.set(touchHex.x, touchHex.y);
- if (action == Action.DRAG) {
- enableOverlayOn(hex.x, hex.y, Hex.BLUE, true);
- pawnsToDraw.remove(pawn);
- movePawnTo(pawn, hex);
- showPossibleActions(pawn);
- action = Action.NONE;
- }
+ return possibleTargets.contains(hex);
+ }
+
+ public void enablePossibleMoves(boolean enable)
+ {
+ for(GridPoint2 hex : possibleMoves)
+ enableOverlayOn(hex, Hex.GREEN, enable);
+ }
+
+ public void enablePossibleTargets(boolean enable)
+ {
+ for(GridPoint2 hex : possibleTargets)
+ enableOverlayOn(hex, Hex.RED, enable);
+ }
+
+ public void enablePossiblePaths(boolean enable, boolean keepDots)
+ {
+ if (keepDots) {
+ for(GridPoint2 hex : possiblePaths)
+ enableOverlayOn(hex, Hex.GREEN, enable);
} else {
- // release out of map
- resetPawnMoves(pawn);
- hex.set(-1, -1);
+ for(GridPoint2 hex : possiblePaths) {
+ enableOverlayOn(hex, Hex.GREEN, enable);
+ enableOverlayOn(hex, Hex.DOT, false);
+ }
}
}
- private void showPossibleActions(Pawn pawn)
+ public void showPossibleActions(Pawn pawn, GridPoint2 hex, boolean enable)
{
- possibleMovesFrom(pawn, hex.x, hex.y, possibleMoves);
- enablePossibleMoves(true);
+ enablePossibleMoves(false);
+ enablePossibleTargets(false);
+ if (enable) {
+ possibleMovesFrom(pawn, hex, possibleMoves);
+ enablePossibleMoves(true);
+ possibleTargetsFrom(pawn, hex, possibleTargets);
+ enablePossibleTargets(true);
+ }
- possibleTargetsFrom(pawn, hex.x, hex.y, possibleTargets);
- enablePossibleTargets(true);
}
- private void enablePossibleMoves(boolean enable)
+ public int possiblePathsSize()
{
- for(GridPoint2 hex : possibleMoves)
- enableOverlayOn(hex.x, hex.y, Hex.GREEN, enable);
+ return possiblePaths.size();
}
- private void toggleDotOverlay(int col, int row)
+ public int buildPossiblePaths(Pawn pawn, GridPoint2 from, GridPoint2 to)
{
- boolean enable= !isOverlayEnabledOn(col, row, Hex.DOT);
- enableOverlayOn(col, row, Hex.DOT, enable);
+ return possiblePaths(pawn, from, to, possiblePaths);
}
- private void enableFinalPath(boolean enable)
+ public int possiblePathsPointToggle(GridPoint2 point)
{
- for(GridPoint2 hex : possiblePaths) {
- enableOverlayOn(hex.x, hex.y, Hex.GREEN, false);
- enableOverlayOn(hex.x, hex.y, Hex.DOT, false);
- enableOverlayOn(hex.x, hex.y, Hex.MOVE, enable);
- }
- enableOverlayOn(to.x, to.y, Hex.ROSE, enable);
+ return possiblePathsFilterToggle(point.x, point.y, possiblePaths);
}
- private void enablePossiblePaths(boolean enable, boolean keepDots)
+ public void clearPossibles()
{
- for(GridPoint2 hex : possiblePaths) {
- enableOverlayOn(hex.x, hex.y, Hex.GREEN, enable);
- if (!keepDots)
- enableOverlayOn(hex.x, hex.y, Hex.DOT, false);
- }
+ enablePossibleMoves(false);
+ enablePossiblePaths(false, false);
+ enablePossibleTargets(false);
+ clearNodesSet(possiblePaths);
+ // clearNodesVector(possibleMoves);
+ // clearNodesVector(possibleTargets);
}
- private void enablePossibleTargets(boolean enable)
+ public void toggleDotOverlay(GridPoint2 hex)
{
- for(GridPoint2 hex : possibleTargets)
- enableOverlayOn(hex.x, hex.y, Hex.RED, enable);
+ boolean enable= !isOverlayEnabledOn(hex.x, hex.y, Hex.DOT);
+ enableOverlayOn(hex, Hex.DOT, enable);
+ }
+
+ public void enableFinalPath(boolean enable)
+ {
+ for(GridPoint2 hex : possiblePaths) {
+ enableOverlayOn(hex, Hex.GREEN, false);
+ enableOverlayOn(hex, Hex.DOT, false);
+ enableOverlayOn(hex, Hex.MOVE, enable);
+ }
}
}