예제 #1
0
파일: Rover.cs 프로젝트: hsouth95/MarsRover
        /// <summary>
        /// Rotates the Rover based on the action it is performing
        /// </summary>
        /// <param name="action">The action the Rover is performing</param>
        public void Rotate(Action action)
        {
            if (action != Action.RotateLeft && action != Action.RotateRight)
            {
                throw new ArgumentOutOfRangeException(nameof(action));
            }

            switch (this.Direction)
            {
            case Direction.North:
                this.Direction = action == Action.RotateLeft ? Direction.West : Direction.East;

                break;

            case Direction.East:
                this.Direction = action == Action.RotateLeft ? Direction.North : Direction.South;

                break;

            case Direction.South:
                this.Direction = action == Action.RotateLeft ? Direction.East : Direction.West;

                break;

            case Direction.West:
                this.Direction = action == Action.RotateLeft ? Direction.South : Direction.North;

                break;

            default:
                throw new InvalidOperationException("Invalid direction on Rover");
            }
        }
예제 #2
0
파일: Rover.cs 프로젝트: hsouth95/MarsRover
        /// <inheritdocs />
        public override void Move()
        {
            if (this.Actions == null || this.Actions.Count == 0)
            {
                throw new InvalidOperationException("Rover has no more movements to make");
            }

            Action action = this.Actions.Dequeue();

            if (action == Action.MoveForward)
            {
                this.MoveForward();
            }
            else if (action == Action.RotateLeft || action == Action.RotateRight)
            {
                this.Rotate(action);
            }
            else
            {
                throw new InvalidOperationException("Rover has invalid movement");
            }
        }