Exemple #1
0
        //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();
            }
        }
Exemple #2
0
 private static void Main(string[] args)
 {
     var animals = new IAnimal[] {new Monkey(), new Dog()};
     foreach (var animal in animals)
     {
         DisplayAnimalData(animal);
     }
 }
Exemple #3
0
        //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");
        }
Exemple #13
0
        //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();
            }
        }
Exemple #14
0
        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();
        }
Exemple #15
0
        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();

        }
Exemple #16
0
 public Person(IAnimal animal)
 {
     this.animal = animal;
 }
Exemple #17
0
		public SomeClass(IAnimal animal)
		{
			this.animal = animal;
		}
Exemple #18
0
 public bool Attaquer(IAnimal animal)
 {
     return(animal.SeFaireAttaquer());
 }
Exemple #19
0
 public void Add(IAnimal newAnimal)
 {
     ZooList.Add(newAnimal);
 }
Exemple #20
0
 void HandleAnimal(IAnimal anyA, IAnimal anyB)
 {
 }
 private void SpeakPlease(IAnimal animal)
 {
     animal.Speak();
 }
Exemple #22
0
 public Animal(IAnimal animal)
     : base(animal)
 {
     Name = animal.Name;
 }
Exemple #23
0
 void HandleAnimal(IAnimal any, ICat cat)
 {
 }
Exemple #24
0
        public Square GetSquare(IAnimal a)
        {
            int[] position = a.GetPosition();

            return(grid[position[0], position[1]]);
        }
Exemple #25
0
 public Program(IAnimal animal)
 {
     Animal = animal;
 }
Exemple #26
0
 public bool AddAnimal(IAnimal animal)
 {
     return(_place.AddAnimal(animal));
 }
Exemple #27
0
        public static void ByGenericParameter <T>() where T : IAnimal
        {
            IAnimal animal = svcMgr.Get <T>();

            animal.Speak();
        }
Exemple #28
0
        public static void ByTypeParameter(Type someAnimal)
        {
            IAnimal animal = svcMgr.Get <IAnimal>(someAnimal);

            animal.Speak();
        }
Exemple #29
0
 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()));
 }
Exemple #31
0
 public void Add(IAnimal item)
 {
     animals.Add(item);
 }
Exemple #32
0
    public void Groom(IAnimal animal)
    {
        var groomer = groomers[animal.GetType()];

        groomer.Groom((dynamic)animal);
    }
Exemple #33
0
 void HandleAnimal(ICat cat, IAnimal any)
 {
 }
Exemple #34
0
 private static void AnimalSays(IAnimal animal)
 {
     Console.WriteLine("{0} says {1}", animal.GetType().Name, animal.Says());
 }
Exemple #35
0
 /// <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}";
Exemple #36
0
 private void MoveToAntilopesPosition(IAnimal antilopeInRange, Lion lion)
 {
     lion.PositionOnXAxis = antilopeInRange.PositionOnXAxis;
     lion.PositionOnYAxis = antilopeInRange.PositionOnYAxis;
 }
Exemple #37
0
 //TEST 2
 public void MakeNoise(IAnimal animal)
 {
     //Test 2 : Modify this method to make the animals talk
     animal.Talk();
 }
Exemple #38
0
 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);
 }
Exemple #39
0
 public virtual void DoService(IAnimal animal, int procedureTime)
 {
 }
Exemple #40
0
 private static bool IsLion(IAnimal animal) {
     return animal.Name == "Lion";
 }
 protected void AddAnimalProcedure(IAnimal animal)
 {
     this.procedureHistory.Add(animal);
 }
Exemple #42
0
 public override void DoService(IAnimal animal, int procedureTime)
 {
     base.DoService(animal, procedureTime);
 }
Exemple #43
0
 public int Exit(IAnimal exitingAnimal)
 {
     _animalsOnSquare.Add(exitingAnimal);
 }
Exemple #44
0
 public AppRunner(IAnimal animal, IVehicle vehicle)
 {
     _animal  = animal;
     _vehicle = vehicle;
 }
 public void Discribe(IAnimal animal)
 {
     Console.WriteLine(animal.GetType().Name + " is " + typeof(IAnimal).Name);
 }
Exemple #46
0
 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);
 }
Exemple #49
0
 private static void DisplayAnimalData(IAnimal animal)
 {
     Console.WriteLine("Animal has {0} legs and makes this sound: {1}", animal.NumberOfLegs);
     animal.Vocalize();
 }
Exemple #50
0
 public void Attach(IAnimal animal)
 {
     animals.Add(animal);
 }
Exemple #51
0
 private void Eat(IAnimal antilope, Lion lion)
 {
     MoveToAntilopesPosition(antilope, lion);
     lion.HitPoints = 100;
     antilope.HitPoints = 0;
 }
Exemple #52
0
 public void Detach(IAnimal animal)
 {
     animals.Remove(animal);
 }
 public void Say(IAnimal obj)
 {
     Console.WriteLine("IAnimal Method");
     Console.WriteLine(obj.GetType().Name);
 }
Exemple #54
0
 public Dog(IAnimal friend) : this()
 {
     Interlocked.Increment(ref CtorIAnimal);
     Friend = friend;
 }
Exemple #55
0
 private void PlaceAnimalOnBoard(IAnimal animal, char animalSignature) {
     Layout[animal.PositionOnYAxis, animal.PositionOnXAxis] = animalSignature;
 }
Exemple #56
0
 public AnimalController(IIndex <string, IAnimal> serviceIndexes)
 {
     _serviceIndexes = serviceIndexes;
     _animal         = serviceIndexes["dog"];
 }
Exemple #57
0
 static void MoveAnimal(IAnimal animal)
 {
     animal.Move();
 }
 public abstract void DoService(IAnimal animal, int procedureTime);
 public IAnimal GetClone(IAnimal animalSample)
 {
     return (IAnimal) animalSample.Clone ();
 }
Exemple #60
0
 void MoveAnimal(IAnimal animal)
 {
     animal.Move();
 }