コード例 #1
0
ファイル: DwarfGame.cs プロジェクト: Rod995/dwarfcorp
            public void Update(DwarfGame game)
            {
                switch (LoadState)
                {
                case State.StartingNewGame:
                    Console.Error.WriteLine("Save/load test: starting new game...");
                    game.StateManager.PushState(new LoadState(game, game.StateManager, new WorldGenerationSettings()
                    {
                        GenerateFromScratch = true
                    }));
                    LoadState = State.WaitingForGameStart;
                    break;

                case State.WaitingForGameStart:
                    if (game.StateManager.CurrentState is PlayState)
                    {
                        PlayState state = game.StateManager.CurrentState as PlayState;
                        if (state.IsInitialized)
                        {
                            Console.Error.WriteLine("Save/load test: doing autosave...");
                            state.AutoSave();
                            LoadState = State.SavingNewGame;
                        }
                    }
                    break;

                case State.SavingNewGame:
                {
                    PlayState state = game.StateManager.CurrentState as PlayState;
                    if (state != null && state.IsInitialized && !state.Paused)
                    {
                        Console.Error.WriteLine("Save/load test: loading the saved game...");
                        LoadState = State.LoadingSavedGame;
                    }
                    break;
                }

                case State.LoadingSavedGame:
                {
                    string latestSave = SaveGame.GetLatestSaveFile();

                    if (latestSave != null)
                    {
                        Console.Error.WriteLine("Save/load test: starting to load...");
                        PlayState state = game.StateManager.CurrentState as PlayState;
                        if (state != null && state.IsInitialized && !state.Paused)
                        {
                            state.QuitGame(new LoadState(game, game.StateManager, new WorldGenerationSettings()
                                {
                                    ExistingFile = latestSave
                                }));
                        }
                        LoadState = State.WaitingForLoading;
                    }
                    break;
                }

                case State.WaitingForLoading:
                    if (game.StateManager.CurrentState is PlayState)
                    {
                        PlayState state = game.StateManager.CurrentState as PlayState;
                        if (state.IsInitialized)
                        {
                            Console.Error.WriteLine("Save/load test completed successfully.");
                            LoadState = State.Done;
                        }
                    }
                    break;

                case State.Done:
                    return;
                }
            }