public void Run() { bool finished = false; // Stretch 2: Process entries until Ctrl + C do { _consoleInterface.Write("Welcome to String Calculator "); _consoleInterface.Write("Enter Operation: Add, Multiply "); string command = _consoleInterface.ReadLine().ToLower(); if (String.IsNullOrWhiteSpace(command)) { _consoleInterface.Write("Goodbye"); finished = true; } else if (command == "add") { // read input string _consoleInterface.Write("Enter numbers: "); var input = _consoleInterface.ReadLine(); // execute and print var addServiceOutput = _addService.Execute(input); _consoleInterface.WriteLine(addServiceOutput); } else if (command == "multiply") { // read input string _consoleInterface.Write("Enter numbers: "); var input = _consoleInterface.ReadLine(); // execute and print var multiplyServiceOutput = _multiplyService.Execute(input); _consoleInterface.WriteLine(multiplyServiceOutput); } else { _consoleInterface.WriteLine("Invalid Input, please try again"); } }while (!finished); }
public void Run() { bool notFinished = true; do { try { this.WriteCommandPrompt(); notFinished = this.ProcessLineCommand(); } catch (Exception e) { var errorMessage = string.Format("{0}: {1}", e.GetType().Name, e.Message); consoleInterface.WriteLine(errorMessage); //notFinished = false; } }while (notFinished); }
public static string Prompt(this IConsoleInterface con, string message) { con.WriteLine(message); return(con.ReadLine()); }
public void Start() { string nextPlayer = "X"; _view.WriteLine("Welcome to Tic-Tac-Toe Game!"); _view.WriteLine("Player X will go first..."); while (string.IsNullOrEmpty(_game.Winner)) { _view.Write($"Player {nextPlayer} move: "); var playerEntry = _view.ReadLine(); bool isValid = int.TryParse(playerEntry.ToString(), out int nextMove); if (isValid && _game.Play(nextMove)) { nextPlayer = nextPlayer == "X" ? "O" : "X"; } else { _view.WriteLine("Your move is not valid."); } DisplayBoard(); } _view.WriteLine(Environment.NewLine); _view.WriteLine(_game.Winner == "-" ? "Cat's Game!" : $"Player {_game.Winner} Won!"); _view.WriteLine(Environment.NewLine); _view.WriteLine("Press any key to exit.."); _view.ReadKey(); }