Search in sources :

Example 1 with AutoSave

use of games.strategy.engine.delegate.AutoSave in project triplea by triplea-game.

the class ServerGame method runStep.

private void runStep(final boolean stepIsRestoredFromSavedGame) {
    if (getCurrentStep().hasReachedMaxRunCount()) {
        gameData.getSequence().next();
        return;
    }
    if (isGameOver) {
        return;
    }
    final GameStep currentStep = gameData.getSequence().getStep();
    final IDelegate currentDelegate = currentStep.getDelegate();
    if (!stepIsRestoredFromSavedGame && currentDelegate.getClass().isAnnotationPresent(AutoSave.class) && currentDelegate.getClass().getAnnotation(AutoSave.class).beforeStepStart()) {
        autoSaveBefore(currentDelegate);
    }
    startStep(stepIsRestoredFromSavedGame);
    if (!stepIsRestoredFromSavedGame && currentDelegate.getClass().isAnnotationPresent(AutoSave.class) && currentDelegate.getClass().getAnnotation(AutoSave.class).afterStepStart()) {
        autoSaveBefore(currentDelegate);
    }
    if (isGameOver) {
        return;
    }
    waitForPlayerToFinishStep();
    if (isGameOver) {
        return;
    }
    // save after the step has advanced
    // otherwise, the delegate will execute again.
    final boolean autoSaveThisDelegate = currentDelegate.getClass().isAnnotationPresent(AutoSave.class) && currentDelegate.getClass().getAnnotation(AutoSave.class).afterStepEnd();
    if (autoSaveThisDelegate && currentStep.getName().endsWith("Move")) {
        autoSave(getAutoSaveAfterFileNameForGameStep(currentStep));
    }
    endStep();
    if (isGameOver) {
        return;
    }
    if (gameData.getSequence().next()) {
        gameData.getHistory().getHistoryWriter().startNextRound(gameData.getSequence().getRound());
        autoSave(gameData.getSequence().getRound() % 2 == 0 ? SaveGameFileChooser.getAutoSaveEvenFileName() : SaveGameFileChooser.getAutoSaveOddFileName());
    }
    if (autoSaveThisDelegate && !currentStep.getName().endsWith("Move")) {
        autoSave(getAutoSaveAfterFileNameForDelegate(currentDelegate));
    }
}
Also used : AutoSave(games.strategy.engine.delegate.AutoSave) GameStep(games.strategy.engine.data.GameStep) IDelegate(games.strategy.engine.delegate.IDelegate)

Aggregations

GameStep (games.strategy.engine.data.GameStep)1 AutoSave (games.strategy.engine.delegate.AutoSave)1 IDelegate (games.strategy.engine.delegate.IDelegate)1