/// <summary> /// Creates a new question /// </summary> private void NextQuestion() { if (NumberOfQuestionsLeft > 0) { // Break is over and buttons are now usable IsBreakOn = false; // Gets the buttons with content from helper class and set the correct answer Tuple <List <Button>, Country> questions = nextQuestion.GetQuestion(ListOfButtons, ListofCountries, gameMode, NumberOfQuestionsLeft); ListOfButtons = questions.Item1; CorrectAnswer = questions.Item2; // Removes the country from the list of questions if (gameMode == GameMode.Capitals) { ListofCountries.Remove(CorrectAnswer); } else { ListofCountries.Remove(CorrectAnswer); } // Sets the question string based on the gamemode Question = nextQuestion.QuestionString; } else { // Changes the page to summary ChangePage(ApplicationPage.SummaryPage); // Sends the message to the SummaryViewModel MessengerInstance.Send(new NotificationMessage <GameMode>(gameMode, "GameModeSummary")); MessengerInstance.Send(new NotificationMessage <List <Tuple <bool, Country, Country> > >(answers, "Summary")); } }
private void CheckTheAnswer(object parameter) { // Casts the parameter as a string Button answer = (Button)parameter; // Initialize string correctAnswerString = string.Empty; Country userAnswer = new Country(); // Check the answer based on the game mode if (gameMode == GameMode.Capitals) { userAnswer = ListofCountries.Where(c => c.Name == answer.Content).FirstOrDefault(); correctAnswerString = CorrectAnswer.Name; } else { userAnswer = ListofCountries.Where(c => c.Capital == answer.Content).FirstOrDefault(); correctAnswerString = CorrectAnswer.Capital; } // Color the buttons according to answers foreach (var button in ListOfButtons) { IsBreakOn = true; // Users choice if (button.Content == answer.Content) { button.IsSelected = true; } // Sets the color of buttons if (button.IsSelected == true && button.Content == correctAnswerString) { button.BackgroundColor = "Green"; } else if (button.IsSelected == true && button.Content != correctAnswerString) { button.BackgroundColor = "Red"; } else if (button.Content == correctAnswerString) { button.BackgroundColor = "Green"; } else { button.BackgroundColor = "Blue"; } } // If the user's answer matcher the correct answer then he gets a point if (answer.Content == correctAnswerString) { // Decrease number of questions by 1 NumberOfQuestionsLeft--; // Increase user score by one NumberOfCorrectAnswers++; // Adds the used country into summary, true because user was right answers.Add(new Tuple <bool, Country, Country>(true, CorrectAnswer, userAnswer)); } else { // Decrease number of questions by 1 NumberOfQuestionsLeft--; // Adds the used country into summary, false because user was wrong answers.Add(new Tuple <bool, Country, Country>(false, CorrectAnswer, userAnswer)); } }