diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-21 17:07:02 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-21 17:07:02 +0100 |
commit | e2f5e85b111d36a8b5616cf9d014b95ce31f2166 (patch) | |
tree | f1dfff60b29d7c39056c1b5b452c7dafee04c7c2 | |
parent | 38acb010de83c6c4b3bce7209a2a796f6dda4dff (diff) | |
download | RustAndDust-e2f5e85b111d36a8b5616cf9d014b95ce31f2166.zip RustAndDust-e2f5e85b111d36a8b5616cf9d014b95ce31f2166.tar.gz |
BattleCommon,Map: the former passes the objectives management to the second
6 files changed, 33 insertions, 57 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 15f73c8..bd04a70 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -34,6 +34,7 @@ public abstract class Map extends Board public final UnitList engagementAssists; public final UnitList activatedUnits; public final UnitList breakUnits; + public final ObjectiveSet objectives; public final Meteorology meteorology; @@ -71,6 +72,8 @@ public abstract class Map extends Board activatedUnits = new UnitList(7); breakUnits = new UnitList(4); + objectives = new ObjectiveSet(this, 4); + meteorology = new Meteorology(); } @@ -106,6 +109,16 @@ public abstract class Map extends Board return (Hex) getTile(col, row); } + public void addObjective(int col, int row, Army army) + { + objectives.add(getHex(col, row), army, true); + } + + public void addHoldObjective(int col, int row, Army army) + { + objectives.add(getHex(col, row), army, false); + } + public int collectPossibleMoves(Unit unit) { if (!unit.canMove()) { diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java b/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java index a816799..cf60324 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java @@ -28,7 +28,6 @@ public abstract class BattleCommon implements Battle protected ArrayList<Zone> exitZone = new ArrayList<Zone>(); protected HashMap<Unit, Zone> unitEntry = new HashMap<Unit, Zone>(); protected HashMap<Unit, Zone> unitExit = new HashMap<Unit, Zone>(); - protected HexSet objectives; public BattleCommon(Factory factory) { diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java index 173e719..653052b 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java @@ -68,14 +68,7 @@ public class BattleFrontalAssault extends BattleCommon if ((ctrl.player.getTurnDone() < 10) || (ctrl.opponent.getTurnDone() < 10)) return null; - int count = 0; - for (Hex hex : objectives) { - Unit unit = hex.getUnit(); - if ((unit != null) && unit.is(Army.US)) - count =+ 1; - } - - if (count > 1) + if (ctrl.map.objectives.count(Army.US) >= 2) return usPlayer; else return gePlayer; @@ -85,11 +78,9 @@ public class BattleFrontalAssault extends BattleCommon public void setup(Ctrl ctrl, Map map) { // G9, E6, H4 - objectives = new HexSet(map, 3); - objectives.add(map.getHex(2, 2)); - objectives.add(map.getHex(6, 4)); - objectives.add(map.getHex(6, 1)); - objectives.enable(Hex.OBJECTIVE, true); + map.addObjective(2, 2, Army.NONE); + map.addObjective(6, 4, Army.NONE); + map.addObjective(6, 1, Army.NONE); // hex rows E-H Zone geEntry = new Zone(map, 38); diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java index e3e9c80..52868a2 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java @@ -53,23 +53,11 @@ public class BattleHeadToHead extends BattleCommon if ((ctrl.player.getTurnDone() < 10) || (ctrl.opponent.getTurnDone() < 10)) return null; - int player = 0; - int opponent = 0; - - for (Hex hex : objectives) { - Unit unit = hex.getUnit(); - if (unit != null) { - if (ctrl.player.isEnemy(unit)) - opponent += 1; - else - player += 1; - } - } - - if (player > 1) - return ctrl.player; - else if (opponent > 1) - return ctrl.opponent; + if (ctrl.map.objectives.count(Army.US) >= 2) + return usPlayer; + if (ctrl.map.objectives.count(Army.GE) >= 2) + return gePlayer; + return null; } @@ -81,11 +69,9 @@ public class BattleHeadToHead extends BattleCommon gePlayer.turnEnd(); // B6, E6, H4 - objectives = new HexSet(map, 3); - objectives.add(map.getHex(7, 7)); - objectives.add(map.getHex(6, 4)); - objectives.add(map.getHex(6, 1)); - objectives.enable(Hex.OBJECTIVE, true); + map.addObjective(7, 7, Army.NONE); + map.addObjective(6, 4, Army.NONE); + map.addObjective(6, 1, Army.NONE); // southern hex row Zone geEntry = new Zone(map, 9); diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleLastStand.java b/core/src/ch/asynk/tankontank/game/battles/BattleLastStand.java index 3430d88..234ceed 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleLastStand.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleLastStand.java @@ -54,15 +54,11 @@ public class BattleLastStand extends BattleCommon int gePoints = usPlayer.casualties(); int usPoints = gePlayer.casualties(); + usPoints += ctrl.map.objectives.count(Army.US); for (Unit unit : gePlayer.casualties) { if (unit.isAce()) usPoints += 1; } - for (Hex hex: objectives) { - Unit unit = hex.getUnit(); - if ((unit != null) && unit.is(Army.US)) - usPoints += 1; - } if (usPoints > gePoints) return usPlayer; @@ -74,12 +70,10 @@ public class BattleLastStand extends BattleCommon public void setup(Ctrl ctrl, Map map) { // A7, E6, F6, G10 - objectives = new HexSet(map, 4); - objectives.add(map.getHex(7, 8)); - objectives.add(map.getHex(6, 4)); - objectives.add(map.getHex(5, 3)); - objectives.add(map.getHex(1, 2)); - objectives.enable(Hex.OBJECTIVE, true); + map.addObjective(7, 8, Army.NONE); + map.addObjective(6, 4, Army.NONE); + map.addObjective(5, 3, Army.NONE); + map.addObjective(1, 2, Army.NONE); // 1 hex of E7 Zone geEntry = new Zone(map, 7); diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleStabToTheFlank.java b/core/src/ch/asynk/tankontank/game/battles/BattleStabToTheFlank.java index 9e8a61e..f529d4b 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleStabToTheFlank.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleStabToTheFlank.java @@ -52,6 +52,7 @@ public class BattleStabToTheFlank extends BattleCommon int gePoints = usPlayer.casualties(); int usPoints = gePlayer.casualties(); + usPoints += ctrl.map.objectives.count(Army.US); int escaped = usPlayer.escaped(); if (escaped == 0) @@ -59,12 +60,6 @@ public class BattleStabToTheFlank extends BattleCommon else usPoints += escaped; - for (Hex hex : objectives) { - Unit unit = hex.getUnit(); - if ((unit != null) && unit.is(Army.US)) - usPoints += 1; - } - if (usPoints > gePoints) return usPlayer; else @@ -95,10 +90,8 @@ public class BattleStabToTheFlank extends BattleCommon public void setup(Ctrl ctrl, Map map) { // F6, E6 - objectives = new HexSet(map, 2); - objectives.add(map.getHex(5, 3)); - objectives.add(map.getHex(6, 4)); - objectives.enable(Hex.OBJECTIVE, true); + map.addHoldObjective(5, 3, Army.NONE); + map.addObjective(6, 4, Army.NONE); // hex rows D-I Zone geEntry = new Zone(map, 57); |