private void buttonRecords_Click(object sender, RoutedEventArgs e) { if (!IsWindowOpen <WindowRecords>()) { var fileExist = File.Exists(_path); if (fileExist) { WindowRecords records = new WindowRecords(); records.Owner = this; records.Show(); } else { MessageBox.Show("Records does not exist!\nPlay first game!"); } } }
private void b_Click(object sender, RoutedEventArgs e) { if (_game.IsSolved()) { return; } Button button = (Button)sender; int x = int.Parse(button.Name.Substring(1, 1)); int y = int.Parse(button.Name.Substring(2, 1)); _game.CLickAt(x, y); ShowButtons(); ColoredGameButtons(); if (_firstClick) { _stopwatch.Start(); _timer.Start(); _firstClick = false; ButtonPause.IsEnabled = true; ButtonPause.Content = "𝅛𝅛 Pause"; } if (_game.IsSolved()) { if (_stopwatch.IsRunning) { _stopwatch.Stop(); _firstClick = true; } _gameStart = false; LabelMoves.Content = $"You win, {_game.Moves} moves!"; ButtonStart.IsEnabled = false; EnabledGameButtons(false); ButtonPause.IsEnabled = false; ButtonPause.Content = "CONGRATULATIONS!"; NameWindow nw = new NameWindow(); nw.Owner = this; if (nw.ShowDialog() == true) { _fileIoService = new FIleIOService(_path); try { _record = _fileIoService.LoadData(); } catch (Exception exception) { MessageBox.Show(exception.Message); Close(); } _record.Add(new Records((nw.UserName).TrimStart(), _game.Moves, _currentTime, (_stopwatch.Elapsed).TotalMilliseconds)); try { _fileIoService.SaveData(_record); } catch (Exception exception) { MessageBox.Show(exception.Message); Close(); } if (!IsWindowOpen <WindowRecords>()) { WindowRecords records = new WindowRecords(); records.Owner = this; records.Show(); } //UI ButtonRecords.Visibility = Visibility.Visible; Grid.SetColumnSpan(ButtonRecords, 2); Grid.SetColumn(ButtonRecords, 2); Grid.SetColumnSpan(ButtonShuffle, 2); } } }