public IAnswer AskAnswer(IQuestion question) { var j = 0; var choices = new Dictionary<char,IChoice>(); question.Choices.ForEach(c => choices.Add((char)('a' + j++), c)); var answerChar = '\0'; do { Console.Clear(); Console.WriteLine("Question: {0}", question.QuestionString); foreach (var choice in choices) { Console.WriteLine("{0}. {1}", choice.Key, choice.Value.ChoiceText); } Console.Write("\nAnswer: "); var readLine = Console.ReadLine(); if (readLine == null) continue; if (new[] { "back", "b", "oops", "p", "prev" }.Contains(readLine.ToLower())) { return question.CreateAnswer(Choice.PREVIOUS_ANSWER); } answerChar = readLine[0]; } while (!choices.ContainsKey(answerChar)); return question.CreateAnswer(choices[answerChar]); }
public IAnswer AskAnswer(IQuestion question) { var j = 0; var choices = new Dictionary <char, IChoice>(); question.Choices.ForEach(c => choices.Add((char)('a' + j++), c)); var answerChar = '\0'; do { Console.Clear(); Console.WriteLine("Question: {0}", question.QuestionString); foreach (var choice in choices) { Console.WriteLine("{0}. {1}", choice.Key, choice.Value.ChoiceText); } Console.Write("\nAnswer: "); var readLine = Console.ReadLine(); if (readLine == null) { continue; } if (new[] { "back", "b", "oops", "p", "prev" }.Contains(readLine.ToLower())) { return(question.CreateAnswer(Choice.PREVIOUS_ANSWER)); } answerChar = readLine[0]; } while (!choices.ContainsKey(answerChar)); return(question.CreateAnswer(choices[answerChar])); }