From d3788af34d63c8352ae4016b543f65e9fe78fedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 13 Oct 2014 17:24:44 +0200 Subject: add StateAttack --- .../asynk/tankontank/game/states/StateAttack.java | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 core/src/ch/asynk/tankontank/game/states/StateAttack.java diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java new file mode 100644 index 0000000..14ade37 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java @@ -0,0 +1,93 @@ +package ch.asynk.tankontank.game.states; + +import com.badlogic.gdx.math.GridPoint2; + +import ch.asynk.tankontank.engine.Pawn; +import ch.asynk.tankontank.game.State.StateType; + +public class StateAttack extends StateCommon +{ + @Override + public void enter(boolean fromSelect) + { + map.clearPossibleTargets(); + ctrl.hud.show(false, false, true, false, ctrl.cfg.canCancel); + ctrl.hud.attackBtn.setOn(); + + if (fromSelect) { + activePawn = null; + // use selectedHex and selectedPawn + from.set(selectedHex); + map.showPossibleTargets(false); + map.buildPossibleTargets(selectedPawn, from); + map.showPossibleTargets(true); + if (to.x != -1) { + // quick fire -> replay touchUp + upHex.set(to); + touchUp(); + } + selectHex(from); + } + } + + @Override + public void leave(StateType nextState) + { + map.showAttackAssists(false); + map.showPossibleTargets(false); + unselectHex(from); + if (to.x != -1) + unselectHex(to); + } + + @Override + public void touchDown() + { + } + + @Override + public void touchUp() + { + // activePawn is the target + if ((activePawn == null) && map.isInPossibleTargets(upHex)) { + map.showPossibleTargets(false); + to.set(upHex); + activePawn = map.getTopPawnAt(to); + showTarget(to, true); + map.buildAttack(selectedPawn, activePawn, to, ctrl.currentPlayer.unitIterator()); + map.showAttackAssists(true); + ctrl.hud.show(false, false, true, true, ctrl.cfg.canCancel); + } + + if ((activePawn != null) && map.isInPossibleAttackAssists(upHex)) { + if (map.toggleAttackAssist(map.getTopPawnAt(upHex))) { + showAssist(upHex, false); + showTarget(upHex, true); + } else { + showAssist(upHex, true); + showTarget(upHex, false); + } + } + } + + @Override + public void abort() + { + super.abort(); + } + + @Override + public void done() + { + int d1 = ctrl.currentPlayer.d6(); + int d2 = ctrl.currentPlayer.d6(); + System.err.print(" attack (" + from.x + ";" + from.y + ") -> (" + to.x + ";" + to.y + ") : 2D6 -> (" + d1 + " + " + d2 + ")"); + if (map.attackPawn(selectedPawn, activePawn, from, to, d1 + d2)) { + map.removePawnFrom(activePawn, to); + ctrl.currentPlayer.casualty(activePawn); + // TODO free move for infantry + } + + super.done(); + } +} -- cgit v1.1-2-g2b99