diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-28 18:07:50 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-28 18:07:50 +0100 |
commit | 0a980b02634f2a0f6cf25a1ea928ec7877e0ee51 (patch) | |
tree | 75feccabbe60d5e2bed734e0523d0197f372bcba /core/src/ch/asynk | |
parent | 7461f77da472539b8ef39875150adc99e2b526d7 (diff) | |
download | RustAndDust-0a980b02634f2a0f6cf25a1ea928ec7877e0ee51.zip RustAndDust-0a980b02634f2a0f6cf25a1ea928ec7877e0ee51.tar.gz |
StateSelect: implement quick rotate
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateCommon.java | 12 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateSelect.java | 56 |
2 files changed, 41 insertions, 27 deletions
diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java index 725e86a..cd230ac 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateCommon.java +++ b/core/src/ch/asynk/tankontank/game/states/StateCommon.java @@ -52,18 +52,6 @@ public abstract class StateCommon implements State return (selectedUnit != null); } - protected void selectHexAndUnit(Hex hex) - { - selectedHex = hex; - selectedUnit = selectedHex.getUnit(); - if (!hex.isOffMap()) map.selectHex(selectedHex); - if (selectedUnit != null) - isEnemy = ctrl.player.isEnemy(selectedUnit); - else - isEnemy = false; - TankOnTank.debug(" select " + selectedHex + selectedUnit + (isEnemy ? " enemy " : " friend ")); - } - protected void showPossibilities(Unit unit) { if (ctrl.cfg.showMoves && unit.canMove()) map.showPossibleMoves(); diff --git a/core/src/ch/asynk/tankontank/game/states/StateSelect.java b/core/src/ch/asynk/tankontank/game/states/StateSelect.java index 86139b7..839784c 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateSelect.java +++ b/core/src/ch/asynk/tankontank/game/states/StateSelect.java @@ -1,9 +1,13 @@ package ch.asynk.tankontank.game.states; import ch.asynk.tankontank.game.Map; +import ch.asynk.tankontank.game.Hex; +import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Ctrl; import ch.asynk.tankontank.game.hud.ActionButtons.Buttons; +import ch.asynk.tankontank.TankOnTank; + public class StateSelect extends StateCommon { public StateSelect(Ctrl ctrl, Map map) @@ -54,6 +58,7 @@ public class StateSelect extends StateCommon @Override public void touchUp() { + if (!isEnemy) { if (map.possibleMoves.contains(upHex)) { // quick move @@ -69,25 +74,46 @@ public class StateSelect extends StateCommon } } - selectHexAndUnit(upHex); hidePossibilities(); + if (upHex.isOffMap()) + return; - if (hasUnit() && (!isEnemy || ctrl.cfg.showEnemyPossibilities)) { - // moves and targets == 0 if selectedUnit can't be activated for - int moves = map.collectPossibleMoves(selectedUnit); - int targets = 0; - if (isEnemy) - targets = map.collectPossibleTargets(selectedUnit, ctrl.player.units); - else - targets = map.collectPossibleTargets(selectedUnit, ctrl.opponent.units); - if (moves > 0) - map.collectMoveableUnits(selectedUnit); - showPossibilities(selectedUnit); - ctrl.hud.actionButtons.show((ctrl.player.canPromote(selectedUnit)) ? Buttons.PROMOTE.b : 0 ); - } else { + Unit unit = upHex.getUnit(); + + if (unit == null) { + isEnemy = false; ctrl.hud.actionButtons.hide(); map.clearAll(); + return; + } + + isEnemy = ctrl.player.isEnemy(unit); + if (!isEnemy && (unit == selectedUnit)) { + // quick rotate + to = upHex; + ctrl.setState(StateType.ROTATE); + } else { + select(upHex, unit, isEnemy); } - if (selectedUnit != null) ctrl.hud.notify(selectedUnit.toString()); + } + + private void select(Hex hex, Unit unit, boolean isEnemy) + { + selectedHex = hex; + selectedUnit = unit; + + if (isEnemy && !ctrl.cfg.showEnemyPossibilities) + return; + + map.selectHex(selectedHex); + // moves and targets == 0 if selectedUnit can't be activated for + if (map.collectPossibleMoves(selectedUnit) > 0) + map.collectMoveableUnits(selectedUnit); + map.collectPossibleTargets(selectedUnit, (isEnemy ? ctrl.player.units : ctrl.opponent.units)); + showPossibilities(selectedUnit); + + ctrl.hud.actionButtons.show((ctrl.player.canPromote(selectedUnit)) ? Buttons.PROMOTE.b : 0 ); + ctrl.hud.notify(selectedUnit.toString()); + TankOnTank.debug(" select " + selectedHex + selectedUnit + (isEnemy ? " enemy " : " friend ")); } } |