summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-17 16:41:47 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-17 16:41:47 +0200
commit79561b976aa7fc4d85a795a5895abf95c19224ca (patch)
tree88bab575efd81e72380b4d66b04b49987191cdd2
parent70f26f0bd227ec9871447d9582b4f7cb78f01a4b (diff)
downloadRustAndDust-79561b976aa7fc4d85a795a5895abf95c19224ca.zip
RustAndDust-79561b976aa7fc4d85a795a5895abf95c19224ca.tar.gz
Ctrl: use Player player,opponent and swap them on turn end
-rw-r--r--core/src/ch/asynk/tankontank/game/Ctrl.java37
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java10
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateAttack.java10
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateCommon.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StatePromote.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateSelect.java6
6 files changed, 29 insertions, 38 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java
index ca2ca64..480dfae 100644
--- a/core/src/ch/asynk/tankontank/game/Ctrl.java
+++ b/core/src/ch/asynk/tankontank/game/Ctrl.java
@@ -18,8 +18,8 @@ public class Ctrl implements Disposable
public Map map;
public Hud hud;
public Config cfg;
- private int player;
- private Player players[] = new Player[2];
+ public Player player;
+ public Player opponent;
private State selectState;
private State pathState;
@@ -38,11 +38,10 @@ public class Ctrl implements Disposable
this.cfg = game.config;
game.ctrl = this;
- this.players[0] = game.factory.getPlayer(Army.GE);
- this.players[1] = game.factory.getPlayer(Army.US);
+ this.player = game.factory.getPlayer(Army.GE);
+ this.opponent = game.factory.getPlayer(Army.US);
this.map = game.factory.getMap(Factory.MapType.MAP_A);
- game.factory.fakeSetup(map, players[0], players[1]);
- player = (new java.util.Random()).nextInt(2);
+ game.factory.fakeSetup(map, player, opponent);
this.selectState = new StateSelect(this, map);
this.pathState = new StateMove();
@@ -55,7 +54,7 @@ public class Ctrl implements Disposable
this.hud = new Hud(this, game);
- player().turnStart();
+ player.turnStart();
}
@Override
@@ -65,16 +64,6 @@ public class Ctrl implements Disposable
map.dispose();
}
- public Player player()
- {
- return this.players[player];
- }
-
- public Player opponent()
- {
- return this.players[((player + 1) % 2)];
- }
-
public boolean mayProcessTouch()
{
return (state != animationState);
@@ -102,18 +91,20 @@ public class Ctrl implements Disposable
private void nextPlayer()
{
- player().turnEnd();
- player = ((player + 1) % 2);
- player().turnStart();
- hud.notify(player().getName() + "'s turn");
+ player.turnEnd();
+ Player tmp = player;
+ player = opponent;
+ opponent = tmp;
+ player.turnStart();
+ hud.notify(player.getName() + "'s turn");
}
private void checkTurnEnd()
{
if (map.activatedPawnsCount() > 0) {
- player().burnDownOneAp();
+ player.burnDownOneAp();
}
- if (player().apExhausted())
+ if (player.apExhausted())
nextPlayer();
}
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
index ef95a22..4a9e0f9 100644
--- a/core/src/ch/asynk/tankontank/game/Hud.java
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -55,8 +55,8 @@ public class Hud implements Disposable
bg = new Bg(atlas.findRegion("disabled"));
msg = new Msg(game.skin.getFont("default-font"), atlas.findRegion("disabled"));
- ctrl.player().setTopLeft(OFFSET, (Gdx.graphics.getHeight() - OFFSET));
- ctrl.opponent().setTopLeft(OFFSET, (Gdx.graphics.getHeight() - OFFSET));
+ ctrl.player.setTopLeft(OFFSET, (Gdx.graphics.getHeight() - OFFSET));
+ ctrl.opponent.setTopLeft(OFFSET, (Gdx.graphics.getHeight() - OFFSET));
}
@Override
@@ -79,7 +79,7 @@ public class Hud implements Disposable
public void draw(Batch batch)
{
- ctrl.player().draw(batch);
+ ctrl.player.draw(batch);
bg.draw(batch);
if (moveBtn.visible) moveBtn.getImage().draw(batch);
if (rotateBtn.visible) rotateBtn.getImage().draw(batch);
@@ -137,7 +137,7 @@ public class Hud implements Disposable
public boolean touchDown(float x, float y)
{
- if (ctrl.player().contains(x,y)) return true;
+ if (ctrl.player.contains(x,y)) return true;
if (!bg.contains(x,y)) return false;
btn = null;
@@ -166,7 +166,7 @@ public class Hud implements Disposable
if (btn != null)
btn.setOn();
- if (ctrl.player().contains(x,y)) {
+ if (ctrl.player.contains(x,y)) {
ctrl.endPlayerTurn();
return true;
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java
index ab37da9..9937913 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateAttack.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java
@@ -19,7 +19,7 @@ public class StateAttack extends StateCommon
// use selectedHex and selectedPawn
from.set(selectedHex);
map.showPossibleTargets(false);
- map.buildPossibleTargets(selectedPawn, from, ctrl.opponent().unitIterator());
+ map.buildPossibleTargets(selectedPawn, from, ctrl.opponent.unitIterator());
map.showPossibleTargets(true);
if (to.x != -1) {
// quick fire -> replay touchUp
@@ -54,7 +54,7 @@ public class StateAttack extends StateCommon
to.set(upHex);
activePawn = map.getTopPawnAt(to);
map.showTarget(to, true);
- map.buildAttackAssists(selectedPawn, activePawn, to, ctrl.player().unitIterator());
+ map.buildAttackAssists(selectedPawn, activePawn, to, ctrl.player.unitIterator());
map.showAttackAssists(true);
ctrl.hud.show(false, false, false, true, true, ctrl.cfg.canCancel);
}
@@ -79,11 +79,11 @@ public class StateAttack extends StateCommon
@Override
public void done()
{
- int d1 = ctrl.player().d6();
- int d2 = ctrl.player().d6();
+ int d1 = ctrl.player.d6();
+ int d2 = ctrl.player.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))
- ctrl.player().casualty(activePawn);
+ ctrl.player.casualty(activePawn);
ctrl.setState(StateType.ANIMATION);
super.done();
diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java
index 416dfaf..e729a84 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, true);
if (selectedPawn != null)
- isEnemy = ctrl.player().isEnemy(selectedPawn);
+ isEnemy = ctrl.player.isEnemy(selectedPawn);
else
isEnemy = false;
System.err.println(" select (" + selectedHex.x + ";" + selectedHex.y + ") " + selectedPawn + (isEnemy ? " enemy " : " friend "));
diff --git a/core/src/ch/asynk/tankontank/game/states/StatePromote.java b/core/src/ch/asynk/tankontank/game/states/StatePromote.java
index b481eee..f998fba 100644
--- a/core/src/ch/asynk/tankontank/game/states/StatePromote.java
+++ b/core/src/ch/asynk/tankontank/game/states/StatePromote.java
@@ -9,7 +9,7 @@ public class StatePromote extends StateCommon
public void enter(boolean flag)
{
ctrl.hud.hide();
- Pawn p = ctrl.player().promote(selectedPawn);
+ Pawn p = ctrl.player.promote(selectedPawn);
if (p != null) {
map.promote(selectedPawn, p);
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateSelect.java b/core/src/ch/asynk/tankontank/game/states/StateSelect.java
index 7a9e3dd..7990666 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateSelect.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateSelect.java
@@ -55,13 +55,13 @@ public class StateSelect extends StateCommon
int moves = map.buildPossibleMoves(selectedPawn, selectedHex);
int targets = 0;
if (isEnemy)
- targets = map.buildPossibleTargets(selectedPawn, selectedHex, ctrl.player().unitIterator());
+ targets = map.buildPossibleTargets(selectedPawn, selectedHex, ctrl.player.unitIterator());
else
- targets = map.buildPossibleTargets(selectedPawn, selectedHex, ctrl.opponent().unitIterator());
+ targets = map.buildPossibleTargets(selectedPawn, selectedHex, ctrl.opponent.unitIterator());
int assists = map.buildMoveAssists(selectedPawn, selectedHex);
showPossibleTargetsMovesAssists(selectedPawn);
ctrl.hud.show(
- ctrl.player().canPromote(selectedPawn),
+ ctrl.player.canPromote(selectedPawn),
selectedPawn.canMove(),
(selectedPawn.canMove() && (moves > 0)),
(selectedPawn.canAttack() && (targets > 0)),