summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/game
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-12-08 21:34:00 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-12-08 21:34:00 +0100
commit126f37e29f279e8ce854e29a4d0313004e58993c (patch)
treea21e38ef28183295597b612010855b6a6c071880 /core/src/ch/asynk/rustanddust/game
parent59e0f7fe6a27f8150df6627a7eac2ec6456f6ba2 (diff)
downloadRustAndDust-126f37e29f279e8ce854e29a4d0313004e58993c.zip
RustAndDust-126f37e29f279e8ce854e29a4d0313004e58993c.tar.gz
Ctrl,Battle: Battle manages currentPlayer and opponent
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game')
-rw-r--r--core/src/ch/asynk/rustanddust/game/Battle.java4
-rw-r--r--core/src/ch/asynk/rustanddust/game/Ctrl.java34
-rw-r--r--core/src/ch/asynk/rustanddust/game/Hud.java4
-rw-r--r--core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java19
-rw-r--r--core/src/ch/asynk/rustanddust/game/battles/BattleTest.java20
-rw-r--r--core/src/ch/asynk/rustanddust/game/hud/UnitDock.java8
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map4Commands.java21
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateDeployment.java2
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateEngage.java10
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateSelect.java6
10 files changed, 63 insertions, 65 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Battle.java b/core/src/ch/asynk/rustanddust/game/Battle.java
index 242e147..fd384df 100644
--- a/core/src/ch/asynk/rustanddust/game/Battle.java
+++ b/core/src/ch/asynk/rustanddust/game/Battle.java
@@ -16,10 +16,12 @@ public interface Battle
public Player getPlayer();
- public Player opponent(Player player);
+ public Player getOpponent();
public MapType getMapType();
+ public void changePlayer();
+
public Map getMap();
public Player checkVictory(Ctrl ctrl);
diff --git a/core/src/ch/asynk/rustanddust/game/Ctrl.java b/core/src/ch/asynk/rustanddust/game/Ctrl.java
index 5bc39a3..ab1293a 100644
--- a/core/src/ch/asynk/rustanddust/game/Ctrl.java
+++ b/core/src/ch/asynk/rustanddust/game/Ctrl.java
@@ -26,8 +26,6 @@ public class Ctrl implements Disposable
public Map map;
public Hud hud;
public Config cfg;
- public Player player;
- public Player opponent;
public boolean blockMap;
public boolean blockHud;
@@ -63,8 +61,6 @@ public class Ctrl implements Disposable
this.map = battle.getMap();
battle.setup(this, map);
this.map.init();
- this.player = battle.getPlayer();
- this.opponent = battle.opponent(player);
this.selectState = new StateSelect(this, map);
this.pathState = new StateMove();
@@ -95,11 +91,6 @@ public class Ctrl implements Disposable
map.dispose();
}
- public Player getPlayer(Army army)
- {
- return (player.is(army) ? player : opponent);
- }
-
public boolean isInAction()
{
return (state != selectState);
@@ -123,20 +114,20 @@ public class Ctrl implements Disposable
private void startPlayerTurn()
{
- player.turnStart();
- // hud.notify(player.getName() + "'s turn", 2, Position.MIDDLE_CENTER, true);
+ battle.getPlayer().turnStart();
+ // hud.notify(battle.getPlayer().getName() + "'s turn", 2, Position.MIDDLE_CENTER, true);
if (battle.getReinforcement(this, map))
hud.notify("You have reinforcement", 2, Position.MIDDLE_CENTER, true);
hud.update();
- setState(battle.getState(player));
+ setState(battle.getState(battle.getPlayer()));
}
private void endPlayerTurn()
{
- player.turnEnd();
+ battle.getPlayer().turnEnd();
Player winner = battle.checkVictory(this);
if (winner != null)
- hud.victory(winner, ((winner == player) ? opponent : player));
+ hud.victory(winner, ((winner == battle.getPlayer()) ? battle.getOpponent() : battle.getPlayer()));
}
private StateType actionAborted()
@@ -145,7 +136,7 @@ public class Ctrl implements Disposable
StateType nextState = this.state.abort();
if (nextState == StateType.ABORT)
- nextState = battle.getState(player);
+ nextState = battle.getState(battle.getPlayer());
return nextState;
}
@@ -154,8 +145,7 @@ public class Ctrl implements Disposable
{
map.turnDone();
endPlayerTurn();
- player = battle.getPlayer();
- opponent = battle.opponent(player);
+ battle.changePlayer();
startPlayerTurn();
}
@@ -168,15 +158,15 @@ public class Ctrl implements Disposable
if (map.unitsActivatedSize() > 0) {
RustAndDust.debug("Ctrl", "burn down 1AP");
hud.notify("1 Action Point burnt", 0.6f, Position.BOTTOM_CENTER, false);
- player.burnDownOneAp();
+ battle.getPlayer().burnDownOneAp();
hud.update();
}
- if (player.apExhausted())
+ if (battle.getPlayer().apExhausted())
hud.notifyNoMoreAP();
}
if (nextState == StateType.DONE)
- nextState = battle.getState(player);
+ nextState = battle.getState(battle.getPlayer());
return nextState;
}
@@ -205,7 +195,7 @@ public class Ctrl implements Disposable
this.state.leave(nextState);
- RustAndDust.debug("Ctrl", String.format(" %s -> %s : %s", stateType, nextState, player));
+ RustAndDust.debug("Ctrl", String.format(" %s -> %s : %s", stateType, nextState, battle.getPlayer()));
switch(nextState) {
case SELECT:
@@ -294,7 +284,7 @@ public class Ctrl implements Disposable
public boolean checkDeploymentDone()
{
- boolean done = battle.deploymentDone(player);
+ boolean done = battle.deploymentDone(battle.getPlayer());
if (done)
hud.askEndDeployment();
return done;
diff --git a/core/src/ch/asynk/rustanddust/game/Hud.java b/core/src/ch/asynk/rustanddust/game/Hud.java
index 7c3ff2e..779c4f9 100644
--- a/core/src/ch/asynk/rustanddust/game/Hud.java
+++ b/core/src/ch/asynk/rustanddust/game/Hud.java
@@ -91,8 +91,8 @@ public class Hud implements Disposable, Animation
public void update()
{
- Position position = ctrl.battle.getHudPosition(ctrl.player);
- playerInfo.update(ctrl.player, position);
+ Position position = ctrl.battle.getHudPosition(ctrl.battle.getPlayer());
+ playerInfo.update(ctrl.battle.getPlayer(), position);
actionButtons.update(position.horizontalMirror());
}
diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
index 731c616..112deaf 100644
--- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
+++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
@@ -24,6 +24,7 @@ public abstract class BattleCommon implements Battle
protected String name;
protected String description;
protected Factory factory;
+ protected Player currentPlayer;
protected Player usPlayer;
protected Player gePlayer;
protected ArrayList<Zone> entryZone = new ArrayList<Zone>();
@@ -74,11 +75,21 @@ public abstract class BattleCommon implements Battle
}
@Override
- public Player opponent(Player player)
+ public Player getPlayer()
{
- if (player == usPlayer)
- return gePlayer;
- return usPlayer;
+ return currentPlayer;
+ }
+
+ @Override
+ public Player getOpponent()
+ {
+ return ((currentPlayer == usPlayer) ? gePlayer : usPlayer);
+ }
+
+ @Override
+ public void changePlayer()
+ {
+ currentPlayer = getOpponent();
}
@Override
diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java b/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java
index 7a9cdce..348e20a 100644
--- a/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java
+++ b/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java
@@ -24,17 +24,6 @@ public class BattleTest extends BattleCommon
}
@Override
- public Player getPlayer()
- {
- if (!gePlayer.isDeploymentDone())
- return gePlayer;
-
- if (gePlayer.getTurnDone() == usPlayer.getTurnDone())
- return usPlayer;
- return gePlayer;
- }
-
- @Override
public Position getHudPosition(Player player)
{
return (player.is(Army.US) ? Position.TOP_RIGHT: Position.TOP_LEFT);
@@ -51,9 +40,9 @@ public class BattleTest extends BattleCommon
@Override
public boolean getReinforcement(Ctrl ctrl, Map map)
{
- if (ctrl.player.is(Army.GE))
+ if (currentPlayer.is(Army.GE))
return false;
- if (ctrl.player.getCurrentTurn() != 2)
+ if (currentPlayer.getCurrentTurn() != 2)
return false;
Zone usEntry = new Zone(map, 1);
@@ -88,7 +77,7 @@ public class BattleTest extends BattleCommon
map.addObjective(3, 4, Army.NONE);
map.addHoldObjective(3, 3, Army.NONE);
- ctrl.player = gePlayer;
+ currentPlayer = gePlayer;
setUnit(map, gePlayer, UnitId.GE_WESPE, 6, 8, Orientation.NORTH, null);
setUnit(map, gePlayer, UnitId.GE_TIGER, 5, 2, Orientation.NORTH, null);
setUnit(map, gePlayer, UnitId.GE_PANZER_IV, 4, 5, Orientation.NORTH_WEST, null);
@@ -110,7 +99,7 @@ public class BattleTest extends BattleCommon
usExit.add(map.getHex(12, 6));
addExitZone(usExit);
- ctrl.player = usPlayer;
+ currentPlayer = usPlayer;
usPlayer.casualty(factory.getUnit(UnitId.US_SHERMAN_HQ));
setUnit(map, usPlayer, UnitId.US_PRIEST, 7, 6, Orientation.SOUTH_EAST, usExit);
setUnit(map, usPlayer, UnitId.US_SHERMAN, 8, 4, Orientation.SOUTH, true, usExit);
@@ -122,5 +111,6 @@ public class BattleTest extends BattleCommon
usPlayer.turnEnd();
map.init();
map.turnDone();
+ currentPlayer = gePlayer;
}
}
diff --git a/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java b/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java
index d2d6f91..bc20c53 100644
--- a/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java
+++ b/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java
@@ -12,6 +12,7 @@ import com.badlogic.gdx.math.Rectangle;
import ch.asynk.rustanddust.engine.gfx.Animation;
import ch.asynk.rustanddust.engine.Orientation;
+import ch.asynk.rustanddust.game.Player;
import ch.asynk.rustanddust.game.Ctrl;
import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.UnitList;
@@ -154,17 +155,18 @@ public class UnitDock extends Bg implements Animation
private boolean resize()
{
- int count = ctrl.player.reinforcement();
+ Player player = ctrl.battle.getPlayer();
+ int count = player.reinforcement();
if (count == 0) {
n = 0;
return false;
}
- if ((count == n) && (units == ctrl.player.reinforcement))
+ if ((count == n) && (units == player.reinforcement))
return true;
n = count;
- units = ctrl.player.reinforcement;
+ units = player.reinforcement;
rect.width = units.get(0).getWidth() + (2 * padding);
rect.height = ((units.get(0).getHeight() * n) + ((n + 1) * padding));
float scaledWidth = (rect.width * scale);
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java b/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java
index b17f1e3..7bb6293 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java
@@ -12,10 +12,12 @@ import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.Player;
import ch.asynk.rustanddust.game.Command;
import ch.asynk.rustanddust.game.Engagement;
+import ch.asynk.rustanddust.game.Battle;
public abstract class Map4Commands extends Map3Animations
{
- private OrderList commands;
+ private final Battle battle;
+ private final OrderList commands;
protected abstract int engagementCost(Engagement e);
protected abstract void resolveEngagement(Engagement e);
@@ -24,7 +26,8 @@ public abstract class Map4Commands extends Map3Animations
{
super(game, map, hex);
- commands = new OrderList();
+ this.battle = game.ctrl.battle;
+ this.commands = new OrderList();
}
@Override
@@ -87,7 +90,7 @@ public abstract class Map4Commands extends Map3Animations
RustAndDust.debug(" revertEnter() "+ unit);
removePawn(unit);
objectives.revert(this);
- game.ctrl.player.revertUnitEntry(unit);
+ battle.getPlayer().revertUnitEntry(unit);
commands.dispose(unit);
unit.reset();
}
@@ -96,14 +99,14 @@ public abstract class Map4Commands extends Map3Animations
{
attack(unit, target, true);
- Command cmd = Command.get(game.ctrl.player);
+ Command cmd = Command.get(battle.getPlayer());
cmd.setEngage(unit, target);
return (process(cmd) == 1);
}
public void promoteUnit(final Unit unit)
{
- Command cmd = Command.get(game.ctrl.player);
+ Command cmd = Command.get(battle.getPlayer());
cmd.setPromote(unit);
process(cmd);
}
@@ -112,7 +115,7 @@ public abstract class Map4Commands extends Map3Animations
private Command getMoveCommand(Unit unit, Move move)
{
- Command cmd = Command.get(game.ctrl.player);
+ Command cmd = Command.get(battle.getPlayer());
cmd.setMove(unit, move);
return cmd;
}
@@ -179,17 +182,17 @@ public abstract class Map4Commands extends Map3Animations
case EXIT:
initMove(unit);
movePawn(unit, move, this);
- game.ctrl.player.unitWithdraw(unit);
+ battle.getPlayer().unitWithdraw(unit);
r = moveableUnits.size();
break;
case SET:
setPawnOnto(unit, move);
- game.ctrl.player.unitEntry(unit);
+ battle.getPlayer().unitEntry(unit);
claim((Hex) move.to, unit.getArmy());
break;
case ENTER:
enterPawn(unit, move);
- game.ctrl.player.unitEntry(unit);
+ battle.getPlayer().unitEntry(unit);
claim((Hex) move.to, unit.getArmy());
break;
default:
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java
index 7d6bb1e..d34d0dd 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java
@@ -101,7 +101,7 @@ public class StateDeployment extends StateCommon
{
selectedUnit = unit;
selectedHex = upHex;
- ctrl.player.reinforcement.remove(unit);
+ ctrl.battle.getPlayer().reinforcement.remove(unit);
map.showOnBoard(unit, upHex, entryZone.orientation);
deployedUnits.add(unit);
entryZone.enable(Hex.AREA, false);
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java
index 5daf1e8..ab7a126 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java
@@ -18,7 +18,7 @@ public class StateEngage extends StateCommon
activeUnit = null;
// use selectedHex and selectedUnit
map.unitsTargetHide();
- map.collectTargets(selectedUnit, ctrl.opponent.units);
+ map.collectTargets(selectedUnit, ctrl.battle.getOpponent().units);
map.unitsTargetShow();
if (to != null) {
// quick fire -> replay touchUp
@@ -54,13 +54,13 @@ public class StateEngage extends StateCommon
{
StateType nextState = StateType.DONE;
if (map.engageUnit(selectedUnit, activeUnit)) {
- ctrl.player.wonEngagementCount += 1;
- ctrl.opponent.casualty(activeUnit);
+ ctrl.battle.getPlayer().wonEngagementCount += 1;
+ ctrl.battle.getOpponent().casualty(activeUnit);
if (map.unitsBreakThroughSize() > 0) {
nextState = StateType.BREAK;
}
} else {
- ctrl.player.lostEngagementCount += 1;
+ ctrl.battle.getPlayer().lostEngagementCount += 1;
}
activeUnit.showTarget();
@@ -87,7 +87,7 @@ public class StateEngage extends StateCommon
to = upHex;
activeUnit = unit;
activeUnit.showTarget();
- map.collectAssists(selectedUnit, activeUnit, ctrl.player.units);
+ map.collectAssists(selectedUnit, activeUnit, ctrl.battle.getPlayer().units);
map.unitsAssistShow();
ctrl.hud.actionButtons.show((ctrl.cfg.mustValidate ? Buttons.DONE.b : 0) | (ctrl.cfg.canCancel ? Buttons.ABORT.b : 0));
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java
index d7738c4..2d97e40 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java
@@ -90,7 +90,7 @@ public class StateSelect extends StateCommon
return;
}
- isEnemy = ctrl.player.isEnemy(unit);
+ isEnemy = ctrl.battle.getPlayer().isEnemy(unit);
if (!isEnemy && (unit == selectedUnit) && unit.canMove()) {
if (unit.isHq()) {
ctrl.hud.notify("HQ activation");
@@ -116,7 +116,7 @@ public class StateSelect extends StateCommon
return;
int moves = map.movesCollect(selectedUnit);
- int targets = map.collectTargets(selectedUnit, (isEnemy ? ctrl.player.units : ctrl.opponent.units));
+ int targets = map.collectTargets(selectedUnit, (isEnemy ? ctrl.battle.getPlayer() : ctrl.battle.getOpponent()).units);
if (moves > 0)
map.collectMoveable(selectedUnit);
@@ -126,7 +126,7 @@ public class StateSelect extends StateCommon
showPossibilities(selectedUnit);
}
- ctrl.hud.actionButtons.show((ctrl.player.canPromote(selectedUnit)) ? Buttons.PROMOTE.b : 0 );
+ ctrl.hud.actionButtons.show((ctrl.battle.getPlayer().canPromote(selectedUnit)) ? Buttons.PROMOTE.b : 0 );
RustAndDust.debug("Select", selectedHex.toString() + " " + selectedUnit + (isEnemy ? " enemy " : " friend "));
}
}