summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/rustanddust/game/Battle.java6
-rw-r--r--core/src/ch/asynk/rustanddust/game/Ctrl.java54
-rw-r--r--core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java22
-rw-r--r--core/src/ch/asynk/rustanddust/game/battles/BattleTest.java14
4 files changed, 51 insertions, 45 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Battle.java b/core/src/ch/asynk/rustanddust/game/Battle.java
index 7cd3b37..27a5079 100644
--- a/core/src/ch/asynk/rustanddust/game/Battle.java
+++ b/core/src/ch/asynk/rustanddust/game/Battle.java
@@ -15,10 +15,12 @@ public interface Battle
public MapType getMapType();
- public void changePlayer();
-
public Player getVictor();
+ public void start();
+
+ public boolean turnDone();
+
public boolean hasReinforcement();
public Zone getEntryZone(Unit unit);
diff --git a/core/src/ch/asynk/rustanddust/game/Ctrl.java b/core/src/ch/asynk/rustanddust/game/Ctrl.java
index 2f92542..2129f22 100644
--- a/core/src/ch/asynk/rustanddust/game/Ctrl.java
+++ b/core/src/ch/asynk/rustanddust/game/Ctrl.java
@@ -55,8 +55,6 @@ public class Ctrl implements Disposable
this.battle = battle;
game.ctrl = this;
- this.map = battle.setup();
-
this.selectState = new StateSelect();
this.pathState = new StateMove();
this.rotateState = new StateRotate();
@@ -70,14 +68,19 @@ public class Ctrl implements Disposable
this.state = selectState;
this.stateType = StateType.DONE;
- StateCommon.set(game);
- this.hud = new Hud(game);
this.blockMap = false;
this.blockHud = false;
- hud.notify(battle.toString(), 2, Position.MIDDLE_CENTER, false);
- startPlayerTurn();
+ this.map = battle.setup();
+ this.hud = new Hud(game);
+ StateCommon.set(game);
+
+ battle.start();
+ hud.update();
+ setState(battle.getState());
+
+ this.hud.notify(battle.toString(), 2, Position.MIDDLE_CENTER, false);
}
@Override
@@ -87,6 +90,18 @@ public class Ctrl implements Disposable
map.dispose();
}
+ private void turnDone()
+ {
+ if (battle.turnDone())
+ hud.victory(battle.getPlayer(), battle.getOpponent());
+ else {
+ hud.update();
+ if (battle.hasReinforcement())
+ hud.notify("You have reinforcement", 2, Position.MIDDLE_CENTER, true);
+ setState(battle.getState());
+ }
+ }
+
public void animationsOver()
{
if (hud.dialogActive())
@@ -97,30 +112,11 @@ public class Ctrl implements Disposable
private void leaveAnimationState()
{
-
StateType tmp = stateAfterAnimation;
stateAfterAnimation = StateType.DONE;
setState(tmp);
}
- private void startPlayerTurn()
- {
- battle.getPlayer().turnStart();
- // hud.notify(battle.getPlayer().getName() + "'s turn", 2, Position.MIDDLE_CENTER, true);
- if (battle.hasReinforcement())
- hud.notify("You have reinforcement", 2, Position.MIDDLE_CENTER, true);
- hud.update();
- setState(battle.getState());
- }
-
- private void endPlayerTurn()
- {
- battle.getPlayer().turnEnd();
- Player winner = battle.getVictor();
- if (winner != null)
- hud.victory(winner, ((winner == battle.getPlayer()) ? battle.getOpponent() : battle.getPlayer()));
- }
-
private StateType actionAborted()
{
hud.notify("Action canceled");
@@ -132,14 +128,6 @@ public class Ctrl implements Disposable
return nextState;
}
- private void turnDone()
- {
- map.turnDone();
- endPlayerTurn();
- battle.changePlayer();
- startPlayerTurn();
- }
-
private StateType actionDone()
{
StateType nextState = this.state.execute();
diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
index 10534c8..b1c5192 100644
--- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
+++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
@@ -71,21 +71,31 @@ public abstract class BattleCommon implements Battle
}
@Override
- public Player getPlayer()
+ public boolean turnDone()
{
- return currentPlayer;
+ map.turnDone();
+ currentPlayer.turnEnd();
+ Player winner = getVictor();
+ if (winner != null) {
+ currentPlayer = winner;
+ return true;
+ } else {
+ currentPlayer = getOpponent();
+ currentPlayer.turnStart();
+ return false;
+ }
}
@Override
- public Player getOpponent()
+ public Player getPlayer()
{
- return ((currentPlayer == usPlayer) ? gePlayer : usPlayer);
+ return currentPlayer;
}
@Override
- public void changePlayer()
+ public Player getOpponent()
{
- currentPlayer = getOpponent();
+ return ((currentPlayer == usPlayer) ? gePlayer : usPlayer);
}
@Override
diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java b/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java
index b9b6333..f161a36 100644
--- a/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java
+++ b/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java
@@ -27,6 +27,16 @@ public class BattleTest extends BattleCommon
}
@Override
+ public void start()
+ {
+ map.actionDone();
+ map.turnDone();
+ usPlayer.turnEnd();
+ gePlayer.turnEnd();
+ currentPlayer = gePlayer;
+ }
+
+ @Override
public Player getVictor()
{
if (usPlayer.getTurnDone() > 2)
@@ -93,10 +103,6 @@ public class BattleTest extends BattleCommon
setUnit(map, usPlayer, UnitId.US_PERSHING, 6, 5, Orientation.SOUTH, usExit);
setUnit(map, usPlayer, UnitId.US_INFANTRY, 5, 3, Orientation.NORTH_EAST, usExit);
setUnit(map, usPlayer, UnitId.US_AT_GUN, 6, 1, Orientation.SOUTH, usExit);
- usPlayer.turnEnd();
- map.init();
- map.turnDone();
- currentPlayer = gePlayer;
return this.map;
}