public void Play() { ConsoleHelper.ResetScreen(); //The game runs forever until user closes the window. while (true) { Console.Write(CurrentQuestion); CurrentQuestion = CurrentQuestion.GetNextQuestion(); } }
public static IQuestionTree LoadFromFile() { var path = GeneralConstants.QUESTION_DATABASE; if (!File.Exists(path)) { return(null); } var questions = File.ReadAllLines(path); IQuestionTree node = null, current = null; foreach (var question in questions) { var splitted = question.Split('|'); string rootNode = splitted[0]; string yesNode = splitted.Length > 1 ? splitted[1] : string.Empty; string noNode = splitted.Length > 2 ? splitted[2] : string.Empty; node = current?.Find(rootNode); if (node == null) { node = CreateQuestion(rootNode); current = node; } if (!string.IsNullOrEmpty(yesNode)) { node.SetPositiveQuestion(yesNode); } if (!string.IsNullOrEmpty(noNode)) { node.SetNegativeQuestion(noNode); } } return(current.First()); }
public static IQuestionTree CreateQuestion(string text, IQuestionTree parent) => new QuestionTree(text, parent);
private void Load() => CurrentQuestion = QuestionFactory.CreateTree();