From eb01d000218cc87f71937aec0e01d3d360125fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 13 Oct 2014 17:14:30 +0200 Subject: Map: support flank attack --- core/src/ch/asynk/tankontank/game/Hex.java | 2 +- core/src/ch/asynk/tankontank/game/Map.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java index ef5b641..b586515 100644 --- a/core/src/ch/asynk/tankontank/game/Hex.java +++ b/core/src/ch/asynk/tankontank/game/Hex.java @@ -131,7 +131,7 @@ public class Hex extends Tile break; } - System.err.println(" def:" + def); + System.err.println(" >= " + def); return def; } } diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 2519ab0..6f20db8 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -257,10 +257,9 @@ public abstract class Map extends Board clearPointVector(possibleTargets); } - public boolean attackPawn(Pawn pawn, GridPoint2 from, GridPoint2 to, int dice) + public boolean attackPawn(Pawn pawn, Pawn target, GridPoint2 from, GridPoint2 to, int dice) { Hex hex = getHex(to.x, to.y); - Pawn target = hex.getTopPawn(); int activatedUnits = activatedPawns.size(); @@ -270,8 +269,15 @@ public abstract class Map extends Board } else if (dice == 12) { success = true; } else { - // TODO : flank attack - success = (dice + activatedUnits >= hex.defenseFor(target, activatedPawns)); + int flankAttacks = 0; + for (Pawn assist : activatedPawns) { + if (assist.isFlankAttack()) { + flankAttacks = 1; + break; + } + } + System.err.print(" + " + activatedUnits + " + " + flankAttacks); + success = ((dice + activatedUnits + flankAttacks) >= hex.defenseFor(target, activatedPawns)); } // TODO : free move for infantry -- cgit v1.1-2-g2b99