public void Update()
        {
            //TODO!
            //operations to be done every virtual minute
            int mCurrentFloor = _mElevatorModuleImpl.GetCurrentFloor();

            if (_mFloorReq.Count > 0)
            {
                //Retrieve the floor from the list of requests - FIFO - First In First Out (BlockingQueue)
                int floor = _mFloorReq.Take();
                //While the current floor is not equal to the destination continue to move towards it
                while (mCurrentFloor != floor)
                {
                    //Retrieve current floor
                    mCurrentFloor = _mElevatorModuleImpl.GetCurrentFloor();

                    //Determine whether lift needs to go up or down
                    if (mCurrentFloor < floor)
                    {
                        _mElevatorModuleImpl.ReqToGoUp();
                    }
                    if (mCurrentFloor > floor)
                    {
                        _mElevatorModuleImpl.ReqToGoDown();
                    }

                    //Process operation
                    _mElevatorModuleImpl.Update();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called over and over again. Updating the world and therefore
        /// it's elements and giving feedback on the state.
        /// </summary>
        public void Update()
        {
            Console.WriteLine("");
            Console.WriteLine("[Minute: " + m_minutesCur + "]");
            int floorNow = m_elevatorModule.GetCurrentFloor();

            Console.WriteLine("Elevator is at floor " + floorNow + ".");

            string info = null;

            //user(s) may enter or leave the elevator
            bool allLeft = true;

            foreach (User user in m_usersAll)
            {
                user.Update(m_minutesCur);
                info = user.GetInfo();
                if (info != null)
                {
                    Console.WriteLine(info);
                }

                if (user.GetState() < User.eState.LEAVING)
                {
                    allLeft = false;
                }
            }

            if (allLeft)
            {
                m_done = true;
                return; //if everyone left no more need to operate!
            }

            //operator system checks where to go to next
            m_elevatorOS.Update();

            //module goes up or down depending on OS input
            m_elevatorModule.Update();
            info = m_elevatorModule.GetInfo();
            if (info != null)
            {
                Console.WriteLine(info);
            }

            m_minutesCur++;
        }