public static Rover CreateRover(string definition) { if (string.IsNullOrEmpty(definition)) { throw new Exception("Definition of rover is empty."); } var coordinatesAndcardinal = definition.Split(' '); if (coordinatesAndcardinal.Length != 3) { throw new Exception("Definition of rover not properly formatted."); } Coordinates coordinates; ICardinal cardinal; try { coordinates = new Coordinates(Convert.ToInt32(coordinatesAndcardinal[0]), Convert.ToInt32(coordinatesAndcardinal[1])); cardinal = CardinalFactory.GetCardinal(coordinatesAndcardinal[2]); } catch (Exception ex) { throw new Exception("Bad definition.", ex); } var rover = new Rover(); rover.Init(coordinates, cardinal); return(rover); }
public void RotateRight() { cardinal = cardinal.RotateRight(); }
public void RotateLeft() { cardinal = cardinal.RotateLeft(); }
public void Init(Coordinates coordinates, ICardinal cardinal) { this.coordinates = coordinates; this.cardinal = cardinal; }
public Rover() { cardinal = new NoCardinal(); }