diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-03-14 15:55:11 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-03-14 15:55:11 +0100 |
commit | 3e969f1d7a9966a40657b1ae07b949cde112525b (patch) | |
tree | 96d74c5ce15d8fb1093e61236b75b69bc4f486ea /core/src/ch/asynk/rustanddust/game | |
parent | c3111281e08da0e7e58032f42751a6b1448dbba8 (diff) | |
download | RustAndDust-3e969f1d7a9966a40657b1ae07b949cde112525b.zip RustAndDust-3e969f1d7a9966a40657b1ae07b949cde112525b.tar.gz |
DB/BattleCommon: add turnCount
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game')
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/Battle.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java | 15 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/ctrl/Solo.java | 9 |
3 files changed, 22 insertions, 6 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Battle.java b/core/src/ch/asynk/rustanddust/game/Battle.java index c8063d1..a21e5a4 100644 --- a/core/src/ch/asynk/rustanddust/game/Battle.java +++ b/core/src/ch/asynk/rustanddust/game/Battle.java @@ -17,6 +17,8 @@ public interface Battle public Position getHudPosition(); + public int getTurnCount(); + public Player getPlayer(); public Player getOpponent(); @@ -37,7 +39,7 @@ public interface Battle public State.StateType getState(); - public void load(String payload); + public void load(int turn, String payload); public String unload(boolean full); } diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java index 2a4f766..50bb1bd 100644 --- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java +++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java @@ -22,6 +22,7 @@ public abstract class BattleCommon implements Battle protected final Factory factory; protected int _id; + protected int turnCount; protected Factory.MapType mapType; protected String name; protected String description; @@ -67,6 +68,7 @@ public abstract class BattleCommon implements Battle { this.map = factory.getMap(getMapType()); setup(); + this.turnCount = 0; this.currentPlayer = players[0]; } @@ -74,6 +76,7 @@ public abstract class BattleCommon implements Battle public void desinit() { this.map = null; + this.turnCount = 0; this.players[0] = null; this.players[1] = null; this.currentPlayer = null; @@ -95,8 +98,9 @@ public abstract class BattleCommon implements Battle } @Override - public void load(String payload) + public void load(int turn, String payload) { + this.turnCount = turn; map.load(payload, players); this.currentPlayer = players[0]; } @@ -130,13 +134,14 @@ public abstract class BattleCommon implements Battle currentPlayer = getOpponent(); currentPlayer.turnStart(getActionPoints()); } + turnCount += 1; map.turnDone(); return ret; } protected boolean turnDoneForBoth() { - return ((currentPlayer.getTurn() > 0) && (currentPlayer.getTurn() == getOpponent().getTurn())); + return ((turnCount > 0) && ((turnCount % 2) == 0)); } protected Player getWinner(int minTurns) @@ -167,6 +172,12 @@ public abstract class BattleCommon implements Battle } @Override + public int getTurnCount() + { + return turnCount; + } + + @Override public Player getPlayer() { return currentPlayer; diff --git a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java index 51a7172..a2c0600 100644 --- a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java +++ b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java @@ -1,6 +1,7 @@ package ch.asynk.rustanddust.game.ctrl; import ch.asynk.rustanddust.RustAndDust; +import ch.asynk.rustanddust.util.GameRecord; import ch.asynk.rustanddust.game.Ctrl; import ch.asynk.rustanddust.game.Battle; @@ -25,7 +26,9 @@ public class Solo extends Ctrl battle.getOpponent().id = other; battle.initialDeployment(); } else { - battle.load(game.db.loadGame(gameId)); + GameRecord r = game.db.loadGame(gameId); + battle.load(r.turn, r.payload); + r.dispose(); } } @@ -44,11 +47,11 @@ public class Solo extends Ctrl private void storeGame() { - game.db.storeGame(gameId, battle.getPlayer().id, battle.unload(true)); + game.db.storeGame(gameId, battle.getTurnCount(), battle.getPlayer().id, battle.unload(true)); } private void storeTurn() { - game.db.storeTurn(gameId, battle.getPlayer().id, battle.unload(false)); + game.db.storeTurn(gameId, battle.getTurnCount(), battle.getPlayer().id, battle.unload(false)); } } |