/// <summary> /// Constructor for the TrafficBuilder class. Randomly assigns drivers to cars and places /// them on the road in order of increasing position. /// </summary> /// <param name="road">The road the vehicles are driving on</param> /// <param name="trafficLevel">Number of cars per lane per mile</param> public TrafficBuilder(Road road, int trafficLevel) { PassingPersonality personality; Speed speed; Attitude attitude; Type type; Road = road; int drivingLane = 0; int nextAvailablePosition = 0; int totalVehicles = trafficLevel * road.GetLanes() * 2; //in this case we're creating 2 miles' worth of cars for (int i = 0; i < totalVehicles; i++) //create new vehicle { personality = PersonalityAssigner.AssignPersonality(); speed = SpeedAssigner.AssignSpeed(); attitude = AttitudeAssigner.AssignAttitude(); //assign random vlues type = TypeAssigner.AssignType(); Driver tempDriver = new Driver(personality, speed, attitude); drivingLane = Random.Next(0, 2); //randomly assign spot on the road nextAvailablePosition = NextAvailablePosition(Vehicles, type, drivingLane); Vehicle tempVehicle = new Vehicle(type, drivingLane, Random.Next(nextAvailablePosition, nextAvailablePosition + 150), tempDriver, Road); Vehicles.Add(tempVehicle); } }
private bool CanMergeDirection(Vehicle vehicle, string direction) { switch (direction) { case "Left": { int lane = vehicle.GetLane(); if (lane == 0) { return(false); } return(true); } case "Right": { int lane = vehicle.GetLane(); if (lane == Highway.GetLanes() - 1) { return(false); } return(true); } } return(false); }