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