public GameEngineModelView() { Locker = new object(); Timer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); Timer.Elapsed += (sender, args) => { if (CanNextTurn()) { NextTurn(); } else { Timer.Stop(); GameState.CurrentTurn = 0; // todo check and rework } }; GameStateSaver = new GameStateSaver(); // todo check for skip TowerType.Empty TowerTypes = Enum.GetValues(typeof(TowerType)) .Cast <TowerType>() .Skip(1) .Select(type => type.CreateTower()); NewGame(); #region Commands BuildTowerCommand = CreateCommand <GameCell>(BuildTowerIn, CanBuildTowerIn, this); NextLevelCommand = CreateCommand(NextLevel, () => GameState.CanNextLevel(), this); SetTowerTypeCommand = CreateCommand <ITower>(SetTowerTypeTo, CanSetTowerTypeTo, this); // menu commands NewGameCommand = CreateCommand(NewGame); UndoTurnCommand = CreateCommand <int>(UndoGameFor, CanUndoGameFor, this); const string file = "test.xml"; // todo : auto start from pause if enemies left ? // todo : select file SaveToFileCommand = CreateCommand(() => SaveGameTo(file), () => EnemiesLeft == 0, this); LoadFromFileCommand = CreateCommand(() => LoadGameFrom(file)); #endregion }
private void LoadGameFrom(string file) { Timer.Stop(); StateOwner = new GameStateOwner(GameStateSaver.LoadFrom(file)); }
private void SaveGameTo(string file) => GameStateSaver.SaveTo(file, StateOwner.GameStates);