Esempio n. 1
0
        private void HourPassedAnimal()
        {
            for (int i = 0; i < AnimalsInZoo.Count; i++)
            {
                for (int j = 0; j < AnimalsInZoo[i].Count; j++)
                {
                    Animal animal = AnimalsInZoo[i][j];
                    //Math.Ceiling (up) or Math.Floor
                    decimal shitsPerHour    = (animal.ShitsPerDay / 24);
                    int     shitMin         = Convert.ToInt16(Math.Floor(shitsPerHour));
                    int     shitMax         = Convert.ToInt16(Math.Ceiling(shitsPerHour));
                    int     hourlyShitCount = StaticRandom.Rand(shitMin, (shitMax + 1));

                    for (int k = 0; k < hourlyShitCount; k++)
                    {
                        AnimalShit shitTaken = animal.TakeShit();
                        lock (HobedShit)
                        {
                            HobedShit.Push(shitTaken);
                            Monitor.Pulse(HobedShit);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void HourPassedEmployee()
        {
            int elapsedTime = 0;

            while (elapsedTime < oneHour)
            {
                lock (HobedShit)
                {
                    if (HobedShit.Count < 1)
                    {
                        Printer.Print("Hobed shit is empty, Employee is waiting.");
                        Monitor.Wait(HobedShit);
                    }
                    else
                    {
                        HobedShit.OrderBy(i => i.ShitPriority);
                        AnimalShit removedShit  = HobedShit.Peek();
                        int        timeToRemove = Convert.ToInt16(removedShit.TimeToRemoveShit * 100);
                        Printer.Print($"Started removing {removedShit.ShitOwner.Name} shit, taking {removedShit.TimeToRemoveShit} minutes ({timeToRemove} ms) Currently hobed shit[{HobedShit.Count}]");
                        HobedShit.Pop();
                        lock (shitTakenInDay)
                        {
                            shitTakenInDay.Add(removedShit);
                        }

                        Thread.Sleep(timeToRemove);
                        elapsedTime += timeToRemove;
                        Printer.Print($"......Finished removing {removedShit.ShitOwner.Name} shit. Currently hobed shit[{HobedShit.Count}] elapsed time[{elapsedTime}]");
                    }
                }
            }
        }