private bool validateAnswer(RandomQuestion question) { try { string[] answer = readyText.Text.Split('\n'); //If the user types 11 but the console reads like 1 1 string finalSolution = System.Text.RegularExpressions.Regex.Replace(answer[0], @"\s+", ""); int checkAnswer = Int32.Parse(finalSolution); if (checkAnswer == question.Solution) { ReadyGoStop.Text = "CORRECT!"; inkView.cleanView(true); totalScore++; finalTotalScore.Text = totalScore.ToString(); questions_math.SetBackgroundColor(Color.Green); return(true); } else { ReadyGoStop.Text = "TRY AGAIN!"; return(false); } } catch (FormatException) { return(false); } }
private RandomQuestion createNewQuestion() { questions_math.SetBackgroundColor(Color.AliceBlue); RandomQuestion newQuestion = new RandomQuestion(); questions_math.Text = newQuestion.FirstOperand.ToString() + " " + newQuestion.Operand + " " + newQuestion.SecondOperand.ToString(); return(newQuestion); }
private void ShowQuestions(bool rightAnswer) { RandomQuestion newQuestion = new RandomQuestion(); questions_math.Text = newQuestion.FirstOperand.ToString() + " " + newQuestion.Operand + " " + newQuestion.SecondOperand.ToString(); submitAnswer.Click += (sender, e) => { totalQuestions++; readyText.Text = inkView.Recognize(false); rightAnswer = validateAnswer(newQuestion); if (rightAnswer) { newQuestion = createNewQuestion(); } }; }