Example #1
0
        public void Turn(RelativeDirections relativeDirection)
        {
            if (!Enum.IsDefined(typeof(RelativeDirections), relativeDirection))
            {
                throw new NotValidException($"Direction is not valid ({relativeDirection.ToString()})", null);
            }

            var compassDirection = relativeDirection switch
            {
                RelativeDirections.Left => (CompassDirections)(((int)Direction + 90) % 360),
                RelativeDirections.Right => (CompassDirections)(((int)Direction + 270) % 360),
                _ => throw new Exception($"Direction is not implemented ({relativeDirection.ToString()})")
            };

            Direction = compassDirection;
        }
Example #2
0
        public void Turn(RelativeDirections direction)
        {
            if (!Enum.IsDefined(typeof(RelativeDirections), direction))
            {
                throw new RelativeDirectionNotValid(direction.ToString());
            }

            CompassDirections compassDirection;

            switch (direction)
            {
            case RelativeDirections.Left:
                compassDirection = (CompassDirections)(((int)Facade + 90) % 360);
                break;

            case RelativeDirections.Right:
                compassDirection = (CompassDirections)(((int)Facade + 270) % 360);
                break;

            default:
                throw new DevelopmentException($"There is uncovered switch-case state [{direction.ToString()}]");
            }

            Facade = compassDirection;
        }