public override void Tick() { var openCount = ParkingLocations.Count(r => !r.IsFull); if (openCount > 0) { while (InQueue.Count > 0) { var location = FindOpenLocation(); if (location != null) { location.ParkAuto(InQueue.Dequeue()); } else { break; } } } var departing = ParkingLocations.Where(r => r.Occupant != null && r.Occupant.DateToDepart <= Simulator.Clock.Now); foreach (var item in departing) { AutoExitingFrom(item); } base.Tick(); while (OutQueue.Count > 0) { Parent.OutQueue.Enqueue(OutQueue.Dequeue()); } }
public ParkingLocation FindOpenLocation() { var open = ParkingLocations.Where(r => r.Occupant == null); var count = open.Count(); if (count > 0) { var location = Simulator.Random.Next(count - 1); return(open.ToList()[location]); } else { return(null); } }