コード例 #1
0
 private void GuestLeaves(Puben pub, PubSettings userPubSettings)
 {
     pub.dirtyGlasses.itemCollection.Add(pub.dirtyGlass);
     LogText?.Invoke($"{Name} leaves the bar", this);
     pub.chairs.itemBag.Add(pub.chair);
     pub.guestsInPub--;
 }
コード例 #2
0
 public void BouncerActions(Action <string, object> logText, Puben pub, PubSettings userPubSettings)
 {
     while (true)
     {
         while (userPubSettings.IsBusWithGuestsComing is true)
         {
             if (userPubSettings.OpenCountdown < 100)
             {
                 userPubSettings.NumberOfEnteringGuests = 15;
                 CreateGuest(logText, pub, userPubSettings);
                 userPubSettings.IsBusWithGuestsComing  = false;
                 userPubSettings.NumberOfEnteringGuests = 1;
             }
             else if (userPubSettings.OpenCountdown > userPubSettings.BouncerMaxNewGuestTimer)
             {
                 TimeToWait(pub.random.Next(userPubSettings.BouncerMinNewGuestTimer, userPubSettings.BouncerMaxNewGuestTimer), userPubSettings.PubSimulationSpeed);
                 CreateGuest(logText, pub, userPubSettings);
             }
         }
         if (userPubSettings.OpenCountdown > userPubSettings.BouncerMaxNewGuestTimer)
         {
             TimeToWait(pub.random.Next(userPubSettings.BouncerMinNewGuestTimer, userPubSettings.BouncerMaxNewGuestTimer), userPubSettings.PubSimulationSpeed);
             CreateGuest(logText, pub, userPubSettings);
         }
         else if (userPubSettings.OpenCountdown == 0)
         {
             logText("Bouncern goes home", this);
             break;
         }
     }
 }
コード例 #3
0
 private void GuestEnter(Puben pub, PubSettings userPubSettings)
 {
     pub.guestsInPub++;
     LogText?.Invoke($"{Name} enters BaBar, and goes to the bar", this);
     TimeToWait(userPubSettings.GuestWalkToBar, userPubSettings.PubSimulationSpeed);
     pub.QueueAtBar.Add(this);
 }
コード例 #4
0
 public void CreatePub(PubSettings userPubSettings)
 {
     chairs             = new ItemsBag <Chair>();
     cleanGlasses       = new ItemsBag <CleanGlass>();
     dirtyGlasses       = new ItemsCollection <DirtyGlass>();
     trayOfDirtyGlasses = new ItemsBag <GlassOnTray>();
     chairs.CreateBagOfItems(new Chair(), userPubSettings.NumOfChairs);
     cleanGlasses.CreateBagOfItems(new CleanGlass(), userPubSettings.NumOfGlasses);
 }
コード例 #5
0
 public void CreateGuest(Action <string, object> logText, Puben pub, PubSettings pubset)
 {
     for (int i = 0; i < pubset.NumberOfEnteringGuests; i++)
     {
         Task.Run(() =>
         {
             Guest guest = new Guest(pub);
             guest.GuestActions(logText, pub, pubset);
             Thread.Sleep(10);
         });
     }
 }
コード例 #6
0
        public void GuestActions(Action <string, object> logText, Puben pub, PubSettings userPubSettings)
        {
            LogText = logText;

            GuestEnter(pub, userPubSettings);
            while (!pub.QueueToChair.Contains(this))
            {
                Thread.Sleep(100);
            }
            GuestLookingForChair(pub, userPubSettings);
            while (pub.chairs.itemBag.Count == 0)
            {
                Thread.Sleep(100);
            }
            GuestDrinks(pub, userPubSettings);
            GuestLeaves(pub, userPubSettings);
        }
コード例 #7
0
 private void GuestDrinks(Puben pub, PubSettings userPubSettings)
 {
     pub.chairs.itemBag.TryTake(out pub.chair);
     LogText?.Invoke($"{Name} sits down and drinks the beer", this);
     TimeToWait(pub.random.Next(userPubSettings.GuestDrinkBeerMinTime, userPubSettings.GuestDrinkBeerMaxTime), userPubSettings.PubSimulationSpeed);
 }
コード例 #8
0
 private void GuestLookingForChair(Puben pub, PubSettings userPubSettings)
 {
     LogText?.Invoke($"{Name} takes the beer and looks for a chair", this);
     TimeToWait(userPubSettings.GuestWalkToChair, userPubSettings.PubSimulationSpeed);
 }
コード例 #9
0
ファイル: Waiter.cs プロジェクト: J0hananderss0n/PubLab6
 public void WaiterActions(Action <string, object> printWaiterListBox, Puben pub, PubSettings userPubSettings)
 {
     while (userPubSettings.OpenCountdown > 0 || pub.dirtyGlasses.itemCollection.Count > 0 || pub.guestsInPub > 0 || pub.trayOfDirtyGlasses.itemBag.Count > 0)
     {
         if (pub.dirtyGlasses.itemCollection.Count == 0)
         {
             printWaiterListBox("Waiting for glasses to clean", this);
             while (pub.dirtyGlasses.itemCollection.Count == 0)
             {
                 Thread.Sleep(100);
             }
         }
         if (pub.dirtyGlasses.itemCollection.Count > 0)
         {
             printWaiterListBox("Picking up dirty glasses", this);
             TimeToWait(userPubSettings.WaiterPickUpGlassesTime, userPubSettings.PubSimulationSpeed);
             foreach (var dirtyGlass in pub.dirtyGlasses.itemCollection)
             {
                 pub.trayOfDirtyGlasses.itemBag.Add(new GlassOnTray());
                 pub.dirtyGlasses.itemCollection.Take();
             }
             printWaiterListBox("Cleaning glasses", this);
             TimeToWait(userPubSettings.WaiterCleanGlassesTime, userPubSettings.PubSimulationSpeed);
             foreach (var glassOnTrayOut in pub.trayOfDirtyGlasses.itemBag)
             {
                 pub.cleanGlasses.itemBag.Add(new CleanGlass());
                 pub.trayOfDirtyGlasses.itemBag.TryTake(out pub.glassOnTray);
             }
             printWaiterListBox("Putting glasses on shelf", this);
         }
     }
     printWaiterListBox("Waiter goes home", this);
     userPubSettings.PubOpenButton = true;
 }
コード例 #10
0
        public void BartenderActions(Action <string, object> printBartenderListBox, Puben pub, PubSettings userPubSettings)
        {
            while (userPubSettings.OpenCountdown > 0 || pub.guestsInPub > 0)
            {
                if (pub.guestsInPub == 0 && userPubSettings.OpenCountdown > 0)
                {
                    printBartenderListBox("Bartender waiting for guest", this);
                    while (pub.guestsInPub == 0 && userPubSettings.OpenCountdown > 0)
                    {
                        Thread.Sleep(100);
                    }
                }
                if (pub.QueueAtBar.Count > 0)
                {
                    printBartenderListBox("Bartender goes to shelf", this);
                    while (pub.cleanGlasses.itemBag.Count == 0)
                    {
                        Thread.Sleep(100);
                    }

                    if (pub.cleanGlasses.itemBag.Count > 0)
                    {
                        TimeToWait(userPubSettings.BartenderFetchGlassTime, userPubSettings.PubSimulationSpeed);
                        pub.cleanGlasses.itemBag.TryTake(out pub.cleanGlass);
                        printBartenderListBox("Pours beer to " + pub.QueueAtBar.First().Name, this);
                        TimeToWait(userPubSettings.BartenderPourBeerTime, userPubSettings.PubSimulationSpeed);
                        pub.QueueToChair.Add(pub.QueueAtBar.First());
                        pub.QueueAtBar.Take();
                    }
                }
                if (pub.QueueAtBar.Count == 0 && userPubSettings.OpenCountdown == 0)
                {
                    printBartenderListBox("Bartender goes home", this);
                    break;
                }
            }
        }