예제 #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;
                }
            }
        }
예제 #2
0
 private bool IsOutOfMap(IMarsMap map)
 {
     return(_positionX > map.CoorX || _positionY > map.CoorY || _positionX < 0 || _positionY < 0);
 }
예제 #3
0
 public Scenario(IMarsMap marsMap, IRover rover, string roverInstructions)
 {
     _marsMap           = marsMap;
     _rover             = rover;
     _roverInstructions = roverInstructions;
 }