Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 2
0
 void CleanShit(Shit shit)
 {
     foreach (Guest guest in Zoo.GetZoo().Guests)
     {
         guest.Happiness += shit.ShitStenchFactor;
     }
 }
Exemplo n.º 3
0
 public void PlaceShit(Shit shit)
 {
     lock (shits)
     {
         shits.Add(shit);
     }
     hasShit.Set();
     isWork.Set();
 }
Exemplo n.º 4
0
 public Shit RemoveShit()
 {
     lock (shits)
     {
         int  index = shits.Count - 1;
         Shit shit  = shits[index];
         shits.RemoveAt(index);
         return(shit);
     }
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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;
            }
        }
Exemplo n.º 7
0
Arquivo: Animal.cs Projeto: Geefy/Zoo
 public Animal(string name, int shitHr, Shit shit)
 {
     this.Name   = name;
     this.shitHr = shitHr * 10000;
     this.Shit   = shit;
 }
Exemplo n.º 8
0
 void CleanShit(Shit shit)
 {
     Thread.Sleep(shit.TimeToClean);
 }