From 0eb2eae843b58fe45883b96874dc876a074df250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 18 Jan 2015 23:22:01 +0100 Subject: Move: add static getEnter() and getSet() --- core/src/ch/asynk/tankontank/engine/Move.java | 28 +++++++++++++++------------ core/src/ch/asynk/tankontank/game/Map.java | 9 ++------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/core/src/ch/asynk/tankontank/engine/Move.java b/core/src/ch/asynk/tankontank/engine/Move.java index b12b8da..0eb3c86 100644 --- a/core/src/ch/asynk/tankontank/engine/Move.java +++ b/core/src/ch/asynk/tankontank/engine/Move.java @@ -42,6 +42,22 @@ public class Move extends Path implements Iterable return m; } + public static Move getEnter(Pawn pawn, Tile to, Orientation orientation) + { + Move m = get(pawn, null, to, orientation, null); + m.type = MoveType.ENTER; + m.cost = to.costFrom(pawn, orientation); + return m; + } + + public static Move getSet(Pawn pawn, Tile to, Orientation orientation) + { + Move m = get(pawn, null, to, orientation, null); + m.type = MoveType.SET; + m.cost = 0; + return m; + } + public Pawn pawn; public Tile from; public Tile to; @@ -86,18 +102,6 @@ public class Move extends Path implements Iterable return (type != MoveType.ENTER); } - public void setSet() - { - type = MoveType.SET; - cost = 0; - } - - public void setEnter() - { - type = MoveType.ENTER; - cost = to.costFrom(pawn, orientation); - } - public void setExit() { type = MoveType.EXIT; diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index eca6e64..7a28a70 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -273,10 +273,8 @@ public abstract class Map extends Board if (entry == Orientation.KEEP) return false; - Move move = Move.get(unit, null, to, entry, null); - move.setEnter(); - enterPawn(unit, move); + enterPawn(unit, Move.getEnter(unit, to, entry)); objectives.claim(to, unit.getArmy()); return true; } @@ -285,10 +283,7 @@ public abstract class Map extends Board { TankOnTank.debug("Map", String.format("set %s %s %s", to.toShort(), unit, entry)); - Move move = Move.get(unit, null, to, entry, null); - move.setSet(); - - setPawnOnto(unit, move); + setPawnOnto(unit, Move.getSet(unit, to, entry)); objectives.claim(to, unit.getArmy()); return true; } -- cgit v1.1-2-g2b99