Ejemplo n.º 1
0
        public void Run(IMarsMap map, string instructions)
        {
            for (int index = 0; index < instructions.Length; index++)
            {
                if (!IsOutOfMap(map))
                {
                    switch (instructions[index])
                    {
                    case 'M':
                        MoveForward();
                        break;

                    case 'L':
                        TurnLeft();
                        break;

                    case 'R':
                        TurnRight();
                        break;

                    default:
                        Console.WriteLine($"unknown instruction {instructions[index]} at index {index}");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine($"rover falls off the cliff at position ({ShowStatus()}), index {index}");
                    return;
                }
            }
        }
Ejemplo n.º 2
0
 private bool IsOutOfMap(IMarsMap map)
 {
     return(_positionX > map.CoorX || _positionY > map.CoorY || _positionX < 0 || _positionY < 0);
 }
Ejemplo n.º 3
0
 public Scenario(IMarsMap marsMap, IRover rover, string roverInstructions)
 {
     _marsMap           = marsMap;
     _rover             = rover;
     _roverInstructions = roverInstructions;
 }