private void ProcessSubmit() { var submittedAnswer = tAnswer.Text.Trim(); if (submittedAnswer.Length == 0) { MessageBox.Show("You must submit an answer"); return; } bool correct; try { correct = CurrentQuestion.SubmitAnswer(submittedAnswer); } catch (Exception e) { MessageBox.Show($"Your answer is invalid, try again: {e.Message}"); return; } lAnswer.Content = CurrentQuestion.GetAnswer(); if (correct) { lMessage.Foreground = Brushes.Green; lMessage.Content = "Correct!"; } else { lMessage.Foreground = Brushes.Red; lMessage.Content = "Incorrect"; } bNext.IsEnabled = true; bSubmit.IsEnabled = false; }
private void Next_Click(object sender, RoutedEventArgs e) { var correctAnswer = _currentQuestion.GetAnswer(); string studentsAnswer; if (_currentQuestion is AnswerChoiceQuestion) { if (Variants.SelectedIndex == -1) { var message = new Message("Не выбран ответ"); message.ShowDialog(); return; } studentsAnswer = Variants.Items[Variants.SelectedIndex].ToString(); } else { studentsAnswer = StudentsAnswer.Text; } if (correctAnswer == studentsAnswer) { var message = new Message("Верно"); message.ShowDialog(); _correctAnswers++; } else { var message = new Message("Неверно"); message.ShowDialog(); } ShowNextQuestion(); }