Ejemplo n.º 1
0
        public RoadMovementComponent TurnAround()
        {
            var newDirection = Direction.Flip();

            if (Progress.IsZero)
            {
                var newDistance = Road.GetDistanceFor(newDirection);
                return(new RoadMovementComponent(Road, newDistance, newDirection));
            }

            // Math.
            {
                // Don't remove 100d part. It specifies decimal type here.
                var oldDistanceValue      = Road.GetDistanceFor(Direction).Value;
                var oldProgressValue      = Progress.Value;
                var oldProgressPercentage = oldProgressValue * 100d / oldDistanceValue;
                var newProgressPercentage = 100 - oldProgressPercentage;

                var newDistanceValue = Road.GetDistanceFor(newDirection).Value;
                var newProgressValue = newDistanceValue * newProgressPercentage / 100d;
                var newProgress      = new Distance(Round(newProgressValue));

                return(new RoadMovementComponent(Road, newProgress, newDirection));
            }
        }
Ejemplo n.º 2
0
        public RoadMovementComponent Move(Distance progress)
        {
            var newProgress = Progress + progress;
            var distance    = Road.GetDistanceFor(Direction);

            if (newProgress > distance)
            {
                throw new InvalidOperationException("Can't progress beyond distance.");
            }

            return(new RoadMovementComponent(
                       Road, newProgress, Direction));
        }