Example #1
0
        private void MovePeopleInTheLift(Lift lift)
        {
            if (this.PeopleWaitingForLift.Count < 1)
            {
                return;
            }

            // 4th -> 6, 0, 1, 8
            // 6, 8
            var peopleGoingInSameDirection = this.PeopleWaitingForLift.Where(p => p.DirectionToGoIn == lift.LiftDirection).ToList();
            var availableCapacityOfTheLift = lift.GetAvailableCapacity();

            if (availableCapacityOfTheLift < 1)
            {
                return;
            }

            var numberOfPeopleWhoCanGetIn = availableCapacityOfTheLift;

            if (availableCapacityOfTheLift > peopleGoingInSameDirection.Count)
            {
                numberOfPeopleWhoCanGetIn = peopleGoingInSameDirection.Count;
            }
            var peopleWhoCanGetIn = peopleGoingInSameDirection.GetRange(0, numberOfPeopleWhoCanGetIn);

            lift.People.AddRange(peopleWhoCanGetIn);
            peopleWhoCanGetIn.ForEach(person =>
            {
                person.SetOnboard();
                this.PeopleWaitingForLift.Remove(person);
            });
        }
Example #2
0
 public void LiftHasArrived(Lift lift)
 {
     // Getting the people out of Lift who wanted to get to the current floor
     MovePeopleOutOfTheLift(lift);
     // Getting the people in Lift who want to go in the same direction
     MovePeopleInTheLift(lift);
 }
Example #3
0
 public Building(int liftCapacity, int[][] floorAndPeopleComposition)
 {
     this.Floors = floorAndPeopleComposition.Select((floorComposition, floorNumber) => {
         var floor = new Floor(floorNumber, floorComposition);
         floor.ButtonPressedForCallingTheLift += this.LiftRequested;
         return(floor);
     }).ToArray();
     this.Lift = new Lift(liftCapacity, this.Floors.Length - 1);
 }
Example #4
0
        private void MovePeopleOutOfTheLift(Lift lift)
        {
            var peopleForCurrentFloor = lift.OffboardPeople(this.FloorNumber);

            if (peopleForCurrentFloor.Count > 0)
            {
                this.PeopleBelongToTheFloor.AddRange(peopleForCurrentFloor);
                peopleForCurrentFloor.ForEach(person =>
                {
                    person.SetReached();
                });
            }
        }
Example #5
0
        public Building(int liftCapacity, int[][] floorAndPeopleComposition)
        {
            Floors = floorAndPeopleComposition.Select((floorComposition, floorNumber) =>
            {
                var floor = new Floor(floorNumber, floorComposition);
                floor.ButtonPressedForCallingTheLift += this.LiftRequested;
                return(floor);
            }).ToArray();

            Lift = new Lift(liftCapacity);

            Lift.LiftArriverAtAFloor += LiftArrivedAtAFloor;

            Lift.Start();
        }