/// <summary> /// Here we'll check the users answer and post the next question until there are no more questions /// </summary> /// <param name="context">The current chat context</param> /// <param name="result">The IAwaitable result</param> /// <returns></returns> private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result) { var activity = (IMessageActivity)await result; await context.PostAsync($"You chose: {activity.Text}"); int usersAnswer = -1; if (int.TryParse(activity.Text, out usersAnswer)) { if (_game.Answer(usersAnswer)) { await context.PostAsync("Correct!"); } else { await context.PostAsync("Sorry, that's wrong :-("); } await context.PostAsync($"Your score is: {_game.Score()}/{_game._questions.Count}. Next question!"); TriviaQuestion nextQuestion = _game.MoveToNextQuestion(); if (nextQuestion != null) { await context.PostAsync(nextQuestion.Question); await context.PostAsync(MakeChoiceCard(context, nextQuestion)); context.Wait(MessageReceivedAsync); } else { await context.PostAsync("That's it! Thanks for playing :-)"); context.Done(""); } } else { await context.PostAsync("I didn't quite get that, I am only programmed to accept numbers :-("); context.Wait(MessageReceivedAsync); } }