Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public void RotateRight()
 {
     cardinal = cardinal.RotateRight();
 }
Ejemplo n.º 3
0
 public void RotateLeft()
 {
     cardinal = cardinal.RotateLeft();
 }
Ejemplo n.º 4
0
 public void Init(Coordinates coordinates, ICardinal cardinal)
 {
     this.coordinates = coordinates;
     this.cardinal    = cardinal;
 }
Ejemplo n.º 5
0
 public Rover()
 {
     cardinal = new NoCardinal();
 }