private void MainBtn_Click(object sender, RoutedEventArgs eve) { var btn = sender as Button; if ((int)btn.GetValue(Grid.RowProperty) == _emptyPosition.Key) //if button and empty field stay in 1 row { if ((int)btn.GetValue(Grid.ColumnProperty) + 1 == _emptyPosition.Value || (int)btn.GetValue(Grid.ColumnProperty) - 1 == _emptyPosition.Value) { var tempPosition = new KeyValuePair <int, int>((int)btn.GetValue(Grid.RowProperty), (int)btn.GetValue(Grid.ColumnProperty)); btn.SetValue(Grid.RowProperty, _emptyPosition.Key); btn.SetValue(Grid.ColumnProperty, _emptyPosition.Value); _emptyPosition = tempPosition; } } if ((int)btn.GetValue(Grid.ColumnProperty) == _emptyPosition.Value) //if button and empty field stay in 1 column { if ((int)btn.GetValue(Grid.RowProperty) + 1 == _emptyPosition.Key || (int)btn.GetValue(Grid.RowProperty) - 1 == _emptyPosition.Key) { var tempPosition = new KeyValuePair <int, int>((int)btn.GetValue(Grid.RowProperty), (int)btn.GetValue(Grid.ColumnProperty)); btn.SetValue(Grid.RowProperty, _emptyPosition.Key); btn.SetValue(Grid.ColumnProperty, _emptyPosition.Value); _emptyPosition = tempPosition; } } if (_isNewGame) { if (IsFinish()) { if (sw.IsRunning) { sw.Stop(); } var currTime = TimeSpan.Parse(currentTime); var tableTime = TimeSpan.Parse(Db_Controller.GetPlayers().First(x => x.NickName == _currNickName).Result == "--:--:--" ? "11:59:59": Db_Controller.GetPlayers().First(x => x.NickName == _currNickName).Result); if (tableTime.ToString() == "--:--:--" || TimeSpan.Compare(currTime, tableTime) == -1) { Db_Controller.UpdateResult(_currNickName, currentTime); } MessageBox.Show($"Congratulations!\n You Win!\n Your best time:{currentTime}"); _isNewGame = false; } } }
private void MenuItem_Click_1(object sender, RoutedEventArgs e) { MessageBox.Show( $"Your result is: {Db_Controller.GetPlayers().First(x => x.NickName == _currNickName).Result}"); }
private void MenuItem_Click(object sender, RoutedEventArgs e) { var resTableWindow = new TableRecordsWindow(Db_Controller.GetPlayers()); resTableWindow.ShowDialog(); }