diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-05 12:13:57 +0100 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-05 12:13:57 +0100 | 
| commit | 3fdaaa05538525e828067e0eb4b91e7758ba023c (patch) | |
| tree | fd99a160502a3f981a14de6db4cb050efd095731 /core/src/ch | |
| parent | fbed4659a16b7e28ab960e28f11d11b841ed1d86 (diff) | |
| download | RustAndDust-3fdaaa05538525e828067e0eb4b91e7758ba023c.zip RustAndDust-3fdaaa05538525e828067e0eb4b91e7758ba023c.tar.gz | |
PossiblePaths: first call init(Pawn, Tile from) then build(Tile to)
Diffstat (limited to 'core/src/ch')
4 files changed, 15 insertions, 20 deletions
| diff --git a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java index bcda72b..7654e90 100644 --- a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java +++ b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java @@ -35,19 +35,15 @@ public class PossiblePaths implements Iterable<Vector3>          this.orientation = Orientation.KEEP;      } -    public int init(Pawn pawn, Tile from, Tile to) +    public void init(Pawn pawn, Tile from)      { -        clear();          this.pawn = pawn;          this.from = from; -        this.to = to; - -        return build();      } -    public int init(Pawn pawn, Tile to) +    public void init(Pawn pawn)      { -        return init(pawn, pawn.getTile(), to); +        init(pawn, pawn.getTile());      }      public void clear() @@ -60,7 +56,6 @@ public class PossiblePaths implements Iterable<Vector3>          this.filteredPaths.clear();          this.tiles.clear();          this.to = null; -        this.pawn = null;          this.orientation = Orientation.KEEP;      } @@ -82,8 +77,10 @@ public class PossiblePaths implements Iterable<Vector3>              board.enableOverlayOn(tile, i, enable);      } -    private int build() +    public int build(Tile to)      { +        clear(); +        this.to = to;          // from and to are not part of the path          if (board.distance(from, to) == 1) {              ArrayList<Tile> temp = new ArrayList<Tile>(0); diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 64d3329..6e6d959 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -105,11 +105,6 @@ public abstract class Map extends Board          return collectPossibleMoves(pawn, possibleMoves);      } -    public int collectPossiblePaths(Pawn pawn, Hex to) -    { -        return possiblePaths.init(pawn, to); -    } -      public int togglePossiblePathHex(Hex hex)      {          return possiblePaths.toggleCtrlTile(hex); diff --git a/core/src/ch/asynk/tankontank/game/states/StateBreak.java b/core/src/ch/asynk/tankontank/game/states/StateBreak.java index 820ad97..1a40f08 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateBreak.java +++ b/core/src/ch/asynk/tankontank/game/states/StateBreak.java @@ -76,7 +76,8 @@ public class StateBreak extends StateCommon          if (done || (activeUnit == null)) return;          done = true; -        if (map.collectPossiblePaths(activeUnit, to) == 1) { +        map.possiblePaths.init(activeUnit); +        if (map.possiblePaths.build(to) == 1) {              map.possiblePaths.orientation = o;              map.movePawn(activeUnit, o);              ctrl.setAnimationCount(1); diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java index e279564..cbacef5 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateMove.java +++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java @@ -11,12 +11,12 @@ public class StateMove extends StateCommon          boolean moreThanOne = ((map.moveablePawns.size() + map.activatedPawns.size()) > 1);          ctrl.hud.show(false, true, true, false, moreThanOne, ctrl.cfg.canCancel);          ctrl.hud.moveBtn.setOn(); -        map.possiblePaths.clear();          if (fromSelect) {              // use selectedHex and selectedUnit              activeUnit = selectedUnit;              activeUnit.showMoveable(); +            map.possiblePaths.init(activeUnit);              map.collectAndShowMovesAndAssits(activeUnit);              if (to != null) {                  // quick move -> replay touchUp @@ -40,6 +40,7 @@ public class StateMove extends StateCommon          activeUnit.hideMoveable();          map.hidePossibleMoves();          map.unselectHex(activeUnit.getHex()); +        map.possiblePaths.clear();          if (to != null) {              map.hideFinalPath(to);          } @@ -66,7 +67,7 @@ public class StateMove extends StateCommon              if(unit != activeUnit)                  changeUnit(unit);          } else if ((s == 0) && map.possibleMoves.contains(upHex)) { -            s = collectPaths(); +            s = collectPaths(upHex);          } else if (map.possiblePaths.contains(upHex)) {              s = togglePoint(downHex, s);          } @@ -106,6 +107,7 @@ public class StateMove extends StateCommon              map.unselectHex(activeUnit.getHex());          activeUnit = unit;          Hex hex = activeUnit.getHex(); +        map.possiblePaths.init(activeUnit, hex);          map.selectHex(hex);          activeUnit.showMoveable();          map.hidePossibleMoves(); @@ -113,10 +115,10 @@ public class StateMove extends StateCommon          map.showPossibleMoves();      } -    private int collectPaths() +    private int collectPaths(Hex hex)      { -        to = upHex; -        int s = map.collectPossiblePaths(activeUnit, to); +        to = hex; +        int s = map.possiblePaths.build(to);          map.showMove(to);          map.hidePossibleMoves();          map.showPossiblePaths(); | 
