示例#1
0
 public static void GetDirectionAndStep(int numberOfCommands, Instructions instructions)
 {
     Console.WriteLine($"Movement {numberOfCommands}:");
     for (int i = 0; i < numberOfCommands; i++)
     {
         var movementWithDirections = Console.ReadLine().Split(null);
         if (movementWithDirections.Length > 1)
         {
             var movementStep = new MovementStep
             {
                 Direction     = movementWithDirections[0].ToUpper(),
                 NumberOfSteps = int.Parse(movementWithDirections[1])
             };
             instructions.MovementSteps.Add(movementStep);
         }
     }
 }
示例#2
0
        private void Scroll(MovementStep move)
        {
            switch (move.Direction)
            {
            case "E":
                Coordinates = new Coordinates(Coordinates.X + 1, Coordinates.Y);
                break;

            case "W":
                Coordinates = new Coordinates(Coordinates.X - 1, Coordinates.Y);
                break;

            case "S":
                Coordinates = new Coordinates(Coordinates.X, Coordinates.Y - 1);
                break;

            case "N":
                Coordinates = new Coordinates(Coordinates.X, Coordinates.Y + 1);
                break;
            }
            AddNewCoordinates(Coordinates.ToString());
        }