From 1985315e60a7c9d83541daa47e602057d10d41e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 21 Nov 2014 17:08:10 +0100 Subject: Map,Board,Pawn: plug in objectives management --- core/src/ch/asynk/tankontank/engine/Board.java | 5 +++-- core/src/ch/asynk/tankontank/engine/Pawn.java | 4 ++-- core/src/ch/asynk/tankontank/game/Map.java | 9 +++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 080eb33..d6426bb 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -19,6 +19,7 @@ import ch.asynk.tankontank.engine.gfx.Image; import ch.asynk.tankontank.engine.gfx.Animation; import ch.asynk.tankontank.engine.gfx.animations.AnimationSequence; import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation; +import ch.asynk.tankontank.engine.gfx.animations.MoveToAnimation.MoveToAnimationCb; public abstract class Board implements Disposable { @@ -410,12 +411,12 @@ public abstract class Board implements Disposable }); } - protected void movePawn(final Pawn pawn, PossiblePaths possiblePaths, RunnableAnimation whenDone) + protected void movePawn(final Pawn pawn, PossiblePaths possiblePaths, RunnableAnimation whenDone, MoveToAnimationCb cb) { possiblePaths.applyToPawn(0); removePawn(pawn); - AnimationSequence seq = pawn.getMoveAnimation(possiblePaths.iterator(), possiblePaths.pathSteps(0) + 2); + AnimationSequence seq = pawn.getMoveAnimation(possiblePaths.iterator(), (possiblePaths.pathSteps(0) + 2), cb); seq.addAnimation(getSetPawnOntoAnimation(pawn)); seq.addAnimation(whenDone); addAnimation(seq); diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index 33c5f07..70fc641 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -345,12 +345,12 @@ public abstract class Pawn implements Moveable, Disposable return seq; } - public AnimationSequence getMoveAnimation(Iterator vectors, int size) + public AnimationSequence getMoveAnimation(Iterator vectors, int size, MoveToAnimation.MoveToAnimationCb cb) { prevPosition.set(position); AnimationSequence seq = AnimationSequence.get(size); while (vectors.hasNext()) - seq.addAnimation(MoveToAnimation.get(this, vectors.next(), MOVE_TIME)); + seq.addAnimation(MoveToAnimation.get(this, vectors.next(), MOVE_TIME, cb)); return seq; } diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index bd04a70..dbf029e 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -192,6 +192,7 @@ public abstract class Map extends Board public void actionDone() { + objectives.forget(); } public boolean enterBoard(Unit unit, Hex to, int allowedMoves) @@ -206,19 +207,22 @@ public abstract class Map extends Board { unit.enterBoard(to, entry); setPawnOnto(unit, to, entry); + objectives.claim(to, unit.getArmy()); return true; } public void leaveBoard(Unit unit) { - removePawn(unit); + Hex hex = unit.getHex(); + if (removePawn(unit) == 0) + objectives.unclaim(hex); activatedUnits.add(unit); } public int moveUnit(Unit unit, Orientation o) { possiblePaths.orientation = o; - movePawn(unit, possiblePaths, notifyDoneAnimation(unit)); + movePawn(unit, possiblePaths, notifyDoneAnimation(unit), objectives); return startMove(unit); } @@ -230,6 +234,7 @@ public abstract class Map extends Board revertLastPawnMove(unit, notifyDoneAnimation(unit)); } activatedUnits.clear(); + objectives.revert(); } private int startMove(Unit unit) -- cgit v1.1-2-g2b99