private async Task <DialogTurnResult> EndGameStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Find the matching game to play and set up our state ScoreState so = stepContext.GetResultAs <ScoreState>(); await stepContext.Context.SendMultipleTextActivity(new[] { $"{so.PlayerName}, you finished the {so.CurrentGame.GameName} game!, with {so.GetCurrentScore()} points!", "Talk to me to restart" }); return(await stepContext.EndDialogAsync(so, cancellationToken)); }
private async Task <DialogTurnResult> CheckAnswerDialogStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { ScoreState ss = stepContext.GetStateAs <ScoreState>(); bool questioncorrect = false; switch (ss.CurrentGame.GameType) { case "Maths": // Split the question out into operands string[] qarray = ss.GetCurrentAnswer().Split(" "); int op1 = int.Parse(qarray[0]); string op = qarray[1]; int op2 = int.Parse(qarray[2]); int answer = 0; // Now calculate and evaluate the answer switch (op) { case "+": answer = op1 + op2; break; case "-": answer = op1 - op2; break; case "*": answer = op1 * op2; break; case "/": answer = op1 / op2; break; default: break; } questioncorrect = (stepContext.GetResultAs <int>() == answer); break; case "Phonics": questioncorrect = (stepContext.GetResultAs <string>().ToLower().Replace(".", "").Trim() == ss.GetCurrentAnswer().ToLower().Trim()); break; default: break; } if (questioncorrect) { ss.MoveToNextTurn(true); await stepContext.Context.SendTextActivity($"That's Right, an extra 2 points for you, taking you to {ss.GetCurrentScore()} in total"); } else { ss.MoveToNextTurn(false); await stepContext.Context.SendTextActivity($"That's incorrect so you lose a point, leaving you with {ss.GetCurrentScore()}in total."); } if (ss.IsGameFinished()) { // This is the last question, They're done, exit and return their ScoreState Object back. return(await stepContext.EndDialogAsync(ss, cancellationToken)); } else { // More to come ... so lets ask a new question return(await stepContext.ReplaceDialogAsync(nameof(GamePlayQuestionDialog), ss, cancellationToken)); } }