//Receives new animals from providers public void Receive(IAnimal animal) { lock (_syncObj) { //statistic _receivedAll++; //kill animal if no space for new one if (_animals.Count >= MaxAnimals) { var toKill = _animals.OrderBy(a => a.Age).FirstOrDefault(); if (toKill != null) { toKill.Kill(); _animals.Remove(toKill); } } //add need animal to the ZOO _animals.Add(animal); //if no space ask provider to stop sending new animals if (_animals.Count >= MaxAnimals && Provider != null) Provider.Pause(); } }
private static void Main(string[] args) { var animals = new IAnimal[] {new Monkey(), new Dog()}; foreach (var animal in animals) { DisplayAnimalData(animal); } }
//Processing in humger event of animal. Does feed animal if there is resources (based on random) public void IsInHunger(IAnimal animal) { //emulating feeding animal with some random values var foodProb = _rnd.Next(1, 100); if (foodProb < 96) animal.Eat(foodProb.ToString(CultureInfo.InvariantCulture)); }
private bool AnimalsInRange(IAnimal currentAnimal, IAnimal animal) { bool himself = animal.PositionOnYAxis == currentAnimal.PositionOnYAxis && animal.PositionOnXAxis == currentAnimal.PositionOnXAxis; return animal.PositionOnXAxis >= currentAnimal.PositionOnXAxis - 1 && animal.PositionOnXAxis <= currentAnimal.PositionOnXAxis + 1 && animal.PositionOnYAxis >= currentAnimal.PositionOnYAxis - 1 && animal.PositionOnYAxis <= currentAnimal.PositionOnYAxis + 1 && !himself; }
public void AppendUnique__An_Array_Can_Append_A_Unique_Item() { var animals = new IAnimal[] { _dog }; animals.AppendUnique(ref animals, _dog); Assert.IsTrue(animals.Length == 1); }
private void CalculateCorrectPosition(Board board, List<IAnimal> animals, IAnimal animal) { adderForXPosition = Program.Random.Next(-1, 2); adderForYPosition = Program.Random.Next(-1, 2); while (board.OutOfBounds(adderForXPosition, adderForYPosition, board.Layout, animal) || PlaceIsNotFree(animal, animals) || DidntMove()) { adderForXPosition = Program.Random.Next(-1, 2); adderForYPosition = Program.Random.Next(-1, 2); } }
public void IndexOf__An_Array_Can_Get_The_Index_Of_An_Item() { var animals = new IAnimal[] { _dog, _cat, _fish }; Assert.IsTrue(animals.IndexOf(_fish) == animals.Length - 1); }
public void InsertAfter__An_Array_Can_Insert_An_Item_After() { var animals = new IAnimal[] { _dog, _cat }; animals.InsertAfter(ref animals, _fish, animals.Length - 1); Assert.IsTrue(animals.IndexOf(_fish) == animals.Length - 1); }
public void InsertBefore__An_Array_Can_Insert_An_Item_Before() { var animals = new IAnimal[] { _cat, _fish }; animals.InsertBefore(ref animals, _dog, 0); Assert.IsTrue(animals.IndexOf(_dog) == 0); }
public static void DoSomething(IAnimal animal) { Console.WriteLine(animal.Name); Console.WriteLine(animal.MakeSound()); if (animal is IBird) { Console.WriteLine("Flap Flap Flap"); } }
public void AddAnimal(IAnimal newAnimal, List<IAnimal> animals) { int x; int y; do { x = Program.Random.Next(1, 10); y = Program.Random.Next(1, 10); if (!PositionIsNotFree(x, y, animals).Any()) { AddAnimalToList(newAnimal, x, y, animals); } } while (!PositionIsNotFree(x, y, animals).Any()); }
public void TestMethod1() { var animals = new IAnimal[] { _dog, _cat, _fish }; var c = animals.Contains(_dog); var xStrings = new string[] { "hello", "world" }; var s = xStrings.XHasStringIgnoreCase("HELLO"); }
//react on animal death public void Died(IAnimal animal) { lock (_syncObj) { //removed dead animals from registration book _animals.Remove(animal); //updated counters/statistic book, it is possible to use Interlocked.Increment for that needs //but as we locked syncObj we don't need that _dead++; NumCorpses++; //give more animals if (_animals.Count < MaxAnimals && Provider != null) Provider.Resume(); } }
static void Main(string[] args) { //Create our animal objects but only talk to them by the interface (contract) they signed IAnimal eagle = new Eagle(); IAnimal chicken = new Chicken(); IAnimal bear = new Bear(); //Add our animals to an array the only cares about the interface they implement (the contract or the what) not the //classes that are really implementing the code inside (the how) IAnimal[] animals = new IAnimal[] { eagle, chicken, bear }; //Call the static DoSomething method on AnimalUtility passing in each animal foreach(var animal in animals) { AnimalUtility.DoSomething(animal); } Console.ReadLine(); }
static void Main(string[] args) { IAnimal[] animales = new IAnimal[2]; animales[0] = new Perro(); animales[0].Nombre = "Scooby"; animales[1] = new Gato(); animales[1].Nombre = "Perla"; foreach (IAnimal animal in animales) { Console.WriteLine("Soy {0}", animal.Nombre); animal.Expresarse(); (animal as IMascota).Jugar(); } Console.ReadLine(); }
public Person(IAnimal animal) { this.animal = animal; }
public SomeClass(IAnimal animal) { this.animal = animal; }
public bool Attaquer(IAnimal animal) { return(animal.SeFaireAttaquer()); }
public void Add(IAnimal newAnimal) { ZooList.Add(newAnimal); }
void HandleAnimal(IAnimal anyA, IAnimal anyB) { }
private void SpeakPlease(IAnimal animal) { animal.Speak(); }
public Animal(IAnimal animal) : base(animal) { Name = animal.Name; }
void HandleAnimal(IAnimal any, ICat cat) { }
public Square GetSquare(IAnimal a) { int[] position = a.GetPosition(); return(grid[position[0], position[1]]); }
public Program(IAnimal animal) { Animal = animal; }
public bool AddAnimal(IAnimal animal) { return(_place.AddAnimal(animal)); }
public static void ByGenericParameter <T>() where T : IAnimal { IAnimal animal = svcMgr.Get <T>(); animal.Speak(); }
public static void ByTypeParameter(Type someAnimal) { IAnimal animal = svcMgr.Get <IAnimal>(someAnimal); animal.Speak(); }
public DuckAdapter(IAnimal a) { this.a = a; }
public void Play(IAnimal animal) { //play with the animal Console.WriteLine(String.Format("playing with {0} and it said {1}", animal.Name, animal.Speak())); }
public void Add(IAnimal item) { animals.Add(item); }
public void Groom(IAnimal animal) { var groomer = groomers[animal.GetType()]; groomer.Groom((dynamic)animal); }
void HandleAnimal(ICat cat, IAnimal any) { }
private static void AnimalSays(IAnimal animal) { Console.WriteLine("{0} says {1}", animal.GetType().Name, animal.Says()); }
/// <summary> /// Reproduction Method for checking the reproductivity of the Snake /// </summary> /// <param name="animal"></param> /// <returns></returns> public string Reproduction(IAnimal animal) => $"{Name} is a {typeof(Snake).Name} and reproductive with {animal.Name}";
private void MoveToAntilopesPosition(IAnimal antilopeInRange, Lion lion) { lion.PositionOnXAxis = antilopeInRange.PositionOnXAxis; lion.PositionOnYAxis = antilopeInRange.PositionOnYAxis; }
//TEST 2 public void MakeNoise(IAnimal animal) { //Test 2 : Modify this method to make the animals talk animal.Talk(); }
public bool OutOfBounds(int x, int y, char[,] boardLayout, IAnimal animal) { return (animal.PositionOnXAxis + x >= boardLayout.GetLength(0)) || (animal.PositionOnXAxis + x < 0) || (animal.PositionOnYAxis + y >= boardLayout.GetLength(1)) || (animal.PositionOnYAxis + y < 0); }
public virtual void DoService(IAnimal animal, int procedureTime) { }
private static bool IsLion(IAnimal animal) { return animal.Name == "Lion"; }
protected void AddAnimalProcedure(IAnimal animal) { this.procedureHistory.Add(animal); }
public override void DoService(IAnimal animal, int procedureTime) { base.DoService(animal, procedureTime); }
public int Exit(IAnimal exitingAnimal) { _animalsOnSquare.Add(exitingAnimal); }
public AppRunner(IAnimal animal, IVehicle vehicle) { _animal = animal; _vehicle = vehicle; }
public void Discribe(IAnimal animal) { Console.WriteLine(animal.GetType().Name + " is " + typeof(IAnimal).Name); }
public void AddAnimal(IAnimal animal) { Animals.Add(animal); }
private bool IsNotFree(int x, int y, IAnimal animal, Antilope antilope) { return antilope.PositionOnXAxis + x == animal.PositionOnXAxis && antilope.PositionOnYAxis + y == animal.PositionOnYAxis; }
public void Lockup(IAnimal animal) { Animals.Add(animal); }
private static void DisplayAnimalData(IAnimal animal) { Console.WriteLine("Animal has {0} legs and makes this sound: {1}", animal.NumberOfLegs); animal.Vocalize(); }
public void Attach(IAnimal animal) { animals.Add(animal); }
private void Eat(IAnimal antilope, Lion lion) { MoveToAntilopesPosition(antilope, lion); lion.HitPoints = 100; antilope.HitPoints = 0; }
public void Detach(IAnimal animal) { animals.Remove(animal); }
public void Say(IAnimal obj) { Console.WriteLine("IAnimal Method"); Console.WriteLine(obj.GetType().Name); }
public Dog(IAnimal friend) : this() { Interlocked.Increment(ref CtorIAnimal); Friend = friend; }
private void PlaceAnimalOnBoard(IAnimal animal, char animalSignature) { Layout[animal.PositionOnYAxis, animal.PositionOnXAxis] = animalSignature; }
public AnimalController(IIndex <string, IAnimal> serviceIndexes) { _serviceIndexes = serviceIndexes; _animal = serviceIndexes["dog"]; }
static void MoveAnimal(IAnimal animal) { animal.Move(); }
public abstract void DoService(IAnimal animal, int procedureTime);
public IAnimal GetClone(IAnimal animalSample) { return (IAnimal) animalSample.Clone (); }
void MoveAnimal(IAnimal animal) { animal.Move(); }