Пример #1
0
        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);
        }
Пример #2
0
 public DrinkingManagerHelper(DrinkingManager _drinkingManager)
 {
     thread         = new BackgroundWorker();
     tellingManager = _drinkingManager;
     thread.DoWork += Thread_DoWork;
 }
        public CucumberWaitress(DrinkingManager _drinkingManager, int seed) : base(_drinkingManager, seed)
        {

        }
        public BottleWaitress(DrinkingManager _drinkingManager, int seed):base(_drinkingManager,seed)
        {

        }
 public Waitress(DrinkingManager _drinkingManager,int seed)
 {
     drinkingManager = _drinkingManager;
     r = new Random(seed);
     thread.DoWork += Thread_DoWork;
 }
Пример #6
0
 public static void InitDrinkingManager(DrinkingManager dm)
 {
     drinkingManager = dm;
 }