Exemple #1
0
        public override void Open()
        {
            while (Zoo.Open)
            {
                Smell();

                for (int i = 0; i < AnimalsInside.Length; i++)
                {
                    lock (_lock)
                    {
                        Shit temp = null;

                        if (AnimalsInside[i].ShitsTakenToday < AnimalsInside[i].AmountOfShitPerDay)
                        {
                            temp = AnimalsInside[i].TakeAShit();
                        }


                        if (temp != null)
                        {
                            Shits.Add(temp);
                        }
                    }

                    //Console.WriteLine("[ElefantHouse] shits: " + Shits.Count);
                }
            }
        }
Exemple #2
0
 void CleanShit(Shit shit)
 {
     foreach (Guest guest in Zoo.GetZoo().Guests)
     {
         guest.Happiness += shit.ShitStenchFactor;
     }
 }
Exemple #3
0
 public void PlaceShit(Shit shit)
 {
     lock (shits)
     {
         shits.Add(shit);
     }
     hasShit.Set();
     isWork.Set();
 }
Exemple #4
0
 public Shit RemoveShit()
 {
     lock (shits)
     {
         int  index = shits.Count - 1;
         Shit shit  = shits[index];
         shits.RemoveAt(index);
         return(shit);
     }
 }
Exemple #5
0
 public void Work(float timeWarp)
 {
     EventWaitHandle[] handles = new EventWaitHandle[workPlace.Animals.Count];
     for (int i = 0; i < handles.Length; i++)
     {
         handles[i] = workPlace.Animals[i].isWork;
     }
     while (true)
     {
         int  workIndex = WaitHandle.WaitAny(handles);
         Shit shit      = workPlace.Animals[workIndex].RemoveShit();
         Thread.Sleep((int)(shit.SecondsToClean * timeWarp));
     }
 }
Exemple #6
0
        public void CleanPlace(PlaceForAnimal place)
        {
            Shit shit = null;

            if (place.Shits.Count != 0)
            {
                shit = place.Shits[new Random().Next(0, place.Shits.Count)];
            }

            if (shit != null)
            {
                Busy = true;
                //Console.WriteLine("[ZooKeeper] Cleaning" + place);
                CleanShit(shit);
                place.Shits.Remove(shit);
                Busy = false;
            }
        }
Exemple #7
0
 public Animal(string name, int shitHr, Shit shit)
 {
     this.Name   = name;
     this.shitHr = shitHr * 10000;
     this.Shit   = shit;
 }
Exemple #8
0
 void CleanShit(Shit shit)
 {
     Thread.Sleep(shit.TimeToClean);
 }