public static Rover CreateRover(string definition) { if (string.IsNullOrEmpty(definition)) throw new WrongRoverDefinitionException("Definition of rover is empty."); var coordinatesAndOrientation = definition.Split(' '); if(coordinatesAndOrientation.Length != 3) throw new WrongRoverDefinitionException("Definition of rover doesn't have the proper format."); Coordinates coordinates; IOrientation orientation; try { coordinates = new Coordinates(Convert.ToInt32(coordinatesAndOrientation[0]), Convert.ToInt32(coordinatesAndOrientation[1])); orientation = OrientationFactory.GenerateOrientation(coordinatesAndOrientation[2]); } catch (Exception ex) { throw new WrongRoverDefinitionException("Bad definition.", ex); } var rover = new Rover(); rover.Init(coordinates, orientation); return rover; }
private static Rover CreateRover(string definition) { var coordinatesAndOrientation = definition.Split(' '); var coordinates = new Coordinates(Convert.ToInt32(coordinatesAndOrientation[0]), Convert.ToInt32(coordinatesAndOrientation[1])); var orientation = OrientationFactory.GenerateOrientation(coordinatesAndOrientation[3]); var rover = new Rover(); rover.Init(coordinates, orientation); return rover; }