public static void TurnLeft(Rover.Land.Domain.Rover rover)
 {
     if (rover.Position.Direction == Direction.N)
     {
         rover.Position.Direction = Direction.W;
     }
     else
     {
         rover.Position.Direction = rover.Position.Direction - 1;
     }
 }
Beispiel #2
0
 public static void TurnRight(Rover.Land.Domain.Rover rover)
 {
     if (rover.Position.Direction == Direction.W)
     {
         rover.Position.Direction = Direction.N;
     }
     else
     {
         rover.Position.Direction = rover.Position.Direction + 1;
     }
 }
Beispiel #3
0
        public static void Move(Rover.Land.Domain.Rover rover, Surface surface)
        {
            int x = rover.Position.Position_X;
            int y = rover.Position.Position_Y;

            switch (rover.Position.Direction)
            {
            case Direction.N:

                if (IsValidMove(surface.Height, y++))
                {
                    rover.Position.Position_Y += 1;
                }
                else
                {
                    new Exception("Position must within Surface");
                }
                break;

            case Direction.S:
                if (IsValidMove(surface.Height, y--))
                {
                    rover.Position.Position_Y -= 1;
                }
                else
                {
                    new Exception("Position must within Surface");
                }
                break;

            case Direction.E:
                if (IsValidMove(surface.Height, x++))
                {
                    rover.Position.Position_X += 1;
                }
                else
                {
                    new Exception("Position must within Surface");
                }
                break;

            case Direction.W:
                if (IsValidMove(surface.Height, x--))
                {
                    rover.Position.Position_X -= 1;
                }
                else
                {
                    new Exception("Position must within Surface");
                }
                break;
            }
        }