コード例 #1
0
        //Find an elevator to service a requested floor
        internal void RequestElevator(CallRequest request)
        {
            bool carFound = false;

            lock (UnservicedFloors)
            {
                if (UnservicedFloors.Contains(request))
                {
                    Logger.Output("Duplicate request received for floor " + request.Floor);

                    return;
                }

                foreach (var car in Bank.Cars)
                {
                    if (car.NextStop == null && car.Shaft.CanAccessFloor(request.Floor))
                    {
                        Logger.Output("Car " + car.Designation + " requested to service floor " + request.Floor);

                        car.NextStop = car.Shaft[request.Floor];

                        carFound = true;

                        break;
                    }
                }

                if (carFound == false)
                {
                    Logger.Output("Request to floor " + request.Floor + " cannot be serviced immediately");

                    UnservicedFloors.Add(request);
                }
            }
        }
コード例 #2
0
        //Simulate someone calling an elevator and attempt to service the request
        internal void PressOutsideButton(CallRequest request)
        {
            Logger.Output("Someone pressed the call button on floor " + request.Floor);

            RequestElevator(request);
        }