From 5b3b354bd3d39b4193a0a067d76fe46fe42106ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 22 Feb 2016 15:37:40 +0100 Subject: Solo: supports battle reloading --- core/src/ch/asynk/rustanddust/game/ctrl/Solo.java | 28 ++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java index 1a7a0af..bcafe29 100644 --- a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java +++ b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java @@ -6,6 +6,8 @@ import ch.asynk.rustanddust.game.Battle; public class Solo extends Ctrl { + private int gameId; + public Solo(final RustAndDust game, final Battle battle) { super(game, battle); @@ -14,12 +16,32 @@ public class Solo extends Ctrl @Override public void init() { - battle.init(this, 0, 1); + gameId = game.config.gameId; + if (gameId == game.db.NO_RECORDS) { + int me = game.backend.getMyId(); + int other = game.backend.getOpponentId(); + gameId = game.db.storeGameGetId(me, other, battle.getId(), game.config.gameMode.i); + battle.init(this, me, other); + } else { + battle.init(this, game.db.loadState(gameId)); + } } @Override - protected void processAction() { } + protected void processAction() + { + storeState(); + } @Override - protected void processTurn() { } + protected void processTurn() + { + // TODO must store Orders in turns table + storeState(); + } + + private void storeState() + { + game.db.storeState(gameId, battle.getPlayer().getId(), battle.getOpponent().getId(), battle.unload()); + } } -- cgit v1.1-2-g2b99