Example #1
0
        public override void AgentCycle(YeOldePub yeOldePub)
        {
            while (hasGoneHome is false)
            {
                switch (CheckState(yeOldePub))
                {
                case RunState.Idling:
                    Thread.Sleep(TimeSpentIdling);
                    if (hasBeenProductive is true)
                    {
                        DataManager.RefreshList(this, "Is currently idling");
                    }
                    hasBeenProductive = false;
                    break;

                case RunState.Working:
                    //Gather empty pints from Tables
                    DataManager.RefreshList(this, "Gathering dirty pints from tables");
                    foreach (var pintGlass in yeOldePub.Tables.Where(g => g.HasBeer is false && g.IsClean is false))
                    {
                        PintGlass gatheredPintGlass = null;
                        while (gatheredPintGlass is null)
                        {
                            yeOldePub.Tables.TryTake(out gatheredPintGlass);
                        }
                        tray.Add(gatheredPintGlass);
                    }
                    Thread.Sleep(TimeSpentCollectingPintGlass);

                    //Clean glass and place on Shelves
                    DataManager.RefreshList(this, $"Cleaning {tray.Count} pint(s)");
                    Thread.Sleep(TimeSpentWashingPintGlass);
                    DataManager.RefreshList(this, "Placing clean pints on the shelves");
                    foreach (var pintGlass in tray)
                    {
                        pintGlass.IsClean = true;
                        if (yeOldePub.Shelves.TryAdd(pintGlass))
                        {
                            tray.TryTake(out PintGlass glass);
                        }
                    }
                    hasBeenProductive = true;
                    break;

                case RunState.LeavingThePub:
                    DataManager.RefreshList(this, "Going home");
                    hasGoneHome = true;
                    break;
                }
            }
        }
        public override void AgentCycle(YeOldePub yeOldePub)
        {
            while (hasGoneHome is false)
            {
                switch (CheckState(yeOldePub))
                {
                case RunState.Idling:
                    if (hasBeenProductive is true)
                    {
                        if (yeOldePub.PatronsWaitingForBeer.IsEmpty)
                        {
                            DataManager.RefreshList(this, "Waiting for a patron");
                        }
                        else if (yeOldePub.Shelves.Count is 0)
                        {
                            DataManager.RefreshList(this, "Waiting for clean pints");
                        }
                    }
                    hasBeenProductive = false;
                    Thread.Sleep(100);
                    break;

                case RunState.Working:
                    //Identify patron in first in queue
                    Patron patronBeingServed = null;
                    while (patronBeingServed is null)
                    {
                        yeOldePub.PatronsWaitingForBeer.TryPeek(out patronBeingServed);
                    }
                    if (patronBeingServed.pintGlass is null)
                    {
                        DataManager.RefreshList(this, $"Taking order from {patronBeingServed.Name}");

                        //Get clean glass from Shelves
                        while (pintGlass is null)
                        {
                            yeOldePub.Shelves.TryTake(out pintGlass);
                        }
                        DataManager.RefreshList(this, "Getting a glass from the shelves");
                        Thread.Sleep(TimeSpentGettingGlass);

                        //Fill glass with beer
                        pintGlass.HasBeer = true;
                        pintGlass.IsClean = false;
                        DataManager.RefreshList(this, "Filling glass with beer");
                        Thread.Sleep(TimeSpentFillingGlassWithBeer);

                        //Give glass to customer
                        patronBeingServed.pintGlass = pintGlass;
                        DataManager.RefreshList(this, $"Giving beer to {patronBeingServed.Name}");
                        pintGlass         = null;
                        hasBeenProductive = true;
                    }
                    break;

                case RunState.LeavingThePub:
                    DataManager.RefreshList(this, "Going home");
                    hasGoneHome = true;
                    break;
                }
            }
        }