Example #1
0
        /// <summary>
        /// Interprets a given <see cref="Sentence"/>. Initiates game model manipulation.
        /// </summary>
        /// <param name="sentence">The <see cref="Sentence"/> to interpret.</param>
        public static void Interpret(Sentence sentence)
        {
            if (sentence == null)
            {
                throw new ArgumentNullException(nameof(sentence));
            }
            // iterate through each top level node in sentence
            for (int i = 0; i < sentence.Length; i++)
            {
                // Conjunction
                if (sentence[i] is ConjunctionNode)
                {
                    continue;
                }

                // Command
                else if (sentence[i] is CommandNode command)
                {
                    command.Delegate();
                }

                // Verb
                else if (sentence[i] is VerbNode verb)
                {
                    foreach (VerbUsage syntax in verb.Usages)
                    {
                    }
                    // new verb logic here: check each word against all syntaxes in syntaxList, if end of a syntax is reached, it is potentially correct, if a word does not
                    // match, throw syntax out. Once all syntaxes have been checked: if there are no potentialy correct syntaxes, use the current word in the error message.
                    // Otherwise, go with the longest potentially correct syntax. Only go with an empty syntax if all other syntaxes were thrown out on the first check,
                    // and throw all pending syntaxes out if the end of the sentence is reached (unless the end of the syntax is reached at the same time).
                }

                // Unknown
                else if (sentence[i] is UnknownNode)
                {
                    ConsoleGUI.Print("I don't understand the word \"" + sentence[i].OrigWord + ".\"");
                    return;
                }

                // anything else
                else
                {
                    ConsoleGUI.Print("You lost me at \"" + sentence[i].OrigWord + ".\"");
                    return;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Run the game.
        /// </summary>
        /// <param name="args"></param>
        public static void Run(string[] args)
        {
            ConsoleGUI.Setup();
            Glossary glossary = Load.BuildGlossary();

            while (true)
            {
                Sentence sentence = Sentence.Parse(ConsoleGUI.GetPlayerInput(), glossary, out string errorMessage);
                if (errorMessage != null)
                {
                    ConsoleGUI.Print(errorMessage);
                }
                else
                {
                    Sentence.Interpret(sentence);
                }
            }
        }