private void GameCompleted() { MessageBox.Show("Niice!", "Completed", MessageBoxButton.OK, MessageBoxImage.Information); if (_playerName == "") { var mbResult = MessageBox.Show("Do you want to save your result?", "Saving results", MessageBoxButton.YesNo, MessageBoxImage.Information); if (mbResult == MessageBoxResult.Yes) { PlayerNameDialog nameWindow = new PlayerNameDialog(); if (nameWindow.ShowDialog() == true) { _playerName = nameWindow.Name; } } else { LogHelper.Log(LogTarget.File, LogType.Info, $"Game completed without saving results."); } } if (_playerName != "") { using (FiveOursContext db = new FiveOursContext()) { var result = new Result() { PlayerName = _playerName, GameTime = _timerTime.Ticks, MovesCount = _moves }; db.Add(result); db.SaveChanges(); } LogHelper.Log(LogTarget.File, LogType.Info, $"Game completed with saving results. Player name: {_playerName}"); } ResultsWindow cw = new ResultsWindow(); cw.ShowInTaskbar = false; cw.Owner = Application.Current.MainWindow; cw.Show(); _isClosingByEndingGame = true; Close(); }
private void NotFastGameBtnClick(object sender, RoutedEventArgs e) { try { PlayerNameDialog nameWindow = new PlayerNameDialog(); if (nameWindow.ShowDialog() == true) { GameWindow cw = new GameWindow(nameWindow.Name); cw.ShowInTaskbar = false; cw.Owner = Application.Current.MainWindow; this.Visibility = Visibility.Hidden; LogHelper.Log(LogTarget.File, LogType.Info, $"Usual game started. Player name: {nameWindow.Name}"); cw.Show(); } } catch (Exception ex) { LogHelper.Log(LogTarget.File, LogType.Fatal, ex.ToString()); } }