diff options
Diffstat (limited to 'core/src/ch')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 6 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/PawnSet.java | 14 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/TileSet.java | 14 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Map.java | 114 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Unit.java | 27 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateAttack.java | 35 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateCommon.java | 14 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateMove.java | 38 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateRotate.java | 26 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateSelect.java | 6 |
10 files changed, 121 insertions, 173 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 8fbc548..2801d18 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -40,8 +40,6 @@ public abstract class Board implements Disposable public interface TileCollection extends Collection<Tile> { public Tile first(); - public void show(); - public void hide(); public void enable(int i, boolean enable); public void collectPawns(PawnCollection pawns); public int fromNodes(Collection<SearchBoard.Node> nodes); @@ -50,8 +48,6 @@ public abstract class Board implements Disposable public interface PawnCollection extends Collection<Pawn> { public Pawn first(); - public void show(); - public void hide(); public void enable(int i, boolean enable); public void collectTiles(TileCollection tiles); public int fromNodes(Collection<SearchBoard.Node> nodes); @@ -417,7 +413,7 @@ public abstract class Board implements Disposable tilesToDraw.remove(tile); } - public void enableOverlayOn(Tile tile, int i, boolean enable, Orientation o) + public void enableOverlayOn(Tile tile, int i, Orientation o, boolean enable) { if(tile.enableOverlay(i, enable, o.r())) tilesToDraw.add(tile); diff --git a/core/src/ch/asynk/tankontank/engine/PawnSet.java b/core/src/ch/asynk/tankontank/engine/PawnSet.java index f4e1c27..d06fdd2 100644 --- a/core/src/ch/asynk/tankontank/engine/PawnSet.java +++ b/core/src/ch/asynk/tankontank/engine/PawnSet.java @@ -7,13 +7,11 @@ import java.util.LinkedHashSet; public class PawnSet extends LinkedHashSet<Pawn> implements Board.PawnCollection { private final Board board; - private int overlay; - public PawnSet(Board board, int overlay, int n) + public PawnSet(Board board, int n) { super(n); this.board = board; - this.overlay = overlay; } public Pawn first() @@ -22,16 +20,6 @@ public class PawnSet extends LinkedHashSet<Pawn> implements Board.PawnCollection return iterator().next(); } - public void show() - { - enable(overlay, true); - } - - public void hide() - { - enable(overlay, false); - } - public void enable(int i, boolean enable) { for (Pawn pawn : this) diff --git a/core/src/ch/asynk/tankontank/engine/TileSet.java b/core/src/ch/asynk/tankontank/engine/TileSet.java index 04f726b..6f71b42 100644 --- a/core/src/ch/asynk/tankontank/engine/TileSet.java +++ b/core/src/ch/asynk/tankontank/engine/TileSet.java @@ -7,13 +7,11 @@ import java.util.LinkedHashSet; public class TileSet extends LinkedHashSet<Tile> implements Board.TileCollection { private final Board board; - private int overlay; - public TileSet(Board board, int overlay, int n) + public TileSet(Board board, int n) { super(n); this.board = board; - this.overlay = overlay; } public Tile first() @@ -22,16 +20,6 @@ public class TileSet extends LinkedHashSet<Tile> implements Board.TileCollection return iterator().next(); } - public void show() - { - enable(overlay, true); - } - - public void hide() - { - enable(overlay, false); - } - public void enable(int i, boolean enable) { for (Tile tile : this) diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index c7e1390..2d1c677 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -43,12 +43,12 @@ public abstract class Map extends Board this.explosions = new SpriteAnimation(game.manager.get("data/explosions.png", Texture.class), 16, 8, 15); setup(); - possibleMoves = new TileSet(this, Hex.MOVE1, 40); - possiblePaths = new TileSet(this, Hex.MOVE1, 10); // Hex.MOVE2 - moveablePawns = new PawnSet(this, Unit.MOVE, 6); + possibleMoves = new TileSet(this, 40); + possiblePaths = new TileSet(this, 10); + moveablePawns = new PawnSet(this, 6); - possibleTargets = new PawnSet(this, Unit.TARGET, 10); - attackAssists = new PawnSet(this, Unit.ATTACK_ASSIST, 6); + possibleTargets = new PawnSet(this, 10); + attackAssists = new PawnSet(this, 6); } @Override @@ -78,53 +78,6 @@ public abstract class Map extends Board return (Hex) getTile(col, row); } - public void selectHex(Hex hex, boolean enable) - { - enableOverlayOn(hex, Hex.SELECT, enable); - } - - public void showAssist(Hex hex, boolean enable) - { - enableOverlayOn(hex, Hex.ASSIST, enable); - } - - public void showTarget(Hex hex, boolean enable) - { - enableOverlayOn(hex, Hex.TARGET, enable); - } - - public void showPossiblePaths(boolean enable, boolean keepFinal) - { - if (keepFinal) { - possiblePaths.enable(Hex.MOVE1, enable); - } else { - possiblePaths.enable(Hex.MOVE1, enable); - possiblePaths.enable(Hex.MOVE2, false); - } - } - - public void showFinalPath(Hex dst, boolean enable) - { - possiblePaths.enable(Hex.MOVE1, false); - possiblePaths.enable(Hex.MOVE2, enable); - } - - public void showDirections(Hex hex, boolean enable) - { - enableOverlayOn(hex, Hex.DIRECTIONS, enable); - } - - public void showOrientation(Hex hex, boolean enable, Orientation o) - { - enableOverlayOn(hex, Hex.ORIENTATION, enable, o); - } - - public void togglePathOverlay(Hex hex) - { - boolean enable= !hex.isOverlayEnabled(Hex.MOVE2); - enableOverlayOn(hex, Hex.MOVE2, enable); - } - public int buildPossibleMoves(Pawn pawn) { if (!pawn.canMove()) { @@ -163,25 +116,27 @@ public abstract class Map extends Board return s; } - public boolean toggleAttackAssist(Pawn pawn) + public void toggleAttackAssist(Unit unit) { - if (activatedPawns.contains(pawn)) { - activatedPawns.remove(pawn); - return false; + if (activatedPawns.contains(unit)) { + activatedPawns.remove(unit); + unit.hideAttack(); + unit.showAttackAssist(); } else { - activatedPawns.add(pawn); - return true; + activatedPawns.add(unit); + unit.showAttack(); + unit.hideAttackAssist(); } } public void buildAndShowMovesAndAssits(Pawn pawn) { - possibleMoves.hide(); - moveablePawns.hide(); + hidePossibleMoves(); + hideMoveablePawns(); buildPossibleMoves(pawn); collectMoveablePawns(pawn); - possibleMoves.show(); - moveablePawns.show(); + showPossibleMoves(); + showMoveablePawns(); activatedPawns.clear(); } @@ -298,4 +253,39 @@ public abstract class Map extends Board setPawnOnto(with, pawn.getTile(), pawn.getOrientation()); activatedPawns.add(with); } + + // SHOW / HIDE + + public void togglePathOverlay(Hex hex) + { + boolean enable= !hex.isOverlayEnabled(Hex.MOVE2); + enableOverlayOn(hex, Hex.MOVE2, enable); + } + + public void showPossibleMoves() { possibleMoves.enable(Hex.MOVE1, true); } + public void hidePossibleMoves() { possibleMoves.enable(Hex.MOVE1, false); } + public void showPossiblePaths() { possiblePaths.enable(Hex.MOVE1, true); } + public void hidePossiblePaths() { possiblePaths.enable(Hex.MOVE1, false); } + public void showFinalPath(Hex dst) { possiblePaths.enable(Hex.MOVE2, true); } + public void hideFinalPath(Hex dst) { possiblePaths.enable(Hex.MOVE2, false); } + + public void showMoveablePawns() { moveablePawns.enable(Unit.MOVE, true); } + public void hideMoveablePawns() { moveablePawns.enable(Unit.MOVE, false); } + public void showPossibleTargets() { possibleTargets.enable(Unit.TARGET, true); } + public void hidePossibleTargets() { possibleTargets.enable(Unit.TARGET, false); } + public void showAttackAssists() { attackAssists.enable(Unit.ATTACK_ASSIST, true); } + public void hideAttackAssists() { attackAssists.enable(Unit.ATTACK, false); + attackAssists.enable(Unit.ATTACK_ASSIST, false); } + + + public void selectHex(Hex hex) { enableOverlayOn(hex, Hex.SELECT, true); } + public void unselectHex(Hex hex) { enableOverlayOn(hex, Hex.SELECT, false); } + public void showDirections(Hex hex) { enableOverlayOn(hex, Hex.DIRECTIONS, true); } + public void hideDirections(Hex hex) { enableOverlayOn(hex, Hex.DIRECTIONS, false); } + public void showTarget(Hex hex) { enableOverlayOn(hex, Hex.TARGET, true); } + public void hideTarget(Hex hex) { enableOverlayOn(hex, Hex.TARGET, false); } + public void showAssist(Hex hex) { enableOverlayOn(hex, Hex.ASSIST, true); } + public void hideAssist(Hex hex) { enableOverlayOn(hex, Hex.ASSIST, false); } + public void showOrientation(Hex hex, Orientation o) { enableOverlayOn(hex, Hex.ORIENTATION, o, true); } + public void hideOrientation(Hex hex) { enableOverlayOn(hex, Hex.ORIENTATION, false); } } diff --git a/core/src/ch/asynk/tankontank/game/Unit.java b/core/src/ch/asynk/tankontank/game/Unit.java index f950a1a..9f8c03b 100644 --- a/core/src/ch/asynk/tankontank/game/Unit.java +++ b/core/src/ch/asynk/tankontank/game/Unit.java @@ -232,23 +232,14 @@ public class Unit extends HeadedPawn hasMoved = false; } - public void showMoveable(boolean enable) - { - enableOverlay(MOVE, enable); - } - - public void showAttack(boolean enable) - { - enableOverlay(ATTACK, enable); - } - public void showAttackAssist(boolean enable) - { - enableOverlay(ATTACK_ASSIST, enable); - } - - public void showTarget(boolean enable) - { - enableOverlay(TARGET, enable); - } + // SHOW / HIDE + public void showMoveable() { enableOverlay(MOVE, true); } + public void hideMoveable() { enableOverlay(MOVE, false); } + public void showTarget() { enableOverlay(TARGET, true); } + public void hideTarget() { enableOverlay(TARGET, false); } + public void showAttack() { enableOverlay(ATTACK, true); } + public void hideAttack() { enableOverlay(ATTACK, false); } + public void showAttackAssist() { enableOverlay(ATTACK_ASSIST, true); } + public void hideAttackAssist() { enableOverlay(ATTACK_ASSIST, false); } } diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java index 0e637fd..1e46c9c 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateAttack.java +++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java @@ -17,16 +17,16 @@ public class StateAttack extends StateCommon if (fromSelect) { activeUnit = null; // use selectedHex and selectedUnit - map.possibleTargets.hide(); + map.hidePossibleTargets(); map.buildPossibleTargets(selectedUnit, ctrl.opponent.unitIterator()); - map.possibleTargets.show(); + map.showPossibleTargets(); if (to != null) { // quick fire -> replay touchUp upHex = to; touchUp(); } - selectedUnit.showAttack(true); - map.selectHex(selectedHex, true); + selectedUnit.showAttack(); + map.selectHex(selectedHex); } else System.err.println("should not happen"); } @@ -34,13 +34,12 @@ public class StateAttack extends StateCommon @Override public void leave(StateType nextState) { - selectedUnit.showAttack(false); - map.attackAssists.enable(Unit.ATTACK, false); - map.attackAssists.enable(Unit.ATTACK_ASSIST, false); - map.possibleTargets.hide(); - map.selectHex(selectedHex, false); + selectedUnit.hideAttack(); + map.hideAttackAssists(); + map.hidePossibleTargets(); + map.unselectHex(selectedHex); if (to != null) - map.selectHex(to, false); + map.unselectHex(to); } @Override @@ -55,23 +54,17 @@ public class StateAttack extends StateCommon // activeUnit is the target if ((activeUnit == null) && map.possibleTargets.contains(unit)) { - map.possibleTargets.hide(); + map.hidePossibleTargets(); to = upHex; activeUnit = unit; - activeUnit.showTarget(true); + activeUnit.showTarget(); map.buildAttackAssists(selectedUnit, activeUnit, ctrl.player.unitIterator()); - map.attackAssists.show(); + map.showAttackAssists(); ctrl.hud.show(false, false, false, true, true, ctrl.cfg.canCancel); } if ((activeUnit != null) && map.attackAssists.contains(unit)) { - if (map.toggleAttackAssist(unit)) { - unit.showAttack(true); - unit.showAttackAssist(false); - } else { - unit.showAttack(false); - unit.showAttackAssist(true); - } + map.toggleAttackAssist(unit); } } @@ -90,7 +83,7 @@ public class StateAttack extends StateCommon System.err.print(" attack (" + selectedHex.getCol() + ";" + selectedHex.getRow() + ") -> (" + to.getCol() + ";" + to.getRow() + ") : 2D6 -> (" + d1 + " + " + d2 + ")"); if (map.attackPawn(selectedUnit, activeUnit, d1 + d2)) ctrl.player.casualty(activeUnit); - activeUnit.showTarget(true); + activeUnit.showTarget(); ctrl.setState(StateType.ANIMATION); super.done(); diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java index 4ab9ec6..9c229b2 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateCommon.java +++ b/core/src/ch/asynk/tankontank/game/states/StateCommon.java @@ -96,7 +96,7 @@ public abstract class StateCommon implements State { selectedHex = hex; selectedUnit = selectedHex.getUnit(); - map.selectHex(selectedHex, true); + map.selectHex(selectedHex); if (selectedUnit != null) isEnemy = ctrl.player.isEnemy(selectedUnit); else @@ -106,15 +106,15 @@ public abstract class StateCommon implements State protected void showPossibleTargetsMovesAssists(Unit pawn) { - if (ctrl.cfg.showMoves && pawn.canMove()) map.possibleMoves.show(); - if (ctrl.cfg.showTargets && pawn.canAttack()) map.possibleTargets.show(); - if (ctrl.cfg.showMoveAssists && pawn.canMove()) map.moveablePawns.show(); + if (ctrl.cfg.showMoves && pawn.canMove()) map.showPossibleMoves(); + if (ctrl.cfg.showTargets && pawn.canAttack()) map.showPossibleTargets(); + if (ctrl.cfg.showMoveAssists && pawn.canMove()) map.showMoveablePawns(); } protected void hidePossibleTargetsMovesAssists() { - map.possibleMoves.hide(); - map.possibleTargets.hide(); - map.moveablePawns.hide(); + map.hidePossibleMoves(); + map.hidePossibleTargets(); + map.hideMoveablePawns(); } } diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java index f976b31..6caf096 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateMove.java +++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java @@ -17,7 +17,7 @@ public class StateMove extends StateCommon if (fromSelect) { // use selectedHex and selectedUnit activeUnit = selectedUnit; - activeUnit.showMoveable(true); + activeUnit.showMoveable(); map.buildAndShowMovesAndAssits(activeUnit); if (to != null) { // quick move -> replay touchUp @@ -38,12 +38,12 @@ public class StateMove extends StateCommon public void leave(StateType nextState) { // hide all but assists : want them when in rotation - activeUnit.showMoveable(false); - map.possibleMoves.hide(); - map.selectHex(activeUnit.getHex(), false); + activeUnit.hideMoveable(); + map.hidePossibleMoves(); + map.unselectHex(activeUnit.getHex()); if (to != null) { - map.selectHex(to, false); - map.showFinalPath(to, false); + map.unselectHex(to); + map.hideFinalPath(to); } if (nextState != StateType.SELECT) { @@ -99,31 +99,31 @@ public class StateMove extends StateCommon private void hideAssists() { - map.showAssist(selectedHex, false); - map.moveablePawns.hide(); + map.hideAssist(selectedHex); + map.hideMoveablePawns(); } private void changeUnit(Unit unit) { if (activeUnit != null ) - map.selectHex(activeUnit.getHex(), false); + map.unselectHex(activeUnit.getHex()); activeUnit = unit; Hex hex = activeUnit.getHex(); - map.selectHex(hex, true); - map.showAssist(hex, false); - activeUnit.showMoveable(true); - map.possibleMoves.hide(); + map.selectHex(hex); + map.hideAssist(hex); + activeUnit.showMoveable(); + map.hidePossibleMoves(); map.buildPossibleMoves(activeUnit); - map.possibleMoves.show(); + map.showPossibleMoves(); } private int buildPaths() { to = upHex; int s = map.buildPossiblePaths(activeUnit, to); - map.selectHex(to, true); - map.possibleMoves.hide(); - map.showPossiblePaths(true, true); + map.selectHex(to); + map.hidePossibleMoves(); + map.showPossiblePaths(); return s; } @@ -134,10 +134,10 @@ public class StateMove extends StateCommon } else if (downHex == to) { // } else { - map.showPossiblePaths(false, true); + map.hidePossiblePaths(); map.togglePathOverlay(downHex); s = map.possiblePathsPointToggle(downHex); - map.showPossiblePaths(true, true); + map.showPossiblePaths(); } return s; diff --git a/core/src/ch/asynk/tankontank/game/states/StateRotate.java b/core/src/ch/asynk/tankontank/game/states/StateRotate.java index e13923e..e9d6b65 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateRotate.java +++ b/core/src/ch/asynk/tankontank/game/states/StateRotate.java @@ -26,12 +26,12 @@ public class StateRotate extends StateCommon if (to == null) System.err.println("to is null but should not be"); // show final path - map.selectHex(to, true); - map.showFinalPath(to, true); + map.selectHex(to); + map.showFinalPath(to); } - map.selectHex(activeUnit.getHex(), true); - map.showDirections(to, true); + map.selectHex(activeUnit.getHex()); + map.showDirections(to); rotationSet = false; } @@ -39,11 +39,11 @@ public class StateRotate extends StateCommon @Override public void leave(StateType nextState) { - map.selectHex(to, false); - map.selectHex(activeUnit.getHex(), false); - map.showFinalPath(to, false); - map.showDirections(to, false); - map.showOrientation(to, false, o); + map.unselectHex(to); + map.unselectHex(activeUnit.getHex()); + map.hideFinalPath(to); + map.hideDirections(to); + map.hideOrientation(to); } @Override @@ -65,8 +65,8 @@ public class StateRotate extends StateCommon if (ctrl.cfg.mustValidate) { - map.showDirections(to, false); - map.showOrientation(to, true, o); + map.hideDirections(to); + map.showOrientation(to, o); ctrl.hud.show(false, true, false, false, true, ctrl.cfg.canCancel); } else doRotation(o); @@ -95,8 +95,8 @@ public class StateRotate extends StateCommon private void hideAssists() { - map.showAssist(selectedHex, false); - map.moveablePawns.hide(); + map.hideMoveablePawns(); + map.hideAssist(selectedHex); } private void doRotation(Orientation o) diff --git a/core/src/ch/asynk/tankontank/game/states/StateSelect.java b/core/src/ch/asynk/tankontank/game/states/StateSelect.java index d4d010c..0fa45de 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateSelect.java +++ b/core/src/ch/asynk/tankontank/game/states/StateSelect.java @@ -27,7 +27,8 @@ public class StateSelect extends StateCommon @Override public void touchDown() { - if (selectedHex != null) map.selectHex(selectedHex, false); + if (selectedHex != null) + map.unselectHex(selectedHex); } @Override @@ -80,7 +81,8 @@ public class StateSelect extends StateCommon @Override public void abort() { - if (selectedHex != null) map.selectHex(selectedHex, false); + if (selectedHex != null) + map.unselectHex(selectedHex); hidePossibleTargetsMovesAssists(); clearAll(); map.clearAll(); |