Beispiel #1
0
        public void ProcessCommand(string command)
        {
            var commandLines = command.Split(" ");

            switch (commandLines[0].ToUpper())
            {
            case "PLACE":
                var position = BuildFromArgs(commandLines.Skip(1).ToArray());
                if (position == null)
                {
                    _messageDisplayer.DisplayMessage("Invald Args");
                    break;
                }
                _robot.PlaceAt(position);
                break;

            case "LEFT":
                _robot.Left();
                break;

            case "RIGHT":
                _robot.Right();
                break;

            case "MOVE":
                if (_robot.Report() == null)
                {
                    break;
                }
                var newPosition = _robot.Report().NewPosition();
                if (!_board.ValdatePosition(newPosition))
                {
                    _robot.PlaceAt(newPosition);
                }
                break;

            case "REPORT":
                var poistion = _robot.Report();
                if (poistion == null)
                {
                    _messageDisplayer.DisplayMessage($"Off the board!....");
                    break;
                }
                ;
                _messageDisplayer.DisplayMessage($"Output: {poistion.X}, {poistion.Y}, {poistion.Direction.ToString()}");
                break;

            default:
                _messageDisplayer.DisplayMessage("Invalid Commands");
                break;
            }
        }
Beispiel #2
0
        public void VerifyDirectionsOnRight(DirectionEnum iniitialDirection, DirectionEnum expectedDirection)
        {
            var robot = new RobotProject.Robot();

            robot.PlaceAt(new RobotPosition {
                X = 0, Y = 0, Direction = iniitialDirection
            });
            robot.Right();

            var position = robot.Report();

            Assert.AreEqual(position.Direction, expectedDirection);
        }