diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-14 11:14:02 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-14 11:14:02 +0200 |
commit | 9108226756b227265be365d40efa4b3942aa712a (patch) | |
tree | c4d518ca895108f1218f39293d46a8adb153402b /core/src/ch/asynk/tankontank/game | |
parent | d8b0575ebc75691012eddb2590d5d95464a55d1b (diff) | |
download | RustAndDust-9108226756b227265be365d40efa4b3942aa712a.zip RustAndDust-9108226756b227265be365d40efa4b3942aa712a.tar.gz |
Ctrl: use Player[2], randomize first player, add currentPlayer() and otherPlayer()
Diffstat (limited to 'core/src/ch/asynk/tankontank/game')
4 files changed, 29 insertions, 18 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java index 8fae035..dd92575 100644 --- a/core/src/ch/asynk/tankontank/game/Ctrl.java +++ b/core/src/ch/asynk/tankontank/game/Ctrl.java @@ -18,9 +18,8 @@ public class Ctrl implements Disposable public Map map; public Hud hud; public Config cfg; - public Player gePlayer; - public Player usPlayer; - public Player currentPlayer; + private int player; + private Player players[] = new Player[2]; private State selectState; private State pathState; @@ -40,8 +39,9 @@ public class Ctrl implements Disposable this.factory = new Factory(game.manager); this.map = factory.getMap(this, game.manager, Factory.MapType.MAP_A); - this.usPlayer = factory.getPlayer(Army.US); - this.gePlayer = factory.getPlayer(Army.GE); + + this.players[0] = factory.getPlayer(Army.GE); + this.players[1] = factory.getPlayer(Army.US); this.selectState = new StateSelect(this, map); this.pathState = new StateMove(); @@ -50,11 +50,12 @@ public class Ctrl implements Disposable this.animationState = new StateAnimation(); this.state = selectState; - this.currentPlayer = factory.fakeSetup(map, gePlayer, usPlayer); + factory.fakeSetup(map, players[0], players[1]); + player = (new java.util.Random()).nextInt(2); this.hud = new Hud(this, game); - currentPlayer.turnStart(); + currentPlayer().turnStart(); } @Override @@ -65,6 +66,16 @@ public class Ctrl implements Disposable factory.dispose(); } + public Player currentPlayer() + { + return this.players[player]; + } + + public Player otherPlayer() + { + return this.players[((player + 1) % 2)]; + } + public boolean mayProcessTouch() { return (state != animationState); @@ -92,9 +103,9 @@ public class Ctrl implements Disposable private void nextPlayer() { - currentPlayer.turnEnd(); - currentPlayer = ((currentPlayer == usPlayer) ? gePlayer : usPlayer); - currentPlayer.turnStart(); + currentPlayer().turnEnd(); + player = ((player + 1) % 2); + currentPlayer().turnStart(); hud.updatePlayer(); } @@ -136,9 +147,9 @@ public class Ctrl implements Disposable private void checkTurnEnd() { if (map.activatedPawnsCount() > 0) { - currentPlayer.burnDownOneAp(); + currentPlayer().burnDownOneAp(); } - if (currentPlayer.apExhausted()) + if (currentPlayer().apExhausted()) nextPlayer(); } diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java index 9a80143..91af8b3 100644 --- a/core/src/ch/asynk/tankontank/game/Hud.java +++ b/core/src/ch/asynk/tankontank/game/Hud.java @@ -89,7 +89,7 @@ public class Hud implements Disposable public void updatePlayer() { - flag = ctrl.currentPlayer.getFlag(); + flag = ctrl.currentPlayer().getFlag(); flag.setPosition(OFFSET, (Gdx.graphics.getHeight() - flag.getHeight() - OFFSET)); } diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java index c8b104c..7c4d6b2 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateAttack.java +++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java @@ -54,7 +54,7 @@ public class StateAttack extends StateCommon to.set(upHex); activePawn = map.getTopPawnAt(to); map.showTarget(to, true); - map.buildAttack(selectedPawn, activePawn, to, ctrl.currentPlayer.unitIterator()); + map.buildAttackAssists(selectedPawn, activePawn, to, ctrl.currentPlayer().unitIterator()); map.showAttackAssists(true); ctrl.hud.show(false, false, true, true, ctrl.cfg.canCancel); } @@ -79,12 +79,12 @@ public class StateAttack extends StateCommon @Override public void done() { - int d1 = ctrl.currentPlayer.d6(); - int d2 = ctrl.currentPlayer.d6(); + 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); + ctrl.currentPlayer().casualty(activePawn); // TODO free move for infantry } diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java index 86b8838..df4dc56 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateCommon.java +++ b/core/src/ch/asynk/tankontank/game/states/StateCommon.java @@ -110,7 +110,7 @@ public abstract class StateCommon implements State selectedPawn = map.getTopPawnAt(selectedHex); map.selectHex(selectedHex); if (selectedPawn != null) - isEnemy = ctrl.currentPlayer.isEnemy(selectedPawn); + isEnemy = ctrl.currentPlayer().isEnemy(selectedPawn); else isEnemy = false; System.err.println(" select (" + selectedHex.x + ";" + selectedHex.y + ") " + selectedPawn + (isEnemy ? " enemy " : " friend ")); |