protected virtual void NewGame(GameState state = null) { GameViewModel gvm = _viewModelChanger?.GetViewModelByName("Game") as GameViewModel; gvm?.StartGame(state); _viewModelChanger?.ChangeCurrentViewModel("Game"); }
/// <summary> /// Switches to the EndGame view. /// </summary> public virtual void OnGameEnded() { GameEngine.Timer.Stop(); GameEngine.EnemyMovementManager.Stop(); TimeSpan time = GameEngine.Timer.TimeLeft; var endGameViewModel = _viewModelChanger.GetViewModelByName("EndGame") as EndGameViewModel; if (endGameViewModel == null) { throw new InvalidOperationException(); } endGameViewModel.Points = GameEngine.Points; endGameViewModel.GameTime = time; _viewModelChanger?.ChangeCurrentViewModel("EndGame"); }
public virtual void SaveGame() { var gvm = _viewModelChanger?.GetViewModelByName("Game"); var state = (gvm as GameViewModel)?.GameEngine?.SaveState(); SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "Stan gry pacman (*.pacsv) | *.pacsv"; if (dialog.ShowDialog() == true) { try { string path = Path.GetFullPath(dialog.FileName); _gameSerializer.SaveGame(state, path); _savedGame = true; MessageBox.Show("Zapisano", string.Empty, MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception) { MessageBox.Show("Zapis stanu gry nie powiódł się.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error); } } }