Exemple #1
0
        public override void AgentCycle(Bar bar)
        {
            var       busCheck = 0;
            Stopwatch timer    = new Stopwatch();

            timer.Start();
            while (hasGoneHome is false)
            {
                switch (CheckState(bar))
                {
                case RunState.Working:
                {
                    if (Bar.IsBussLoad)
                    {
                        bouncerSpeed = 500;

                        while (busCheck == 0)
                        {
                            if (timer.ElapsedMilliseconds >= 20000)
                            {
                                busCheck++;
                                for (int i = 0; i <= 10; i++)
                                {
                                    var newPatron = new Patron(bar);
                                    bar.patronsQueue.TryAdd(newPatron.Name, newPatron);
                                }
                                timer.Stop();
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (Bar.IsCouplesNight)
                    {
                        NumberOfPatronToLetInside = 2;
                    }

                    Thread.Sleep(TimeBetweenLettingPatronIn(bouncerSpeed));
                    for (int patron = 0; patron < NumberOfPatronToLetInside; patron++)
                    {
                        var newPatron = new Patron(bar);
                        bar.patronsQueue.TryAdd(newPatron.Name, newPatron);
                    }
                    break;
                }

                case RunState.LeavingThePub:
                {
                    BarController.EventListBoxHandler(this, "Bouncer is going home");
                    hasGoneHome = true;
                    break;
                }
                }
            }
        }
Exemple #2
0
 public MainWindow()
 {
     InitializeComponent();
     barController = new BarController(this);
     NumberOfGlasOnShelfLabel.Content  = "-";
     NumberOfPatronsInBarLabel.Content = "-";
     NumberOfVacantSeatsLabel.Content  = "-";
     TimeUntillClosed.Content          = "-";
 }
Exemple #3
0
        public override void AgentCycle(Bar bar)
        {
            while (hasGoneHome is false)
            {
                switch (CheckState(bar))
                {
                case RunState.Idling:
                {
                    Thread.Sleep(TimeSpentIdling);
                    if (hasBeenProductive is true)
                    {
                        BarController.EventListBoxHandler(this, "Is currently idling");
                    }
                    hasBeenProductive = false;
                    break;
                }

                case RunState.Working:
                {
                    BarController.EventListBoxHandler(this, "Collecting dirty glasses from tables");
                    foreach (var glass in bar.glassesOnTables.Where(g => g.HasBeer is false && g.IsClean is false))
                    {
                        Glass gatheredBeerGlass = null;
                        while (gatheredBeerGlass is null)
                        {
                            bar.glassesOnTables.TryTake(out gatheredBeerGlass);
                        }
                        tray.Add(gatheredBeerGlass);
                    }
                    Thread.Sleep(TimeSpentCollectingBeerGlass);

                    //Clean glass and place on Shelves
                    BarController.EventListBoxHandler(this, $"Cleaning {tray.Count} glasses");
                    Thread.Sleep(TimeSpentWashingBeerGlass);
                    BarController.EventListBoxHandler(this, "Placing clean glasses on the shelves");
                    foreach (var collectedGlass in tray)
                    {
                        collectedGlass.IsClean = true;
                        if (bar.shelfForGlasses.TryAdd(collectedGlass))
                        {
                            tray.TryTake(out Glass glass);
                        }
                    }
                    hasBeenProductive = true;
                    break;
                }

                case RunState.LeavingThePub:
                {
                    BarController.EventListBoxHandler(this, "Waitress is going home");
                    hasGoneHome = true;
                    break;
                }
                }
            }
        }
Exemple #4
0
 public Bar(BarController barController)
 {
     BarController   = barController;
     currentBarState = BarState.Open;
     GenerateGlasses();
     GenerateChairs();
     Bartender = new Bartender(this);
     Bouncer   = new Bouncer(this);
     Waitress  = new Waitress(this);
 }
Exemple #5
0
        public override void AgentCycle(Bar bar)
        {
            while (hasGoneHome is false)
            {
                TimeDrinkingBeer(TimeSpentDrinkingBeer);
                switch (CurrentState)
                {
                case RunState.WalkingToBar:
                {
                    BarController.EventListBoxHandler(this, $"{Name} entered and is walking to the bar");
                    bar.PatronsWaitingForBeer.Enqueue(this);
                    CurrentQueue = bar.PatronsWaitingForBeer;
                    Thread.Sleep(1000);
                    CurrentState = RunState.WaitingForBeer;
                    break;
                }

                case RunState.WaitingForBeer:
                {
                    BarController.EventListBoxHandler(this, $"{Name} is waiting for a glass of beer");
                    while (glass is null)
                    {
                        Thread.Sleep(TimeSpentWaiting);
                    }
                    BarController.EventListBoxHandler(this, $"{Name} got a glass of beer");
                    DequeuePatron(CurrentQueue, this);
                    CurrentState = RunState.WaitingForChair;
                    break;
                }

                case RunState.WaitingForChair:
                {
                    bar.PatronsWaitingForChair.Enqueue(this);
                    CurrentQueue = bar.PatronsWaitingForChair;
                    BarController.EventListBoxHandler(this, $"{Name} is waiting for an available chair");

                    var isFirstInQueue = false;
                    while (isFirstInQueue is false)
                    {
                        Thread.Sleep(TimeSpentWaiting);
                        bar.PatronsWaitingForChair.TryPeek(out var firstPatronInQueue);
                        if (this.Equals(firstPatronInQueue))
                        {
                            isFirstInQueue = true;
                            while (chair is null)
                            {
                                foreach (var chair in bar.availableChairs)
                                {
                                    if (!(chair.IsAvailable))
                                    {
                                        continue;
                                    }
                                    this.chair        = chair;
                                    chair.IsAvailable = false;
                                    DequeuePatron(CurrentQueue, this);
                                    BarController.RefreshLabels();
                                    break;
                                }
                            }
                        }
                    }
                    CurrentState = RunState.WalkingToChair;
                    break;
                }

                case RunState.WalkingToChair:
                {
                    BarController.EventListBoxHandler(this, $"{Name} is walking to a chair");
                    Thread.Sleep(TimeSpentWalkingToChair);
                    CurrentState = RunState.DrinkingBeer;
                    break;
                }

                case RunState.DrinkingBeer:
                {
                    BarController.EventListBoxHandler(this, $"{Name} is drinking the beer");
                    Thread.Sleep(TimeSpentDrinkingBeer);
                    glass.HasBeer = false;

                    bar.glassesOnTables.Add(glass);
                    chair.IsAvailable = true;
                    CurrentState      = RunState.LeavingThePub;
                    break;
                }

                case RunState.LeavingThePub:
                {
                    BarController.EventListBoxHandler(this, $"{Name} finished the beer and is going home");
                    while (hasGoneHome is false)
                    {
                        hasGoneHome = bar.patronsQueue.TryRemove(Name, out _);
                    }
                    hasGoneHome = true;
                    break;
                }
                }
            }
        }
Exemple #6
0
        public override void AgentCycle(Bar bar)
        {
            while (!hasGoneHome)
            {
                switch (CheckState(bar))
                {
                case RunState.Idling:
                {
                    if (hasBeenProductive)
                    {
                        if (bar.PatronsWaitingForBeer.IsEmpty)
                        {
                            BarController.EventListBoxHandler(this, "Waiting for a patron");
                        }
                        else if (bar.shelfForGlasses.Count is 0)
                        {
                            BarController.EventListBoxHandler(this, "Waiting for clean glasses");
                        }
                    }
                    hasBeenProductive = false;
                    Thread.Sleep(100);
                    break;
                }

                case RunState.Working:
                {
                    Patron patronWaitingToBeServed = null;
                    while (patronWaitingToBeServed is null)
                    {
                        bar.PatronsWaitingForBeer.TryPeek(out patronWaitingToBeServed);
                    }
                    if (patronWaitingToBeServed.glass is null)
                    {
                        BarController.EventListBoxHandler(this, $"Taking order from {patronWaitingToBeServed.Name}");

                        while (glassInBar is null)
                        {
                            bar.shelfForGlasses.TryTake(out glassInBar);
                        }
                        BarController.EventListBoxHandler(this, "Getting a glass from the shelves");
                        Thread.Sleep(TimeSpentGettingGlass);

                        glassInBar.HasBeer = true;
                        glassInBar.IsClean = false;
                        BarController.EventListBoxHandler(this, "Filling glass with beer");
                        Thread.Sleep(TimeSpentFillingGlassWithBeer);

                        patronWaitingToBeServed.glass = glassInBar;
                        BarController.EventListBoxHandler(this, $"Giving beer to {patronWaitingToBeServed.Name}");
                        glassInBar        = null;
                        hasBeenProductive = true;
                    }
                    break;
                }

                case RunState.LeavingThePub:
                {
                    BarController.EventListBoxHandler(this, "Bartender is going home");
                    hasGoneHome = true;
                    break;
                }
                }
            }
        }