예제 #1
0
        /// <summary>
        /// Processes the input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        /// <exception cref="InvalidInputDataException">
        /// </exception>
        public bool ProcessInput(string input)
        {
            string[] commandArgs = Regex.Split(input, @"\s+").Where(s => s != string.Empty).ToArray();

            bool isInputValid = false;
            bool result       = false;

            try
            {
                switch (commandArgs[0])
                {
                case "L":
                case "l":
                    isInputValid = InputCommandValidator.ValidateInput(commandArgs, 5);

                    if (!isInputValid)
                    {
                        throw new InvalidInputDataException();
                    }
                    this.CanvasProcessor.DrawLineOnCanvas(Canvas, commandArgs);
                    break;

                case "R":
                case "r":
                    isInputValid = InputCommandValidator.ValidateInput(commandArgs, 5);

                    if (!isInputValid)
                    {
                        throw new InvalidInputDataException();
                    }

                    this.CanvasProcessor.DrawARectangleOnCanvas(Canvas, commandArgs);
                    break;

                case "B":
                case "b":
                    isInputValid = InputCommandValidator.ValidateInput(commandArgs, 4);

                    if (!isInputValid)
                    {
                        throw new InvalidInputDataException();
                    }

                    this.CanvasProcessor.BucketFillOnCanvas(Canvas, commandArgs);
                    break;

                case "Q":
                case "q":
                    OutputWriter.SendToOutput("Returning to Main Menu", true);
                    result = true;
                    break;

                default:
                    OutputWriter.SendToOutput("Invalid Option, please choose from below", true);
                    break;
                }
            }
            catch (InvalidInputDataException exception)
            {
                OutputWriter.SendToOutput(exception.Message, true);
            }
            return(result);
        }
예제 #2
0
 public void Setup()
 {
     _inputCommandValidator = new InputCommandValidator();
     _outputWriter          = new StandardInputOutputWriter();
 }
예제 #3
0
 public void TearDown()
 {
     _inputCommandValidator = null;
     _outputWriter          = null;
 }
        /// <summary>
        /// Process the game.
        /// </summary>
        /// <param name="playBoard">Current play board value.</param>
        /// <param name="playerMoves">Current player moves.</param>
        public void ProcessGame(ref char[,] playBoard, ref int playerMoves)
        {
            byte rowLenght = (byte)playBoard.GetLength(0);
            byte columnLenght = (byte)playBoard.GetLength(1);
            Board boardGenerator = new Board(rowLenght, columnLenght);

            ScoreBoardFormatter formatter = new ScoreBoardFormatter();

            // ILogger fileLogger = new FileLogger("scorebord.txt", formatter);
            ILogger consoleLogger = new ConsoleLogger(formatter);
            ScoreBoard scoreBoard = new ScoreBoard(consoleLogger);

            var printer = PrintingManager.Instance;

            switch (this.currentCommand)
            {
                case "RESTART":
                    IInputCommand restart = new RestartCommand(boardGenerator, printer);
                    restart.Execute(ref playBoard, ref playerMoves);
                    break;

                case "TOP":
                    IInputCommand topscoreBoard = new TopCommand(scoreBoard, this.topPlayers);
                    topscoreBoard.Execute(ref playBoard, ref playerMoves);
                    break;

                case "EXIT":
                    break;

                default:
                    InputCommandValidator validator = new InputCommandValidator();
                    if (validator.IsValidInputCommand(this.currentCommand))
                    {
                        IInputCommand play = new PlayCommand(this.currentCommand, this.topPlayers, scoreBoard, boardGenerator, printer);
                        play.Execute(ref playBoard, ref playerMoves);
                        break;
                    }

                    Console.WriteLine("Wrong input ! Try Again ! ");
                    break;
            }
        }