예제 #1
0
 /// <summary>
 ///  Prompts the user for the starting position of the new rover and the
 ///  direction in which it is facing.
 /// </summary>
 /// <param name="bounds">A <c>Point</c> representing the northeastern boundary of the plateau as entered previously by the user.</param>
 /// <returns>The user's input as a <c>PointWithHead</c> object.</returns>
 public static PointWithHead GetRoverStart(Point bounds)
 {
     while (true)
     {
         Console.WriteLine("Enter the rover's starting coordinates and the direction it is facing. [x y N|E|S|W]: ");
         String        str = Console.ReadLine();
         PointWithHead start;
         if (!PointWithHead.TryParse(str, out start))
         {
             Console.WriteLine("Invalid Entry: Please enter two positive integers separated by a space character, followed by another space character and letter representing a cardinal direction (ex. \"0 0 N\")");
             continue;
         }
         else if (start.x > bounds.x || start.y > bounds.y)
         {
             Console.WriteLine($"Out of Bounds: The rover must begin within the bounds set by the plateau: {bounds}");
             continue;
         }
         return(start);
     }
 }
예제 #2
0
        /// <summary>
        ///  Determines whether the assigned rover can be moved in the direction it is facing, or whether it has hit a boundary.
        /// </summary>
        /// <returns><c>true</c> if the <c>Rover</c> can safely move, <c>false</c> otherwise.</returns>
        private bool CanMoveRover()
        {
            PointWithHead pos = GetRoverPosition();

            if (pos.head == Direction.N && pos.y == bounds.y)
            {
                return(false);
            }
            else if (pos.head == Direction.E && pos.x == bounds.x)
            {
                return(false);
            }
            else if (pos.head == Direction.S && pos.y == 0)
            {
                return(false);
            }
            else if (pos.head == Direction.W && pos.x == 0)
            {
                return(false);
            }
            return(true);
        }
예제 #3
0
 /// <summary>
 ///  Creates a new <c>Rover</c> instance at the given position
 /// </summary>
 /// <param name="position">The starting coordinates and facing direction of the <c>Rover</c></param>
 public Rover(PointWithHead position)
 {
     this.position = position;
 }