From 35c6e8e8617c261b51462c6d07d1fcad5c1b0504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 16 Nov 2014 12:18:26 +0100 Subject: Battle: code reorder --- core/src/ch/asynk/tankontank/game/Battle.java | 6 +-- .../tankontank/game/battles/BattleCommon.java | 10 ++-- .../game/battles/BattleFrontalAssault.java | 62 +++++++++++----------- .../tankontank/game/battles/BattleHeadToHead.java | 48 ++++++++--------- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/core/src/ch/asynk/tankontank/game/Battle.java b/core/src/ch/asynk/tankontank/game/Battle.java index 4d5178c..8bc1642 100644 --- a/core/src/ch/asynk/tankontank/game/Battle.java +++ b/core/src/ch/asynk/tankontank/game/Battle.java @@ -11,13 +11,11 @@ public interface Battle public String getDescription(); - public Map getMap(); - public Player getFirstPlayer(); public Player getSecondPlayer(); - public void setup(Map map, Player firstPlayer, Player secondPlayer); + public Map getMap(); public Player checkVictory(Ctrl ctrl); @@ -28,4 +26,6 @@ public interface Battle public State.StateType getState(Player player); public boolean deploymentDone(Player player); + + public void setup(Map map, Player firstPlayer, Player secondPlayer); } diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java b/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java index 58abcd9..4893411 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java @@ -66,6 +66,11 @@ public abstract class BattleCommon implements Battle return factory.getPlayer(secondArmy); } + public EntryPoint getEntryPoint(Unit unit) + { + return pawnEntry.get(unit); + } + public void addEntryPoint(EntryPoint entry) { entryPoints.add(entry); @@ -77,9 +82,4 @@ public abstract class BattleCommon implements Battle player.addReinforcement(unit); pawnEntry.put(unit, entryPoint); } - - public EntryPoint getEntryPoint(Unit unit) - { - return pawnEntry.get(unit); - } } diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java index 9fc1d23..4ed9f44 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java @@ -24,25 +24,24 @@ public class BattleFrontalAssault extends BattleCommon name = "Frontal Assault"; } - public Player checkVictory(Ctrl ctrl) + @Override + public Map getMap() { - if (ctrl.opponent.unitsLeft() == 0) - return ctrl.player; - - if ((ctrl.player.getTurn() < 10) || (ctrl.opponent.getTurn() < 10)) - return null; + return factory.getMap(Factory.MapType.MAP_A); + } - int count = 0; - for (Tile tile : objectives) { - Unit unit = ((Hex) tile).getUnit(); - if ((unit != null) && unit.is(Army.US)) - count =+ 1; - } + @Override + public Position getHudPosition(Player player) + { + return (player.is(Army.US) ? Position.TOP_RIGHT: Position.TOP_LEFT); + } - if (count > 1) - return (ctrl.player.is(Army.US) ? ctrl.player : ctrl.opponent); - else - return (ctrl.player.is(Army.GE) ? ctrl.player : ctrl.opponent); + @Override + public StateType getState(Player player) + { + if (player.getTurn() == 0) + return StateType.DEPLOYMENT; + return StateType.SELECT; } @Override @@ -56,24 +55,25 @@ public class BattleFrontalAssault extends BattleCommon return ((player.is(Army.GE) && (n == 4))); } - @Override - public Position getHudPosition(Player player) + public Player checkVictory(Ctrl ctrl) { - return (player.is(Army.US) ? Position.TOP_RIGHT: Position.TOP_LEFT); - } + if (ctrl.opponent.unitsLeft() == 0) + return ctrl.player; - @Override - public Map getMap() - { - return factory.getMap(Factory.MapType.MAP_A); - } + if ((ctrl.player.getTurn() < 10) || (ctrl.opponent.getTurn() < 10)) + return null; - @Override - public StateType getState(Player player) - { - if (player.getTurn() == 0) - return StateType.DEPLOYMENT; - return StateType.SELECT; + int count = 0; + for (Tile tile : objectives) { + Unit unit = ((Hex) tile).getUnit(); + if ((unit != null) && unit.is(Army.US)) + count =+ 1; + } + + if (count > 1) + return (ctrl.player.is(Army.US) ? ctrl.player : ctrl.opponent); + else + return (ctrl.player.is(Army.GE) ? ctrl.player : ctrl.opponent); } @Override diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java index 364c897..0ee2b19 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java @@ -23,6 +23,30 @@ public class BattleHeadToHead extends BattleCommon name = "Head To Head"; } + @Override + public Map getMap() + { + return factory.getMap(Factory.MapType.MAP_A); + } + + @Override + public Position getHudPosition(Player player) + { + return (player.is(Army.US) ? Position.TOP_RIGHT: Position.TOP_LEFT); + } + + @Override + public boolean deploymentDone(Player player) + { + return true; + } + + @Override + public StateType getState(Player player) + { + return StateType.SELECT; + } + public Player checkVictory(Ctrl ctrl) { if (ctrl.opponent.unitsLeft() == 0) @@ -52,30 +76,6 @@ public class BattleHeadToHead extends BattleCommon } @Override - public boolean deploymentDone(Player player) - { - return true; - } - - @Override - public Position getHudPosition(Player player) - { - return (player.is(Army.US) ? Position.TOP_RIGHT: Position.TOP_LEFT); - } - - @Override - public Map getMap() - { - return factory.getMap(Factory.MapType.MAP_A); - } - - @Override - public StateType getState(Player player) - { - return StateType.SELECT; - } - - @Override public void setup(Map map, Player a, Player b) { Player gePlayer; -- cgit v1.1-2-g2b99