public Glass TakeGlassFromBarTop() { Glass glass = barTop.ElementAt(0); barTop = new ConcurrentBag <Glass>(barTop.Except(new[] { glass })); return(glass); }
public void Work() { while (!LeftPub) { SetState(); switch (currentState) { case State.AwaitingPatron: WaitForPatron(); break; case State.AwaitingGlass: WaitForGlass(); break; case State.FetchingGlass: FetchGlass(); break; case State.PouringBeer: PourBeer(); carriedGlass = null; currentPatron = null; break; case State.LeavingWork: CleanBarAndLeaveWork(); break; } } }
void FillShelf(Establishment establishment) { for (int i = 0; i < establishment.MaxGlasses; i++) { var glass = new Glass(); glass.CurrentState = Glass.State.Clean; shelf.Add(glass); } }
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; } } } }
private void LeavePub(ConcurrentDictionary <int, Patron> allPatrons, ConcurrentQueue <Chair> availableChairs, ConcurrentBag <Glass> glassesOnTables) { if (chairUsed != null) { availableChairs.Enqueue(chairUsed); } uiUpdater.UpdateChairLabel(availableChairs.Count()); chairUsed = null; glassesOnTables.Add(carriedBeer); carriedBeer = null; LogStatus($"{name} leaves the pub", this); allPatrons.TryRemove(patronID, out _); uiUpdater.UpdatePatronLabel(allPatrons.Count()); LeftPub = true; }
private void PourBeer(Glass beerToServe, Patron patron) { Thread.Sleep(pourBeer / Pub.GlobalSpeedModifer); LogHandler.UpdateLog($" poured {patron.Name} a beer.", LogHandler.MainWindow.BartenderLog); beerToServe.HasBeer = true; }
public void PutGlassOnTable(Glass glass) { glassesOnTable.Add(glass); }
public void AddUsedGlass(Glass glass) { usedGlasses.Add(glass); }
public void AddAvailableGlass(Glass glass) { availableGlasses.Add(glass); }
public void SetBeer(Glass beer) { carriedBeer = beer; }
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; } } } }
public void AddGlassToBarTop(Glass glass) { barTop.Add(glass); }
public void AddGlassToShelf(Glass glass) { shelf.Add(glass); }