private async Task GenerateQuestion() { if (Utils.IsInternetAvailable) { mainContainer.Visibility = Visibility.Collapsed; bsyMessage.IsBusy = true; question = await App.methods.GenerateQuestion(); if (question == null) { await Utils.ShowMessage("The question could not be generated. Add more contacts with valid numbers", "Error"); return; } txtNumber.Text = (question.Type != 5) ? question.Contact.PhoneNumber : ""; txtCorrectAnswer.Text = question.Options[question.CorrectOption]; txtName.Text = question.Contact.Name; txtMessage.Foreground = new SolidColorBrush(Colors.White); txtMessage.Text = GetMessage(question.Type); imgContact.Source = Utils.GetBitmap(question.Contact.Thumbnail); rbn0.Content = question.Options[0]; rbn1.Content = question.Options[1]; rbn2.Content = question.Options[2]; rbn3.Content = question.Options[3]; EnableRadioButton(rbn0, true); EnableRadioButton(rbn1, true); EnableRadioButton(rbn2, true); EnableRadioButton(rbn3, true); ShowHideTextBlock(txtCorrectAnswer, false, ""); bsyMessage.IsBusy = false; mainContainer.Visibility = Visibility.Visible; } else { await Utils.ShowMessageNoInternetConnection(); Utils.GoBack(this.Frame); } }
public async Task<Question> GenerateQuestion() { int type = Utils.GetRandomValue(6, 1); int correct = Utils.GetRandomValue(4); var contact = await GetRandomContact(type); if (contact == null) return null; Question question = new Question() { Contact = contact, Type = type, CorrectOption = correct, Options = GetOptions(type, correct, contact) }; App.player = await IncrementQuestion(); return question; }
public bool IsCorrect(Question question, int option) { return option == question.CorrectOption; }