private void runner()
        {
            while (!finished)
            {
                if (nextFloor != floor)
                {
                    inQueue = !inElevator;
                    lifter.callElevator(floor);
                }
                else
                {
                    inQueue = false;
                    if (nextFloor == 0)
                    {
                        finished    = true;
                        waitOnFloor = 1;
                    }
                    else
                    {
                        while (nextFloor == floor)
                        {
                            nextFloor = getRandomNumber(0, maxFloor + 1);
                        }
                        if (floor - nextFloor > 0)
                        {
                            direction = Direction.Down;
                        }
                        else
                        {
                            direction = Direction.Up;
                        }
                        waitOnFloor = getRandomNumber(10000, 120000);
                    }
                    Thread.Sleep(waitOnFloor);
                }

                Thread.Sleep(10);
            }
        }
Exemplo n.º 2
0
        private void update()
        {
            while (!stop)
            {
                if (peopleCounter < maxPeople && getRandomNumber(0, 101) > 97)
                {
                    floor0List.Add(new Person(maxFloor, ++peopleCounter, lifter, parentForm));
                }

                if (!lifter.doorClosed)
                {
                    switch (lifter.floor)
                    {
                    case 0:
                        if (lifter.lifterList.Count > 0)
                        {
                            for (int i = lifter.lifterList.Count - 1; i >= 0; i--)
                            {
                                if (lifter.lifterList[i].nextFloor == 0)
                                {
                                    Thread.Sleep(400);
                                    lifter.lifterList[i].Reset();
                                    exitList.Add(lifter.lifterList[i]);
                                    parentForm.updateExit(exitList);
                                    lifter.lifterList.RemoveAt(i);
                                    parentForm.updateElevator(lifter.lifterList);
                                    lifter.callElevator(lifter.floor);
                                }
                            }
                        }
                        for (int i = floor0List.Count - 1; i >= 0; i--)
                        {
                            if (lifter.lifterList.Count < elevatorCapacity)
                            {
                                Thread.Sleep(400);
                                floor0List[i].setFloor(lifter.floor, true);
                                lifter.addPerson(floor0List[i]);
                                parentForm.updateElevator(lifter.lifterList);
                                floor0List.RemoveAt(i);
                                parentForm.updateFloors(floor0List, 0);
                            }
                        }
                        lifter.doorClosed = true;
                        break;

                    case 1: floor1List = updateUI(floor1List, false); break;

                    case 2: floor2List = updateUI(floor2List, false); break;

                    case 3: floor3List = updateUI(floor3List, false); break;

                    case 4: floor4List = updateUI(floor4List, false); break;

                    case 5: floor5List = updateUI(floor5List, false); break;

                    case 6: floor6List = updateUI(floor6List, true); break;

                    default: break;
                    }
                }

                parentForm.updateExit(exitList);
                parentForm.updateElevator(lifter.lifterList);
                parentForm.updateFloors(floor0List, 0);
                parentForm.updateFloors(floor1List, 1);
                parentForm.updateFloors(floor2List, 2);
                parentForm.updateFloors(floor3List, 3);
                parentForm.updateFloors(floor4List, 4);
                parentForm.updateFloors(floor5List, 5);
                parentForm.updateFloors(floor6List, 6);
                Thread.Sleep(100);
            }
        }