diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-02-19 22:22:50 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-02-19 22:22:50 +0100 |
commit | 2c8831a19f8035bd9f882f22938a96563eaf22ca (patch) | |
tree | 44b1306e3dbcbada2677be09131311e87a325142 /core/src/ch/asynk/tankontank | |
parent | d065bc534df0b906478110f10448cfcc1dbf28df (diff) | |
download | RustAndDust-2c8831a19f8035bd9f882f22938a96563eaf22ca.zip RustAndDust-2c8831a19f8035bd9f882f22938a96563eaf22ca.tar.gz |
Engagement: add private diceRoll() called in EngagementPool.get()
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Engagement.java | 18 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Map.java | 25 |
2 files changed, 19 insertions, 24 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Engagement.java b/core/src/ch/asynk/tankontank/game/Engagement.java index 8f01008..df50123 100644 --- a/core/src/ch/asynk/tankontank/game/Engagement.java +++ b/core/src/ch/asynk/tankontank/game/Engagement.java @@ -2,12 +2,15 @@ package ch.asynk.tankontank.game; import java.util.List; import java.util.LinkedList; +import java.util.Random; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.Disposable; public class Engagement implements Disposable, Pool.Poolable { + private static Random rand = new Random(); + private static final Pool<Engagement> engagementPool = new Pool<Engagement>() { @Override protected Engagement newObject() { @@ -20,6 +23,7 @@ public class Engagement implements Disposable, Pool.Poolable Engagement e = engagementPool.obtain(); e.attacker = attacker; e.defender = defender; + e.diceRoll(); return e; } @@ -73,12 +77,16 @@ public class Engagement implements Disposable, Pool.Poolable assists.add(unit); } - public void set(int d1, int d2, int d3, int d4, int cnt, int flk, int def, int tdf, int wdf) + private void diceRoll() + { + d1 = rand.nextInt(6) + 1; + d2 = rand.nextInt(6) + 1; + d3 = rand.nextInt(6) + 1; + d4 = rand.nextInt(6) + 1; + } + + public void set(int cnt, int flk, int def, int tdf, int wdf) { - this.d1 = d1; - this.d2 = d2; - this.d3 = d3; - this.d4 = d4; this.unitCount = cnt; this.flankBonus = flk; this.unitDefense = def; diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index b1213f6..335a10a 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -1,7 +1,5 @@ package ch.asynk.tankontank.game; -import java.util.Random; - import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.graphics.Texture; @@ -39,8 +37,6 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS { private final Ctrl ctrl; - private Random rand = new Random(); - public final HexSet possibleMoves; public final PathBuilder pathBuilder; @@ -64,11 +60,6 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS protected abstract void setup(); - public int d6() - { - return rand.nextInt(6) + 1; - } - public Map(final TankOnTank game, Board.Config cfg, String textureName) { super(game.factory, cfg, game.manager.get(textureName, Texture.class), @@ -341,7 +332,6 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS r = promoteUnit(cmd.unit, cmd.player); break; case ENGAGE: - // FIXME having the dice roll here does not fit networking game resolveEngagement(cmd.engagement); r = doEngagement(cmd.engagement); break; @@ -511,11 +501,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS private void resolveEngagement(Engagement e) { - int d1 = d6(); - int d2 = d6(); - int d3 = 0; - int d4 = 0; - int dice = d1 + d2; + int dice = e.d1 + e.d2; int distance = 0; boolean mayReroll = false; @@ -563,9 +549,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS success = (s1 >= s2); } if (!success && mayReroll) { - d3 = d6(); - d4 = d6(); - dice = d3 + d4; + dice = e.d3 + e.d4; s1 = (dice + cnt + flk); if (dice == 2) { success = false; @@ -574,9 +558,12 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS } else { success = (s1 >= s2); } + } else { + e.d3 = 0; + e.d4 = 0; } - e.set(d1, d2, d3, d4, cnt, flk, def, tdf, wdf); + e.set(cnt, flk, def, tdf, wdf); e.success = success; e.attackerArmy = ctrl.player.army; e.defenderArmy = ctrl.opponent.army; |