private static void Simulate() { Random r = new Random(); int n = Const.n; Table table = new Table(); List <Knight> knights = new List <Knight>(); knights.Add(new King(r.Next(), 0)); for (int i = 1; i < n; i++) { knights.Add(new Knight(r.Next(), i)); } TellingManager tellingManager = new TellingManager(knights); TellingManagerHelper tellingManagerHelper = new TellingManagerHelper(tellingManager); DrinkingManager drinkingManager = new DrinkingManager(table); DrinkingManagerHelper drinkingManagerHelper = new DrinkingManagerHelper(drinkingManager); BottleWaitress bottleWaitress = new BottleWaitress(drinkingManager, r.Next()); CucumberWaitress cucumberWaitress = new CucumberWaitress(drinkingManager, r.Next()); Knight.InitTellingManager(tellingManager); Knight.InitDrinkingManager(drinkingManager); Knight.InitKnightManager(new KnightManager()); tellingManagerHelper.StartThread(); drinkingManagerHelper.StartThread(); bottleWaitress.StartThread(); cucumberWaitress.StartThread(); for (int i = 0; i < n; i++) { knights[i].StartThread(); } Thread.Sleep(1000 * 60 * 10); }
public static void InitTellingManager(TellingManager tm) { tellingManager = tm; }
public TellingManagerHelper(TellingManager _tellingManager) { thread = new BackgroundWorker(); tellingManager = _tellingManager; thread.DoWork += Thread_DoWork; }