コード例 #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Lane" /> class.
        ///     Precondition: maxNumVehicles greater than/= 0; originalSpeed greater than/= 0, laneLength greater than 0
        ///     Postcondition: LaneManager properties initialized
        /// </summary>
        /// <param name="maxNumVehicles">The maximum number of vehicles.</param>
        /// <param name="vehicleType">Type of the vehicle.</param>
        /// <param name="originalSpeed">The originalSpeed.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="laneLength">Width of the window.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     maxNumVehicles - maxNumVehicles must be >= 0
        ///     or
        ///     originalSpeed - originalSpeed must be > 0
        ///     or
        ///     laneLength - laneLength must be > 0
        /// </exception>
        public Lane(int maxNumVehicles, VehicleTypes vehicleType, double originalSpeed, VehicleDirections direction,
                    double laneLength)
        {
            if (maxNumVehicles < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxNumVehicles), "maxNumVehicles must be >= 0");
            }

            if (originalSpeed < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(originalSpeed), "originalSpeed must be > 0");
            }

            if (laneLength <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(laneLength), "laneLength must be > 0");
            }

            this.maxNumVehicles = maxNumVehicles;
            this.vehicleType    = vehicleType;
            this.originalSpeed  = originalSpeed;
            this.Direction      = direction;
            this.laneLength     = laneLength;

            this.addVehiclesToRoad(direction);
        }
コード例 #2
0
        private void addVehiclesToRoad(VehicleDirections direction)
        {
            for (var i = 0; i < this.maxNumVehicles; i++)
            {
                this.vehicles.Add(new Vehicle(this.vehicleType, direction, this.originalSpeed));
                var vehicle = this.vehicles[i];
                vehicle.X = this.laneLength / this.maxNumVehicles * i - vehicle.Width;

                if (direction == VehicleDirections.Right)
                {
                    vehicle.Sprite.RenderTransformOrigin = new Point(0.5, 0.5);
                    vehicle.Sprite.RenderTransform       = new ScaleTransform {
                        ScaleX = -1
                    };
                }
            }

            this.ResetVehicleVisibility();
        }