summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-17 17:47:45 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-17 17:47:45 +0100
commit1cc8cb3977cc4d2464c65111df59b459210b30fb (patch)
treeadf03160b76732e7992f454049500c6266dd5564
parenta1f6fb835be0b32ec3023a92ae28be6872ae14a2 (diff)
downloadRustAndDust-1cc8cb3977cc4d2464c65111df59b459210b30fb.zip
RustAndDust-1cc8cb3977cc4d2464c65111df59b459210b30fb.tar.gz
Battle: owns usPlayer, gePlayer, implementations return them when needed
-rw-r--r--core/src/ch/asynk/tankontank/game/battles/BattleCommon.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java12
-rw-r--r--core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java17
3 files changed, 15 insertions, 18 deletions
diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java b/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java
index d7e6b23..745da34 100644
--- a/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java
+++ b/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java
@@ -19,6 +19,8 @@ public abstract class BattleCommon implements Battle
protected String name;
protected String description;
protected Factory factory;
+ protected Player usPlayer;
+ protected Player gePlayer;
protected ArrayList<EntryPoint> entryPoints = new ArrayList<EntryPoint>();
protected HashMap<Unit, EntryPoint> pawnEntry = new HashMap<Unit, EntryPoint>();
protected TileSet objectives;
@@ -26,6 +28,8 @@ public abstract class BattleCommon implements Battle
public BattleCommon(Factory factory)
{
this.factory = factory;
+ this.usPlayer = factory.getPlayer(Army.US);
+ this.gePlayer = factory.getPlayer(Army.GE);
}
public String toString()
diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java
index 22cb230..1f99fec 100644
--- a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java
+++ b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java
@@ -31,7 +31,10 @@ public class BattleFrontalAssault extends BattleCommon
@Override
public Player getPlayer(boolean first, boolean deploymentPhase)
{
- return factory.getPlayer((first ? Army.GE : Army.US));
+ if (deploymentPhase)
+ return (first ? gePlayer : usPlayer);
+ else
+ return (first ? usPlayer : gePlayer);
}
@Override
@@ -82,17 +85,14 @@ public class BattleFrontalAssault extends BattleCommon
}
if (count > 1)
- return ctrl.getPlayer(Army.US);
+ return usPlayer;
else
- return ctrl.getPlayer(Army.GE);
+ return gePlayer;
}
@Override
public void setup(Ctrl ctrl, Map map)
{
- Player gePlayer = ctrl.getPlayer(Army.GE);
- Player usPlayer = ctrl.getPlayer(Army.US);
-
objectives = new TileSet(map, 3);
objectives.add(map.getHex(2, 2));
objectives.add(map.getHex(6, 4));
diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java
index 7d6286f..7e392a6 100644
--- a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java
+++ b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java
@@ -17,19 +17,12 @@ import ch.asynk.tankontank.engine.Orientation;
public class BattleHeadToHead extends BattleCommon
{
private Army firstArmy;
- private Army secondArmy;
public BattleHeadToHead(Factory factory)
{
super(factory);
name = "Head To Head";
- if (random.nextInt(2) == 0) {
- firstArmy = Army.US;
- secondArmy = Army.GE;
- } else {
- firstArmy = Army.GE;
- secondArmy = Army.US;
- }
+ firstArmy = ((random.nextInt(2) == 0) ? Army.US : Army.GE);
}
@Override
@@ -41,7 +34,10 @@ public class BattleHeadToHead extends BattleCommon
@Override
public Player getPlayer(boolean first, boolean deploymentPhase)
{
- return factory.getPlayer((first ? firstArmy : secondArmy));
+ if (firstArmy == Army.US)
+ return (first ? usPlayer : gePlayer);
+ else
+ return (first ? gePlayer : usPlayer);
}
@Override
@@ -100,9 +96,6 @@ public class BattleHeadToHead extends BattleCommon
@Override
public void setup(Ctrl ctrl, Map map)
{
- Player gePlayer = ctrl.getPlayer(Army.GE);
- Player usPlayer = ctrl.getPlayer(Army.US);
-
gePlayer.deploymentDone();
usPlayer.deploymentDone();