예제 #1
0
        public void Play()
        {
            ConsoleHelper.ResetScreen();

            //The game runs forever until user closes the window.
            while (true)
            {
                Console.Write(CurrentQuestion);

                CurrentQuestion = CurrentQuestion.GetNextQuestion();
            }
        }
예제 #2
0
        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());
        }
예제 #3
0
 public static IQuestionTree CreateQuestion(string text, IQuestionTree parent) => new QuestionTree(text, parent);
예제 #4
0
 private void Load() => CurrentQuestion = QuestionFactory.CreateTree();