Example #1
0
        public static Status ExecuteCommand(this Rover rover, string command)
        {
            var isCommandValid = command.ValidateCommandInput();

            if (isCommandValid)
            {
                foreach (var commandChar in command)
                {
                    switch (commandChar)
                    {
                    case (char)Command.Advance:
                    {
                        isCommandValid = rover.Advance();
                        break;
                    }

                    case (char)Command.TurnLeft:
                    {
                        rover.TurnLeft();
                        break;
                    }

                    case (char)Command.TurnRight:
                    {
                        rover.TurnRight();
                        break;
                    }
                    }
                }
            }
            return(new Status()
            {
                IsCommandValid = isCommandValid,
                FinalOrientation = rover.Orientation,
                FinalPosition = rover.RoverPosition
            });
        }