예제 #1
0
        public void ElevatorStopped(object sender, EventArgs e)
        {
            IElevator            elev = (IElevator)sender;
            ElevStoppedEventArgs args = (ElevStoppedEventArgs)e;


            if (args.StoppedFloor == _sourceFloor && !_isInside && UpDown == elev.HistoryDirection && !_isArrived)
            {
                EnterElevator(args.Scheduler, args.Tick, elev);
            }

            if (args.StoppedFloor == _targetFloor && _isInside && _myElev == elev)
            {
                LeaveElevator(args.Tick, elev);
            }

            if (_isArrived)
            {
                elev.UnregStopHandler(StopAlarmHandler);
            }
            //if (CheckElevatorAndPassenger(this.SourceFloor, args.StoppedElevator))
            //{
            //    this._TargetReqTime = Elevator.SenElevator.SenClock.Ticks;
            //    StudentScheduler.QueueTargetFloor(this);
            //}
            //else
            //{
            //    Console.WriteLine("passenger can't enter into elevator");
            //}

            return;
        }
예제 #2
0
        public void StatusUpdateForEveryTick(int ticks)
        {
            if (_Status.DoorCloseOpenTicks == -1) // not closing or opening
            {
                switch (_Status.CurrentDirection)
                {
                case Direction.Down:
                    _Status.CurrentHeight -= _MaxSpeed;
                    Console.WriteLine("[Elevator]#{0}:{1} D", _id, _Status.CurrentHeight);
                    break;

                case Direction.Up:
                    _Status.CurrentHeight += _MaxSpeed;
                    Console.WriteLine("[Elevator]#{0}:{1} U", _id, _Status.CurrentHeight);
                    break;
                }
            }

            _Status.CurrentFloor = _Status.CurrentHeight / _FloorHeight;

            if (_Status.CurrentHeight == _target * this._FloorHeight || _Status.DoorCloseOpenTicks >= 0)
            {
                ResetDoorCloseOpenTickCountOnce();
                Console.WriteLine("[Elevator]  #{0} stopped at floor {1}, {2} ticks left before door closing",
                                  _id, _Status.CurrentFloor, _Status.DoorCloseOpenTicks);

                EventArgs e = new ElevStoppedEventArgs(_Status.CurrentFloor, ticks, Scheduler);

                _Status.DoorCloseOpenTicks--;
                if (_StopEventHandler != null)
                {
                    _StopEventHandler(this, e);
                }
            }
        }