예제 #1
0
파일: Program.cs 프로젝트: silpheed/M
        //testable main
        public static void Run(IEnumerable<string> args, ITextDiscriminator textDiscriminator, IConsoleFacade console, IStateMachine player, IInformationDisplayer informationDisplayer)
        {
            //once off construction of input from execution args
            string input = String.Empty;
            if (args != null)
                foreach (String s in args)
                    input += s + " ";

            //main loop
            bool exit = false;
            while (!exit) {
                foreach (ICommand command in textDiscriminator.Interpret(input.Trim()))
                {
                    //ignore
                    if (command.CommandType == CommandType.Ignore)
                        continue;
                    //quit
                    if ((command.CommandType == CommandType.Exit) || ((command.CommandType == CommandType.Stop) && (player.IsStopped)))
                        exit = true;
                    //everything else is fair game
                    informationDisplayer.ProcessCommand(command);
                    player.ProcessCommand(command);
                }
                if (!exit)
                    input = console.ReadLine();
            }
        }