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();
        }
Пример #2
0
        private void FillListView()
        {
            using (FiveOursContext db = new FiveOursContext())
            {
                var results = db.Results;

                foreach (var result in results)
                {
                    var convertedResult = new
                    {
                        Id    = result.ResultID,
                        Name  = result.PlayerName,
                        Time  = TimeSpan.FromTicks(result.GameTime),
                        Moves = result.MovesCount
                    };

                    listViewResults.Items.Add(convertedResult);
                }
            }
        }