diff options
Diffstat (limited to 'core/src/ch')
10 files changed, 91 insertions, 6 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java index dd92575..6ef8eed 100644 --- a/core/src/ch/asynk/tankontank/game/Ctrl.java +++ b/core/src/ch/asynk/tankontank/game/Ctrl.java @@ -7,6 +7,7 @@ import ch.asynk.tankontank.game.states.StateCommon; import ch.asynk.tankontank.game.states.StateSelect; import ch.asynk.tankontank.game.states.StateMove; import ch.asynk.tankontank.game.states.StateRotate; +import ch.asynk.tankontank.game.states.StatePromote; import ch.asynk.tankontank.game.states.StateAttack; import ch.asynk.tankontank.game.states.StateAnimation; @@ -24,6 +25,7 @@ public class Ctrl implements Disposable private State selectState; private State pathState; private State rotateState; + private State promoteState; private State attackState; private State animationState; @@ -46,6 +48,7 @@ public class Ctrl implements Disposable this.selectState = new StateSelect(this, map); this.pathState = new StateMove(); this.rotateState = new StateRotate(); + this.promoteState = new StatePromote(); this.attackState = new StateAttack(); this.animationState = new StateAnimation(); @@ -131,6 +134,9 @@ public class Ctrl implements Disposable case ROTATE: this.state = rotateState; break; + case PROMOTE: + this.state = promoteState; + break; case ATTACK: this.state = attackState; break; diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java index 91af8b3..81009bc 100644 --- a/core/src/ch/asynk/tankontank/game/Hud.java +++ b/core/src/ch/asynk/tankontank/game/Hud.java @@ -25,6 +25,7 @@ public class Hud implements Disposable public Button moveBtn; public Button rotateBtn; + public Button promoteBtn; public Button attackBtn; public Button checkBtn; public Button cancelBtn; @@ -46,6 +47,7 @@ public class Hud implements Disposable moveBtn = new Button(atlas, "btn-move"); rotateBtn = new Button(atlas, "btn-rotate"); + promoteBtn = new Button(atlas, "btn-promote"); attackBtn = new Button(atlas, "btn-attack"); checkBtn = new Button(atlas, "btn-check"); cancelBtn = new Button(atlas, "btn-cancel"); @@ -68,6 +70,7 @@ public class Hud implements Disposable { moveBtn.dispose(); rotateBtn.dispose(); + promoteBtn.dispose(); attackBtn.dispose(); checkBtn.dispose(); cancelBtn.dispose(); @@ -82,6 +85,7 @@ public class Hud implements Disposable flag.draw(batch); if (moveBtn.visible) moveBtn.getImage().draw(batch); if (rotateBtn.visible) rotateBtn.getImage().draw(batch); + if (promoteBtn.visible) promoteBtn.getImage().draw(batch); if (attackBtn.visible) attackBtn.getImage().draw(batch); if (checkBtn.visible) checkBtn.getImage().draw(batch); if (cancelBtn.visible) cancelBtn.getImage().draw(batch); @@ -101,7 +105,7 @@ public class Hud implements Disposable return (y + btn.getHeight() + OFFSET); } - public void show(boolean rotate, boolean move, boolean attack, boolean check, boolean cancel) + public void show(boolean promote, boolean rotate, boolean move, boolean attack, boolean check, boolean cancel) { float x = (bottomLeft.x - checkBtn.getWidth()); float y = bottomLeft.y; @@ -112,6 +116,8 @@ public class Hud implements Disposable else rotateBtn.hide(); if (attack) y = setButton(attackBtn, x, y); else attackBtn.hide(); + if (promote) y = setButton(promoteBtn, x, y); + else promoteBtn.hide(); if (cancel) y = setButton(cancelBtn, x, y); else cancelBtn.hide(); if (check) y = setButton(checkBtn, x, y); @@ -124,6 +130,7 @@ public class Hud implements Disposable { moveBtn.hide(); rotateBtn.hide(); + promoteBtn.hide(); attackBtn.hide(); checkBtn.hide(); cancelBtn.hide(); @@ -140,6 +147,8 @@ public class Hud implements Disposable btn = moveBtn; else if (rotateBtn.hit(x, y)) btn = rotateBtn; + else if (promoteBtn.hit(x, y)) + btn = promoteBtn; else if (attackBtn.hit(x, y)) btn = attackBtn; else if (checkBtn.hit(x, y)) @@ -165,6 +174,8 @@ public class Hud implements Disposable ctrl.setState(State.StateType.MOVE); else if (btn == rotateBtn) ctrl.setState(State.StateType.ROTATE); + else if (btn == promoteBtn) + ctrl.setState(State.StateType.PROMOTE); else if (btn == attackBtn) ctrl.setState(State.StateType.ATTACK); else if (btn == checkBtn) diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 352d73d..1e57c6a 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -362,4 +362,12 @@ public abstract class Map extends Board activatedPawns.add(pawn); return activablePawns.size(); } + + public void promote(Pawn pawn, Pawn with) + { + GridPoint2 coords = getHexUnder(pawn); + removePawnFrom(pawn, coords); + setPawnAt(with, coords, pawn.getOrientation()); + activatedPawns.add(with); + } } diff --git a/core/src/ch/asynk/tankontank/game/Player.java b/core/src/ch/asynk/tankontank/game/Player.java index 5646311..bb50013 100644 --- a/core/src/ch/asynk/tankontank/game/Player.java +++ b/core/src/ch/asynk/tankontank/game/Player.java @@ -118,6 +118,20 @@ public class Player implements Drawable, Disposable return false; } + public Pawn promote(Pawn pawn) + { + for (Pawn p: casualties) { + if (p.isHqOf(pawn)) { + units.remove(pawn); + casualties.add(pawn); + units.add(p); + casualties.remove(p); + return p; + } + } + return null; + } + public void setPosition(float x, float y) { flag.setPosition(x, y); diff --git a/core/src/ch/asynk/tankontank/game/State.java b/core/src/ch/asynk/tankontank/game/State.java index 6156f8b..8f004c4 100644 --- a/core/src/ch/asynk/tankontank/game/State.java +++ b/core/src/ch/asynk/tankontank/game/State.java @@ -7,6 +7,7 @@ public interface State MOVE, ROTATE, ATTACK, + PROMOTE, ANIMATION }; diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java index bbf54d1..c6aebc6 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateAttack.java +++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java @@ -11,7 +11,7 @@ public class StateAttack extends StateCommon public void enter(boolean fromSelect) { map.clearPossibleTargets(); - ctrl.hud.show(false, false, true, false, ctrl.cfg.canCancel); + ctrl.hud.show(false, false, false, true, false, ctrl.cfg.canCancel); ctrl.hud.attackBtn.setOn(); if (fromSelect) { @@ -56,7 +56,7 @@ public class StateAttack extends StateCommon map.showTarget(to, true); map.buildAttackAssists(selectedPawn, activePawn, to, ctrl.currentPlayer().unitIterator()); map.showAttackAssists(true); - ctrl.hud.show(false, false, true, true, ctrl.cfg.canCancel); + ctrl.hud.show(false, false, false, true, true, ctrl.cfg.canCancel); } if ((activePawn != null) && map.isInPossibleAttackAssists(upHex)) { diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java index 43a8d7f..e8e1c3b 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateMove.java +++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java @@ -10,7 +10,7 @@ public class StateMove extends StateCommon public void enter(boolean fromSelect) { map.clearPossiblePaths(); - ctrl.hud.show(true, true, false, ((map.activablePawnsCount() + map.activatedPawnsCount()) > 1), ctrl.cfg.canCancel); + ctrl.hud.show(false, true, true, false, ((map.activablePawnsCount() + map.activatedPawnsCount()) > 1), ctrl.cfg.canCancel); ctrl.hud.moveBtn.setOn(); if (fromSelect) { diff --git a/core/src/ch/asynk/tankontank/game/states/StatePromote.java b/core/src/ch/asynk/tankontank/game/states/StatePromote.java new file mode 100644 index 0000000..cb86fd9 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/states/StatePromote.java @@ -0,0 +1,44 @@ +package ch.asynk.tankontank.game.states; + +import ch.asynk.tankontank.engine.Pawn; +import ch.asynk.tankontank.game.State.StateType; + +public class StatePromote extends StateCommon +{ + @Override + public void enter(boolean flag) + { + ctrl.hud.hide(); + Pawn p = ctrl.currentPlayer().promote(selectedPawn); + if (p != null) { + map.promote(selectedPawn, p); + } + done(); + } + + @Override + public void leave(StateType nextState) + { + } + + @Override + public void touchDown() + { + } + + @Override + public void touchUp() + { + } + + @Override + public void abort() + { + } + + @Override + public void done() + { + super.done(); + } +} diff --git a/core/src/ch/asynk/tankontank/game/states/StateRotate.java b/core/src/ch/asynk/tankontank/game/states/StateRotate.java index 9b26288..43350df 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateRotate.java +++ b/core/src/ch/asynk/tankontank/game/states/StateRotate.java @@ -15,7 +15,7 @@ public class StateRotate extends StateCommon this.rotateOnly = rotateOnly; // if ((map.activablePawnsCount() + map.activatedPawnsCount()) == 1) - ctrl.hud.show(true, false, false, false, ctrl.cfg.canCancel); + ctrl.hud.show(false, true, false, false, false, ctrl.cfg.canCancel); ctrl.hud.rotateBtn.setOn(); if (rotateOnly) { @@ -68,7 +68,7 @@ public class StateRotate extends StateCommon if (ctrl.cfg.mustValidate) { map.showDirections(to, false); map.showOrientation(to, true, o); - ctrl.hud.show(true, false, false, true, ctrl.cfg.canCancel); + ctrl.hud.show(false, true, false, false, true, ctrl.cfg.canCancel); } else doRotation(o); } diff --git a/core/src/ch/asynk/tankontank/game/states/StateSelect.java b/core/src/ch/asynk/tankontank/game/states/StateSelect.java index 5dc5e68..10fbed1 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateSelect.java +++ b/core/src/ch/asynk/tankontank/game/states/StateSelect.java @@ -57,6 +57,7 @@ public class StateSelect extends StateCommon int assists = map.buildMoveAssists(selectedPawn, selectedHex); showPossibleTargetsMovesAssists(selectedPawn); ctrl.hud.show( + ctrl.currentPlayer().canPromote(selectedPawn), selectedPawn.canMove(), (selectedPawn.canMove() && (moves > 0)), (selectedPawn.canAttack() && (targets > 0)), |