private ICommand ParseUserInput() { Console.SetCursorPosition(0, 20); Console.Write("Enter a row and a column: "); string userInput = Console.ReadLine(); ICommand command = new Command(userInput); return command; }
private void HandleCommand(Command commandInput, string commandInputString) { switch (commandInput) { case Command.Restart: this.currentAction = CurrentAction.Restarting; field = new PlayField(5, 10); player = new Player(); communicator.RenderGameField(field); break; case Command.Top: this.currentAction = CurrentAction.PrintingTopBoard; communicator.RenderWinnerBoard(scoreBoard); break; case Command.Exit: this.currentAction = CurrentAction.IsNotRunning; communicator.PrintUserMessage("Good Bye! "); System.Threading.Thread.Sleep(500); break; case Command.CoordinateForParsing: this.currentAction = CurrentAction.CheckingCoordinates; int userInputRow = parser.ParseCommandToRow(commandInputString); int userInputColumn = parser.ParseCommandToCol(commandInputString); field.MakeChangesToField(userInputRow, userInputColumn); player.UpdateMovesAmmount(); if (field.ClearedLevel()) //if field is empty { FinalizeGame(); this.currentAction = CurrentAction.FinishedGame; } communicator.RenderGameField(field); break; case Command.Invalid: this.currentAction = CurrentAction.IsWaitingForValidInput; if (parser.CheckIfCommandIsCoordinate(commandInputString, field) && !parser.CheckPoppableBalloon(commandInputString, field)) { communicator.PrintUserMessage("Illegal move: cannot pop missing ballon!\n"); } else { communicator.PrintUserMessage("Wrong input ! Try Again !\n"); } break; } }