Esempio n. 1
0
        /**
         * Ask and interpret the user input. Return a Command object.
         */
        public Command getCommand()
        {
            Console.Write("> ");     // print prompt

            string word1 = null;
            string word2 = null;

            string[] words = Console.ReadLine().Split(' ');
            if (words.Length > 0)
            {
                word1 = words[0];
            }
            if (words.Length > 1)
            {
                word2 = words[1];
            }

            // Now check whether this word is known. If so, create a command with it.
            if (commands.isCommand(word1))
            {
                return(new Command(word1, word2));
            }

            // If not, create a "null" command (for unknown command).
            return(new Command(null, null));
        }
Esempio n. 2
0
        /* Reads commands AND check if it is a command */
        public Command getCommand()
        {
            Console.Write("> ");

            string word1 = null;
            string word2 = null;
            string word3 = null;

            string[] words = Console.ReadLine().Split(' ');
            if (words.Length > 0)
            {
                word1 = words[0];
            }
            if (words.Length > 1)
            {
                word2 = words[1];
            }
            if (words.Length > 2)
            {
                word3 = words[2];
            }

            //If command is known, return the WORDS
            if (commands.isCommand(word1))
            {
                return(new Command(word1, word2, word3));
            }

            // If command is unknown, return NULL
            return(new Command(null, null, null));
        }