summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-28 23:30:39 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-28 23:30:39 +0100
commit3adfb61709282b45f09d852ab74010da67b348ed (patch)
tree74da0abe937986590a03292aea14d67592f035e9 /core
parentdeae030e26b485db9618d86fbaacd3861436954e (diff)
downloadRustAndDust-3adfb61709282b45f09d852ab74010da67b348ed.zip
RustAndDust-3adfb61709282b45f09d852ab74010da67b348ed.tar.gz
Move and Rotate States: adapt to new moveablePawns definition
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateCommon.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateMove.java55
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateRotate.java18
3 files changed, 39 insertions, 38 deletions
diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java
index 91f0609..6326366 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateCommon.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateCommon.java
@@ -110,13 +110,13 @@ public abstract class StateCommon implements State
{
if (ctrl.cfg.showMoves && pawn.canMove()) map.possibleMoves.show();
if (ctrl.cfg.showTargets && pawn.canAttack()) map.possibleTargets.show();
- if (ctrl.cfg.showMoveAssists && pawn.canMove()) map.moveAssists.show();
+ if (ctrl.cfg.showMoveAssists && pawn.canMove()) map.moveablePawns.show();
}
protected void hidePossibleTargetsMovesAssists()
{
map.possibleMoves.hide();
map.possibleTargets.hide();
- map.moveAssists.hide();
+ map.moveablePawns.hide();
}
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java
index 73d5606..f976b31 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateMove.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java
@@ -1,6 +1,7 @@
package ch.asynk.tankontank.game.states;
import ch.asynk.tankontank.game.Hex;
+import ch.asynk.tankontank.game.Unit;
import ch.asynk.tankontank.game.State.StateType;
public class StateMove extends StateCommon
@@ -9,13 +10,14 @@ public class StateMove extends StateCommon
public void enter(boolean fromSelect)
{
map.possiblePaths.clear();
- ctrl.hud.show(false, true, true, false, ((map.activablePawns.size() + map.activatedPawns.size()) > 1), ctrl.cfg.canCancel);
+ boolean moreThanOne = ((map.moveablePawns.size() + map.activatedPawns.size()) > 1);
+ ctrl.hud.show(false, true, true, false, moreThanOne, ctrl.cfg.canCancel);
ctrl.hud.moveBtn.setOn();
if (fromSelect) {
// use selectedHex and selectedUnit
- from = selectedHex;
activeUnit = selectedUnit;
+ activeUnit.showMoveable(true);
map.buildAndShowMovesAndAssits(activeUnit);
if (to != null) {
// quick move -> replay touchUp
@@ -23,14 +25,12 @@ public class StateMove extends StateCommon
touchUp();
}
} else {
- // back from rotation -> use the above and unmodified activeUnit
- if ((activeUnit == selectedUnit) || !selectedUnit.canMove()) {
- upHex = (Hex) map.moveAssists.first();
- activeUnit = upHex.getUnit();
+ // back from rotation -> chose next Pawn
+ if (selectedUnit.canMove()) {
+ changeUnit(selectedUnit);
} else {
- upHex = selectedHex;
+ changeUnit((Unit) map.moveablePawns.first());
}
- changeUnit(upHex);
}
}
@@ -38,8 +38,9 @@ public class StateMove extends StateCommon
public void leave(StateType nextState)
{
// hide all but assists : want them when in rotation
+ activeUnit.showMoveable(false);
map.possibleMoves.hide();
- map.selectHex(from, false);
+ map.selectHex(activeUnit.getHex(), false);
if (to != null) {
map.selectHex(to, false);
map.showFinalPath(to, false);
@@ -47,7 +48,7 @@ public class StateMove extends StateCommon
if (nextState != StateType.SELECT) {
if (to == null)
- to = from;
+ to = activeUnit.getHex();
}
}
@@ -61,9 +62,11 @@ public class StateMove extends StateCommon
{
int s = map.possiblePaths.size();
- if (map.moveAssists.contains(upHex) || (selectedUnit.canMove() && (selectedHex == upHex))) {
- if(upHex != from)
- changeUnit(upHex);
+ Unit unit = upHex.getUnit();
+
+ if (map.moveablePawns.contains(unit)) {
+ if(unit != activeUnit)
+ changeUnit(unit);
} else if ((s == 0) && map.possibleMoves.contains(upHex)) {
s = buildPaths();
} else if (map.possiblePaths.contains(upHex)) {
@@ -71,9 +74,6 @@ public class StateMove extends StateCommon
}
if (s == 1) {
- // prevent changeUnit
- if (from == selectedHex)
- selectedHex = to;
ctrl.setState(StateType.ROTATE, false);
}
}
@@ -91,6 +91,7 @@ public class StateMove extends StateCommon
public void done()
{
hideAssists();
+ // be sure that the hq is activated
if (selectedUnit.canMove() && (map.activatedPawns.size() > 0))
selectedUnit.move(0);
super.done();
@@ -99,20 +100,18 @@ public class StateMove extends StateCommon
private void hideAssists()
{
map.showAssist(selectedHex, false);
- map.moveAssists.hide();
+ map.moveablePawns.hide();
}
- private void changeUnit(Hex next)
+ private void changeUnit(Unit unit)
{
- if (from != null) {
- // toggle selected to assist
- map.selectHex(from, false);
- map.showAssist(from, true);
- }
- from = next;
- activeUnit = from.getUnit();
- map.selectHex(from, true);
- map.showAssist(from, false);
+ if (activeUnit != null )
+ map.selectHex(activeUnit.getHex(), false);
+ activeUnit = unit;
+ Hex hex = activeUnit.getHex();
+ map.selectHex(hex, true);
+ map.showAssist(hex, false);
+ activeUnit.showMoveable(true);
map.possibleMoves.hide();
map.buildPossibleMoves(activeUnit);
map.possibleMoves.show();
@@ -130,7 +129,7 @@ public class StateMove extends StateCommon
private int togglePoint(int s)
{
- if (downHex == from) {
+ if (downHex == activeUnit.getHex()) {
//
} else if (downHex == to) {
//
diff --git a/core/src/ch/asynk/tankontank/game/states/StateRotate.java b/core/src/ch/asynk/tankontank/game/states/StateRotate.java
index 610ba08..e13923e 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateRotate.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateRotate.java
@@ -18,19 +18,19 @@ public class StateRotate extends StateCommon
ctrl.hud.rotateBtn.setOn();
if (rotateOnly) {
- if (from == null) {
- // rotateBtn from Select state
- from = selectedHex;
+ // rotateBtn from Select state
+ if (activeUnit == null)
activeUnit = selectedUnit;
- }
- to = from;
+ to = activeUnit.getHex();
} else {
+ if (to == null)
+ System.err.println("to is null but should not be");
// show final path
map.selectHex(to, true);
map.showFinalPath(to, true);
}
- map.selectHex(from, true);
+ map.selectHex(activeUnit.getHex(), true);
map.showDirections(to, true);
rotationSet = false;
@@ -40,7 +40,7 @@ public class StateRotate extends StateCommon
public void leave(StateType nextState)
{
map.selectHex(to, false);
- map.selectHex(from, false);
+ map.selectHex(activeUnit.getHex(), false);
map.showFinalPath(to, false);
map.showDirections(to, false);
map.showOrientation(to, false, o);
@@ -60,8 +60,10 @@ public class StateRotate extends StateCommon
o = Orientation.fromAdj(to.getCol(), to.getRow(), downHex.getCol(), downHex.getRow());
if (o == Orientation.KEEP) return;
+ if (rotateOnly && (o == activeUnit.getOrientation())) return;
rotationSet = true;
+
if (ctrl.cfg.mustValidate) {
map.showDirections(to, false);
map.showOrientation(to, true, o);
@@ -94,7 +96,7 @@ public class StateRotate extends StateCommon
private void hideAssists()
{
map.showAssist(selectedHex, false);
- map.moveAssists.hide();
+ map.moveablePawns.hide();
}
private void doRotation(Orientation o)