Example #1
0
        private PlaceParameters ParsePlaceParameters(string command)
        {
            string withoutPlaceWord = command.Remove(0, Place.Length);

            string[] parameters = withoutPlaceWord.Split(',');
            if (parameters.Length < 3)
            {
                return(null);
            }
            int x, y;

            if (!int.TryParse(parameters[0], out x))
            {
                return(null);
            }
            if (!int.TryParse(parameters[1], out y))
            {
                return(null);
            }
            PlaceParameters placeParameters = new PlaceParameters(x, y, parameters[2]);

            if (placeParameters.Heading == CardinalPoint.Undefined)
            {
                throw  new ArgumentException("Cannot move to nowhere");
            }
            return(placeParameters);
        }
Example #2
0
        public string[] Process(string[] args)
        {
            List <string> responses = new List <string>();

            foreach (string arg in args)
            {
                var command = arg.ToLower();
                if (command.StartsWith(Place))
                {
                    PlaceParameters place = ParsePlaceParameters(command);
                    if (place != null)
                    {
                        robot.Place(place.X, place.Y, place.Heading);
                    }
                    continue;
                }

                if (command == "report" && robot.IsPlaced)
                {
                    responses.Add(robot.Position.ToString());
                    continue;
                }
                switch (command)
                {
                case "move":
                    robot.Move();
                    continue;

                case "left":
                    robot.TurnLeft();
                    continue;

                case "right":
                    robot.TurnRight();
                    continue;

                default:
                    continue;
                }
            }
            return(responses.ToArray());
        }