diff options
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Map.java | 38 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/Engagement.java | 59 |
2 files changed, 83 insertions, 14 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 0eb919e..12ee01f 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -61,6 +61,8 @@ public abstract class Map extends Board public boolean success; public int d1; public int d2; + public int d3; + public int d4; public int unitCount; public int flankBonus; public int unitDefense; @@ -69,16 +71,21 @@ public abstract class Map extends Board public int attack; public int defense; - public void set(int d1, int d2, int cnt, int flk, int def, int tdf, int wdf) + public void set(int d1, int d2, int d3, int d4, 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; this.terrainDefense = tdf; this.weatherDefense = wdf; - this.attack = (d1 + d2 + unitCount + flankBonus); + if (d3 == 0) + this.attack = (d1 + d2 + unitCount + flankBonus); + else + this.attack = (d3 + d4 + unitCount + flankBonus); this.defense = (unitDefense + terrainDefense + weatherDefense); } } @@ -351,10 +358,12 @@ public abstract class Map extends Board ctrl.animationDone(); } - private boolean resolveFight(Unit unit, final Unit target) + private boolean resolveFight(Unit unit, final Unit target, boolean mayReroll) { int d1 = d6(); int d2 = d6(); + int d3 = 0; + int d4 = 0; int die = d1 + d2; int distance = 0; @@ -389,7 +398,6 @@ public abstract class Map extends Board } int s1 = (die + cnt + flk); int s2 = (def + tdf + wdf); - engagement.set(d1, d2, cnt, flk, def, tdf, wdf); boolean success = false; if (die == 2) { @@ -399,7 +407,22 @@ public abstract class Map extends Board } else { success = (s1 >= s2); } + if (!success && mayReroll) { + d3 = d6(); + d4 = d6(); + die = d3 + d4; + TankOnTank.debug(String.format("Reroll: (%d %d -> %d %d)", d1, d2, d3, d4)); + s1 = (die + cnt + flk); + if (die == 2) { + success = false; + } else if (die == 12) { + success = true; + } else { + success = (s1 >= s2); + } + } + engagement.set(d1, d2, d3, d4, cnt, flk, def, tdf, wdf); engagement.success = success; engagement.attacker = ctrl.player.army; engagement.defender = ctrl.opponent.army; @@ -433,12 +456,7 @@ public abstract class Map extends Board mayReroll = true; } - boolean success; - success = resolveFight(unit, target); - if (!success && mayReroll) { - TankOnTank.debug("Reroll"); - success = resolveFight(unit, target); - } + boolean success = resolveFight(unit, target, mayReroll); breakUnits.clear(); for (Unit u : activatedUnits) { diff --git a/core/src/ch/asynk/tankontank/game/hud/Engagement.java b/core/src/ch/asynk/tankontank/game/hud/Engagement.java index 5198cb1..4a95f38 100644 --- a/core/src/ch/asynk/tankontank/game/hud/Engagement.java +++ b/core/src/ch/asynk/tankontank/game/hud/Engagement.java @@ -18,7 +18,11 @@ public class Engagement extends Patch implements Animation public static int PADDING = 20; public static int VSPACING = 10; public static int HSPACING = 5; + public static float REROLL_DELAY = 0.3f; + private boolean reroll; + private boolean roll2; + private float delay; private Sprite usFlag; private Sprite geFlag; private Sprite winner; @@ -31,6 +35,8 @@ public class Engagement extends Patch implements Animation private Bg okBtn; private DiceAnimation d1Animation; private DiceAnimation d2Animation; + private DiceAnimation d3Animation; + private DiceAnimation d4Animation; public Engagement(BitmapFont font, TextureAtlas atlas) { @@ -47,6 +53,8 @@ public class Engagement extends Patch implements Animation this.visible = false; this.d1Animation = new DiceAnimation(); this.d2Animation = new DiceAnimation(); + this.d3Animation = new DiceAnimation(); + this.d4Animation = new DiceAnimation(); } public void show(Map.Engagement e, Position position, float volume) @@ -99,9 +107,28 @@ public class Engagement extends Patch implements Animation attack.setPosition(x, y); attackR.setPosition(defenseR.getX(), y); + reroll = (e.d3 != 0); + delay = 0f; + if (reroll) { + d3Animation.set(e.d3, x, y); + d4Animation.set(e.d4, x, y); + } + visible = true; } + private void reroll() + { + // hud.notify("Ace re-roll"); + roll2 = true; + float h = (getHeight() + d1Animation.getHeight() + VSPACING); + set(getX(), getY(), getWidth(), h); + d3Animation.set(d1Animation.getX(), d1Animation.getY()); + d4Animation.set(d2Animation.getX(), d2Animation.getY()); + d1Animation.set(d1Animation.getX(), (d1Animation.getY() + d1Animation.getHeight() + VSPACING)); + d2Animation.set(d2Animation.getX(), (d2Animation.getY() + d2Animation.getHeight() + VSPACING)); + } + public boolean hit(float x, float y) { if (okBtn.hit(x, y)) @@ -113,8 +140,17 @@ public class Engagement extends Patch implements Animation public boolean animate(float delta) { if (!visible) return true; - d1Animation.animate(delta); - d2Animation.animate(delta); + if (!roll2) { + d1Animation.animate(delta); + d2Animation.animate(delta); + } else { + if (delay < REROLL_DELAY) { + delay += delta; + return false; + } + d3Animation.animate(delta); + d4Animation.animate(delta); + } return false; } @@ -128,6 +164,8 @@ public class Engagement extends Patch implements Animation defenseR.dispose(); d1Animation.dispose(); d2Animation.dispose(); + d3Animation.dispose(); + d4Animation.dispose(); okBtn.dispose(); } @@ -139,14 +177,27 @@ public class Engagement extends Patch implements Animation attackImg.draw(batch); d1Animation.draw(batch); d2Animation.draw(batch); + if (roll2) { + d3Animation.draw(batch); + d4Animation.draw(batch); + } attack.draw(batch); defenseImg.draw(batch); defense.draw(batch); defenseR.draw(batch); okBtn.draw(batch); if (d1Animation.isDone() && d2Animation.isDone()) { - attackR.draw(batch); - winner.draw(batch); + if (reroll) { + if (!roll2) + reroll(); + if (d3Animation.isDone() && d4Animation.isDone()) { + attackR.draw(batch); + winner.draw(batch); + } + } else { + attackR.draw(batch); + winner.draw(batch); + } } } |