public Robot(int initialX, int initialY, OrientationEnum orientation, IGrid grid, IRobotCommandMarshaller commandMarshaller) { _commandMarshaller = commandMarshaller; _commandMarshaller.SetRobot(this); _grid = grid; X = initialX; Y = initialY; Orientation = orientation; }
public Robot(string setupString, IGrid grid, IRobotCommandMarshaller commandMarshaller) { _commandMarshaller = commandMarshaller; commandMarshaller.SetRobot(this); _grid = grid; string[] setupParts = setupString.Split(' '); if (setupParts.Length != 3) { throw new ArgumentException("To set up a robot provide X Y [N|E|S|W] values seperated by spaces\ne.g: 1 1 N"); } int tryX = 0, tryY = 0; if (!int.TryParse(setupParts[0], out tryX)) { throw new ArgumentException(string.Format("{0} is not a valid value for X", setupParts[0]), "setupString"); } if (!int.TryParse(setupParts[1], out tryY)) { throw new ArgumentException(string.Format("{0} is not a valid value for Y", setupParts[1]), "setupString"); } if (tryX < 0 || tryX >= grid.Width || tryY < 0 || tryY >= grid.Height) { throw new ArgumentException(string.Format("The coordinates {0},{1} are outside the grid", setupParts[0], setupParts[1]), "setupString"); } X = tryX; Y = tryY; switch (setupParts[2]) { case "N": Orientation = OrientationEnum.North; break; case "E": Orientation = OrientationEnum.East; break; case "S": Orientation = OrientationEnum.South; break; case "W": Orientation = OrientationEnum.West; break; default: throw new ArgumentException(string.Format("{0} is not a valid value for Orientation", setupParts[2]), "setupString"); } }
public Robot(string setupString, IGrid grid, IRobotCommandMarshaller commandMarshaller) { _commandMarshaller = commandMarshaller; commandMarshaller.SetRobot(this); _grid = grid; string[] setupParts = setupString.Split(' '); if (setupParts.Length != 3) throw new ArgumentException("To set up a robot provide X Y [N|E|S|W] values seperated by spaces\ne.g: 1 1 N"); int tryX = 0, tryY = 0; if (!int.TryParse(setupParts[0], out tryX)) throw new ArgumentException(string.Format("{0} is not a valid value for X", setupParts[0]), "setupString"); if (!int.TryParse(setupParts[1], out tryY)) throw new ArgumentException(string.Format("{0} is not a valid value for Y", setupParts[1]), "setupString"); if (tryX < 0 || tryX >= grid.Width || tryY < 0 || tryY >= grid.Height) throw new ArgumentException(string.Format("The coordinates {0},{1} are outside the grid", setupParts[0], setupParts[1]), "setupString"); X = tryX; Y = tryY; switch(setupParts[2]) { case "N": Orientation = OrientationEnum.North; break; case "E": Orientation = OrientationEnum.East; break; case "S": Orientation = OrientationEnum.South; break; case "W": Orientation = OrientationEnum.West; break; default: throw new ArgumentException(string.Format("{0} is not a valid value for Orientation", setupParts[2]), "setupString"); } }