/// <summary>
        /// Dispatches commands to be executed.
        /// </summary>
        /// <param name="commandSet">Command set to dispatch.</param>
        public void Dispatch(CommandSet commandSet)
        {
            if (commandSet == null)
            {
                throw new ArgumentNullException(nameof(commandSet));
            }

            this.guidance.Move(commandSet);

            this.listener?.Transmit($"{this.guidance.Coordinates.X} {this.guidance.Coordinates.Y} {InstructionHelper.ConvertHeadingToString(this.guidance.Heading)}");
        }
Пример #2
0
        /// <summary>
        /// Validate the values in the command set object.
        /// </summary>
        /// <param name="commandSet">Command set object to validate.</param>
        private void ValidateCommandSet(CommandSet commandSet)
        {
            if (commandSet.EstablishGrid == null)
            {
                throw new ArgumentException("Establish grid command was null.", nameof(commandSet));
            }

            if (commandSet.EstablishGrid.Grid.Width < 0)
            {
                throw new ArgumentException("Establish grid command x-axis length is invalid.", nameof(commandSet));
            }

            if (commandSet.EstablishGrid.Grid.Height < 0)
            {
                throw new ArgumentException("Establish grid command y-axis length is invalid.", nameof(commandSet));
            }

            if (commandSet.ConfirmPosition == null)
            {
                throw new ArgumentException("Confirm position command was null.", nameof(commandSet));
            }

            if (commandSet.ConfirmPosition.Coordinates.X < 0)
            {
                throw new ArgumentException("Confirm position command x-coordinate value is invalid.", nameof(commandSet));
            }

            if (commandSet.ConfirmPosition.Coordinates.Y < 0)
            {
                throw new ArgumentException("Confirm position command y-coordinate value is invalid.", nameof(commandSet));
            }

            if (commandSet.ConfirmPosition.Coordinates.X > commandSet.EstablishGrid.Grid.Width)
            {
                throw new ArgumentOutOfRangeException("Confirm position command x-coordinate is out of the established grid.", nameof(commandSet));
            }

            if (commandSet.ConfirmPosition.Coordinates.Y > commandSet.EstablishGrid.Grid.Height)
            {
                throw new ArgumentOutOfRangeException("Confirm position command y-coordinate is out of the established grid.", nameof(commandSet));
            }

            if (commandSet.Move == null)
            {
                throw new ArgumentException("Move command was null", nameof(commandSet));
            }
        }
 /// <summary>
 /// Moves the rover.
 /// </summary>
 /// <param name="commandSet">Commands used to move the rover.</param>
 public abstract void Move(CommandSet commandSet);
Пример #4
0
        /// <summary>
        /// Moves the rover.
        /// </summary>
        /// <param name="commandSet">Commands used to move the rover.</param>
        public override void Move(CommandSet commandSet)
        {
            this.ValidateCommandSet(commandSet);

            this.ProcessMoves(commandSet);
        }