Example #1
0
        /// <summary>
        /// Walks a user through the robot program,
        /// asks for input and returns results from movement instructions.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.WriteLine("-----------------------------");
            Console.WriteLine("Welcome to The Robot Program!");
            Console.WriteLine("-----------------------------");
            Console.WriteLine("Write q to quit.");

            Parser         parser = new Parser();
            RoomDimensions room   = parser.GetRoom();

            (Point point, char direction) = parser.GetStartingPointAndDirection();
            Robot robot;

            try
            {
                robot = parser.GetRobot(room, point, direction);
            }
            catch (Exception)
            {
                // TODO: Log exceptions
                Console.WriteLine("Terminating...");
                return;
            }
            parser.MoveAccordingToInstructions(robot);
            Console.WriteLine("Goodbye!");
        }
Example #2
0
 /// <summary>
 /// Creates a new instance of a robot with input parameters.
 /// </summary>
 /// <param name="room">The robot room boundaries.</param>
 /// <param name="point">The starting point.</param>
 /// <param name="direction">The direction the robot is facing.</param>
 /// <returns>Robot</returns>
 public Robot GetRobot(RoomDimensions room, Point point, char direction)
 {
     try
     {
         return(new Robot(room, point, direction));
     }
     catch (IllegalStartingPointException)
     {
         // TODO: Log exceptions
         Console.WriteLine("Illegal starting position within room boundaries.");
         throw;
     }
     catch (IllegalDirectionException)
     {
         // TODO: Log exceptions
         Console.WriteLine("Illegal direction when constructing Robot.");
         throw;
     }
     catch (Exception)
     {
         // TODO: Log exceptions
         Console.WriteLine("Something went wrong constructing the Robot.");
         throw;
     }
 }
Example #3
0
        public Robot(RoomDimensions room, Point position, char direction)
        {
            if (!IsValidPositionWithinRoom(room, position))
            {
                throw new IllegalStartingPointException();
            }

            this.room     = room;
            this.position = position;
            Direction     = direction switch
            {
                (Constants.NORTH) => CardinalPoint.N,
                (Constants.EAST) => CardinalPoint.E,
                (Constants.SOUTH) => CardinalPoint.S,
                (Constants.WEST) => CardinalPoint.W,
                _ => throw new IllegalDirectionException(),
            };