//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(); } }
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); }
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; } } } } }
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); }
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); } } }