예제 #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();
            }
        }
예제 #2
0
        public int RequestInput()
        {
            var input = _consoleFacade.ReadLine();

            // old code
            //var input = Console.ReadLine();

            // do something with input
            int.TryParse(input, out var result);

            return(result);
        }
예제 #3
0
        public void Loop()
        {
            field = inputs.GetUserInput();
            field = fieldAlterations.GenerateField(field);

            while (true)
            {
                facade.Clear();
                display.DrawGame(field);
                simulation.StartNewGen(field);
                display.WriteProperties(numOfIterations);
                numOfIterations++;

                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.P)
                    {
                        facade.Clear();
                        facade.WriteLine(Texts.Pause);
                        var answ = facade.ReadLine().ToLower();
                        if (texts.True(answ))
                        {
                            file.Save(field);
                            facade.WriteLine(Texts.Approval);
                            continue;
                        }
                        else if (texts.False(answ))
                        {
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
        }
예제 #4
0
        public Field GetUserInput()
        {
            facade.WriteLine(Texts.Intro);
            facade.WriteLine();
            facade.WriteLine(Texts.StartFromSaved);
            var answ = facade.ReadLine().ToLower();

            if (validation.ValidateQuestion(answ))
            {
                field = fileWorker.Load();
                return(field);
            }
            else if (!validation.ValidateQuestion(answ))
            {
                facade.WriteLine(Texts.Param);
                facade.WriteLine(Texts.Height);
                inputHeight = facade.ReadLine();
                facade.WriteLine(Texts.Width);
                inputWidth = facade.ReadLine();

                var validH = validation.ValidateInt(inputHeight);
                var validW = validation.ValidateInt(inputWidth);

                if (validH && validW)
                {
                    field = CreateInputField(inputHeight, inputWidth);
                    return(field);
                }
                else
                {
                    facade.WriteLine(Texts.Error);
                    GetUserInput();
                    return(field);
                }
            }
            return(field);
        }
예제 #5
0
 public void Run()
 {
     while (true)
     {
         console.Write(">> ");
         var input = console.ReadLine();
         if (input == "exit")
         {
             break;
         }
         if (command.IsValid(input))
         {
             command.Execute(input);
         }
         else
         {
             console.WriteLine(input);
         }
     }
 }