diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-01-18 22:06:22 +0100 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-01-18 22:06:22 +0100 | 
| commit | e60b3d647b9eff905977fd9f5a7760ce0b0113ea (patch) | |
| tree | 2a2be7fd724f3534cfeb818ebffa275f7e90c55f /core/src/ch/asynk/tankontank/engine | |
| parent | 28ebacf54e013690337a754522616ca909a440f5 (diff) | |
| download | RustAndDust-e60b3d647b9eff905977fd9f5a7760ce0b0113ea.zip RustAndDust-e60b3d647b9eff905977fd9f5a7760ce0b0113ea.tar.gz  | |
remove Pawn.Movement class, use Move instead
Diffstat (limited to 'core/src/ch/asynk/tankontank/engine')
| -rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 19 | ||||
| -rw-r--r-- | core/src/ch/asynk/tankontank/engine/Pawn.java | 87 | ||||
| -rw-r--r-- | core/src/ch/asynk/tankontank/engine/PossiblePaths.java | 51 | 
3 files changed, 62 insertions, 95 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 28164ce..5ec1210 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -405,6 +405,12 @@ public abstract class Board implements Disposable, Animation          return n;      } +    public Pawn setPawnOnto(Pawn pawn, Move move) +    { +        pawn.move(move); +        return setPawnOnto(pawn, move.to, move.orientation.r()); +    } +      public Pawn setPawnOnto(Pawn pawn, Tile tile, Orientation o)      {          return setPawnOnto(pawn, tile, o.r()); @@ -422,21 +428,26 @@ public abstract class Board implements Disposable, Animation          return RunnableAnimation.get(pawn, new Runnable() {              @Override              public void run() { -                setPawnOnto(pawn, pawn.movement.to, pawn.movement.orientation); +                setPawnOnto(pawn, pawn.move.to, pawn.move.orientation);              }          });      } -    protected void movePawn(final Pawn pawn, PossiblePaths possiblePaths, RunnableAnimation whenDone, MoveToAnimationCb cb) +    protected void movePawn(final Pawn pawn, Move move, RunnableAnimation whenDone, MoveToAnimationCb cb)      { +        pawn.move(move);          removePawn(pawn); -        AnimationSequence seq = pawn.getMoveAnimation(possiblePaths.iterator(), (possiblePaths.pathSteps(0) + 2), cb); +        AnimationSequence seq = pawn.getMoveAnimation(move.iterator(), (move.steps() + 2), cb);          seq.addAnimation(getSetPawnOntoAnimation(pawn));          seq.addAnimation(whenDone);          addAnimation(seq); +    } -        pawn.move(); +    protected void enterPawn(final Pawn pawn, Move move) +    { +        pawn.enter(move); +        setPawnOnto(pawn, move.to, move.orientation);      }      protected void revertLastPawnMove(final Pawn pawn, RunnableAnimation whenDone) diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index d3359ef..a2e6951 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -50,47 +50,6 @@ public abstract class Pawn implements Moveable, Disposable          }      } -    public class Movement -    { -        Tile from; -        Tile to; -        int distance; -        public int cost; -        boolean roadMarch; -        public boolean entryMove; -        Orientation orientation; - -        public String toString() -        { -            if (to == null) -                return "move : HQ activation"; -            else if (from == null) -                return "move : reinforcement -> [" + to.col + ";" + to.row + ";" + orientation + "] dist:" + distance + " cost:" + cost + " road:" + roadMarch + " entry:" + entryMove; -            else -                return "move : [" + from.col + ";" + from.row + "] -> [" + to.col + ";" + to.row + ";" + orientation + "] dist:" + distance + " cost:" + cost + " road:" + roadMarch + " entry:" + entryMove; -        } - -        public void reset() -        { -            from = null; -            to = null; -            cost = 0; -            roadMarch = false; -            entryMove = false; -            orientation = Orientation.KEEP; -        } - -        public boolean isRotation() -        { -            return (distance == 0); -        } - -        public boolean isComplete() -        { -            return ((from != null) && (to != null)); -        } -    } -      private static final float MOVE_TIME = 0.4f;      private Vector3 position; @@ -102,7 +61,7 @@ public abstract class Pawn implements Moveable, Disposable      private Sprite sprite;      private StackedImages overlays;      public Engagement engagement = new Engagement(); -    public Movement movement= new Movement(); +    protected Move move;      public abstract int getMovementPoints();      public abstract int getRoadMarchBonus(); @@ -166,19 +125,49 @@ public abstract class Pawn implements Moveable, Disposable      public void reset()      {          engagement.reset(); -        movement.reset(); +        if (move != null) { +            move.dispose(); +            move  = null; +        } +    } + +    public void move(Move move) +    { +        if (move.isEntry()) +            throw new RuntimeException("wrong MoveType"); + +        if (this.move != null) { +            if (this.move.isEntry()) +                this.move.dispose(); +            else +                throw new RuntimeException("try to override an existing move instance"); +        } + +        setMove(move);      } -    public void enterBoard(Tile to, Orientation o) +    public void enter(Move move)      { -        movement.to = to; -        movement.from = null; -        movement.entryMove = true; -        movement.orientation = o; -        movement.cost = to.costFrom(this, o); +        if (!move.isEntry()) +            throw new RuntimeException("wrong MoveType"); + +        if (this.move != null) +            throw new RuntimeException("try to override an existing move instance"); + +        setMove(move); +    } + +    private void setMove(Move move) +    { +        this.move = move;          move();      } +    public boolean justEntered() +    { +        return ((move != null) && move.isEntry()); +    } +      public boolean is(Faction faction)      {          return (this.faction == faction); diff --git a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java index 163df7c..847b88e 100644 --- a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java +++ b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java @@ -1,6 +1,5 @@  package ch.asynk.tankontank.engine; -import java.util.Iterator;  import java.util.ArrayList;  import java.util.List;  import java.util.LinkedList; @@ -11,7 +10,7 @@ import com.badlogic.gdx.utils.Disposable;  import com.badlogic.gdx.math.Vector2;  import com.badlogic.gdx.math.Vector3; -public class PossiblePaths implements Disposable, Iterable<Vector3> +public class PossiblePaths implements Disposable  {      private final Board board; @@ -186,20 +185,17 @@ public class PossiblePaths implements Disposable, Iterable<Vector3>          return filteredPaths.size();      } -    public void applyToPawn(int i) +    public int pathCost(int i)      { -        pawn.movement.from = from; -        pawn.movement.to = to; -        pawn.movement.orientation = orientation; -        Path path = paths.get(i); -        pawn.movement.cost = path.cost; -        pawn.movement.distance = this.distance; -        pawn.movement.roadMarch = path.roadMarch; +        return paths.get(i).cost;      } -    public int pathCost(int i) +    public Move getMove()      { -        return paths.get(i).cost; +        if (size() != 1) +            return null; + +        return Move.get(pawn, from, to, orientation, getPath(0));      }      public Path getPath(int i) @@ -217,38 +213,9 @@ public class PossiblePaths implements Disposable, Iterable<Vector3>          to = board.getAdjTileAt(to, exit);      } -    public int pathSteps(int idx) -    { -        int steps = 0; - -        Tile tile = from; -        Orientation o = pawn.getOrientation(); -        for (Tile next : getPath(idx).tiles) { -            Orientation nextO = Orientation.fromMove(tile.col, tile.row, next.col, next.row); -            if (nextO != o) { -                steps += 2; -                o = nextO; -            } else -                steps += 1; -            tile = next; -        } -        if (orientation != Orientation.fromMove(tile.col, tile.row, to.col, to.row)) -            steps += 2; -        else -            steps +=1; - -        return steps; -    } - -    @Override -    public Iterator<Vector3> iterator() -    { -        return new PathIterator(pawn, from, to, orientation, getPath(0).tiles); -    } -      private void printToErr(String what, List<Path> paths)      { -        System.err.println(what + " ("+paths.size()+") " + from + " -> " + to); +        System.err.println(what + pawn + " ("+paths.size()+") " + from + " -> " + to);          for (Path path : paths) {              System.err.println(String.format(" - path (l:%d c:%d r:%b)", path.tiles.size(), path.cost, path.roadMarch));              for(Tile tile : path.tiles)  | 
