diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-13 17:24:44 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-13 17:24:44 +0200 |
commit | d3788af34d63c8352ae4016b543f65e9fe78fedc (patch) | |
tree | a341fe54746f45903bb542c04115d04ec06e11fa /core/src | |
parent | 209e390927fd961e4175fb889d1a4179263325c3 (diff) | |
download | RustAndDust-d3788af34d63c8352ae4016b543f65e9fe78fedc.zip RustAndDust-d3788af34d63c8352ae4016b543f65e9fe78fedc.tar.gz |
add StateAttack
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateAttack.java | 93 |
1 files changed, 93 insertions, 0 deletions
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(); + } +} |