示例#1
0
        public static void ParseUserInput(AI ai)
        {
            string input = DANI.Program.ReadIn().Trim();

            //Basic checks
            if ( input == "quit" ) { Application.Exit(); }
            if ( input == "" ) { return; }

            //Checking if it's not a command - if so, consult AI
            if ( input.Substring(0, 1) != "/" )
            {
                if ( printInput ) { Program.PrintOutLn("You: " + input, false); }
                DANI.Program.PrintOutLn("Dani: ", false);
                DANI.Program.PrintOutLn(ai.GetResponse(input), true); //on a separate line for text-to-speech reasons
            }
            else //Otherwise treat it as a command
            {
                //Tokenise user input
                string[] tokens = input.Substring(1).ToLower().Split(' ');
                if ( tokens.Length == 0 ) { return; }

                switch ( tokens[0] )
                {
                    //Reset the AI
                    case "reset": currentAI = new AI(); break;
                    case "clear": form.outputTextbox.Clear(); break;

                    //Clear the console output
                    case "exit":
                    case "quit": Application.Exit(); break;

                    //Shows the help listing
                    case "help": ShowHelp(); break;

                    //Change the minimum number of sentences generated
                    case "sentencemin":
                    {
                        int newValue;
                        if ( (tokens.Length > 1) && (int.TryParse(tokens[1], out newValue)) )
                        {
                            Sentence.minSentences = newValue;
                            Sentence.maxSentences = Math.Max(Sentence.maxSentences, Sentence.minSentences);
                        }
                        break;
                    }

                    //Change the maximum number of sentences generated
                    case "sentencemax":
                    {
                        int newValue;
                        if ( ( tokens.Length > 1 ) && ( int.TryParse(tokens[1], out newValue) ) )
                        {
                            Sentence.maxSentences = newValue;
                            Sentence.minSentences = Math.Min(Sentence.minSentences, Sentence.maxSentences);
                        }
                        break;
                    }

                    //Wordbank commands split by tokens
                    case "wordbank":
                    {
                        if ( tokens.Length < 2 ) { return; }
                        switch ( tokens[1] )
                        {
                            case "clear": form.outputTextbox.Clear(); break;
                            case "print":
                            {
                                if ( tokens.Length < 3 )
                                { PrintOutLn(currentAI.wordbank.ToString(), false); }
                                else
                                {
                                    Word foundWord;
                                    if ( currentAI.TryGetWord(tokens[2], out foundWord) )
                                    { PrintOutLn(foundWord.ToString(), false); }
                                }
                                break;
                            }

                        } //end of argument switch
                        break;
                    }

                    //Heh, why not
                    case "crash": Environment.FailFast("Hello world"); break;

                } //end of command interpreter
            }
        }