示例#1
0
 public RobotJoe(object locking, Hopper fillinghopper, Hopper flavorhopper, Hopper toppinghopper, ManualResetEvent hopperevent, ManualResetEvent lucyevent)
 {
     this.fillinghopper = fillinghopper;
     this.flavorhopper  = flavorhopper;
     this.toppinghopper = toppinghopper;
     this.locking       = locking;
     this.hopperevent   = hopperevent;
     this.lucyevent     = lucyevent;
 }
示例#2
0
        public void FillHoppers(Hopper hopperFilling, Hopper hopperFlavor, Hopper hopperTopping)
        {
            while (isWorking)
            {
                this.FillHopper(hopperFilling, 250);

                this.FillHopper(hopperFlavor, 20);

                this.FillHopper(hopperFilling, 70);

                this.FillHopper(hopperTopping, 130);
            }
        }
示例#3
0
        public void FillHopper(Hopper hopper, int amount)
        {
            if (hopper.Content <= (2000 - amount))
            {
                int iterations = amount / 10;

                for (int i = 0; i < iterations; i++)
                {
                    hopper.Content += 10;
                    Spin.Wait(1);
                }
            }
        }
示例#4
0
 public void FillHopper(Hopper hopper)
 {
     lock (locking)
     {
         if (hopper.Body >= 1000)
         {
             hopper.Needfilling = false;
             return;
         }
         hopper.Body = hopper.Body + 100;
     }
     Thread.Sleep(10);
     Console.WriteLine("filled one");
 }
示例#5
0
        public void Dispensing(bool isDispensing,
                               Hopper hopperFilling, Hopper hopperFlavor, Hopper hopperTopping,
                               ConcurrentBag <Crust> crusts, AutoResetEvent stopLucy, AutoResetEvent waitLucy)
        {
            while (isWorking)
            {
                stopLucy.WaitOne();
                isDispensing = true;



                while (!this.EnoughForDispensing(hopperFilling, 250))
                {
                    Spin.Wait(1);
                }
                this.AddFilling(crusts.ElementAt(Crust.numberOfPies - 1), hopperFilling);
                Console.WriteLine("Filling was added successfully.");


                while (!this.EnoughForDispensing(hopperFlavor, 10))
                {
                    Spin.Wait(1);
                }
                this.AddFlavour(crusts.ElementAt(Crust.numberOfPies - 1), hopperFlavor);

                Console.WriteLine("Flavor was added successfully.");


                while (!this.EnoughForDispensing(hopperTopping, 100))
                {
                    Spin.Wait(1);
                }
                this.AddTopping(crusts.ElementAt(Crust.numberOfPies - 1), hopperTopping);

                Console.WriteLine("Topping was added successfully.");

                isDispensing = false;
                waitLucy.Set();
            }
        }
示例#6
0
 public bool EnoughForDispensing(Hopper hopper, int quantity)
 {
     return((hopper.Content >= quantity) ? true : false);
 }
示例#7
0
 public void AddTopping(Crust crust, Hopper hopper)
 {
     crust.Topping   = 100;
     hopper.Content -= 100;
     Spinning();
 }
示例#8
0
 public void AddFlavour(Crust crust, Hopper hopper)
 {
     crust.Flavor    = 10;
     hopper.Content -= 10;
     Spinning( );
 }
示例#9
0
 public void AddFilling(Crust crust, Hopper hopper)
 {
     crust.Filling   = 250;
     hopper.Content -= 250;
     Spinning();
 }
示例#10
0
        static void Main(string[] args)
        {
            Hopper hopperFilling = new Hopper();
            Hopper hopperFlavor  = new Hopper();
            Hopper hopperTopping = new Hopper();

            Joe  joe  = new Joe();
            Lucy lucy = new Lucy();

            AutoResetEvent stopLucy = new AutoResetEvent(false);
            AutoResetEvent waitLucy = new AutoResetEvent(false);

            ConcurrentBag <Crust> crusts = new ConcurrentBag <Crust>();

            bool isDispensing          = false;
            bool stopFactory           = false;
            bool isStoppedSuccessfully = false;

            string startingTheFactory = "START WORKING";

            Console.WriteLine("Press \"ENTER\" to start the factory and press \"ESCAPE\" to stop it.");

            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Enter))
            {
                ;
            }

            for (int i = 0; i < 5; i++)
            {
                Console.SetCursorPosition(0, 1);
                startingTheFactory += '.';
                Console.WriteLine(startingTheFactory);
                Spin.Wait(450);
            }
            Console.WriteLine();

            void ConveyorBelt()
            {
                Conveyor.Belt(isDispensing,
                              crusts, stopLucy, waitLucy);
            }

            void WorkingLucy()
            {
                lucy.Dispensing(isDispensing,
                                hopperFilling, hopperFlavor, hopperTopping, crusts, stopLucy, waitLucy);
            }

            void WorkingJoe()
            {
                joe.FillHoppers(hopperFilling, hopperFlavor, hopperTopping);
            }

            Thread Belt = new Thread(new ThreadStart(ConveyorBelt));

            Thread RobotLucy = new Thread(new ThreadStart(WorkingLucy));

            Thread RobotJoe = new Thread(new ThreadStart(WorkingJoe));


            RobotJoe.Start();
            Belt.Start();
            RobotLucy.Start();

            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                ;
            }
            Joe.isWorking        = false;
            Conveyor.stopFactory = true;
            do
            {
                if (Conveyor.isStopped)
                {
                    isStoppedSuccessfully = true;
                    Console.WriteLine("Pie factory stopped working successfully!");
                }
            } while (!isStoppedSuccessfully);
        }