예제 #1
0
파일: Zoo.cs 프로젝트: snitsars/Trainings
        //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();
            }
        }
예제 #2
0
 private static void Main(string[] args)
 {
     var animals = new IAnimal[] {new Monkey(), new Dog()};
     foreach (var animal in animals)
     {
         DisplayAnimalData(animal);
     }
 }
예제 #3
0
파일: Zoo.cs 프로젝트: snitsars/Trainings
        //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));
        }
예제 #4
0
 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;
 }
예제 #5
0
 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);
 }
예제 #6
0
 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);
     }
 }
예제 #7
0
 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);
 }
예제 #8
0
 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);
 }
예제 #9
0
 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);
 }
예제 #10
0
        public static void DoSomething(IAnimal animal)
        {
            Console.WriteLine(animal.Name);
            Console.WriteLine(animal.MakeSound());

            if (animal is IBird)
            {
                Console.WriteLine("Flap Flap Flap");
            }
        }
예제 #11
0
 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());
 }
예제 #12
0
        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");
        }
예제 #13
0
파일: Zoo.cs 프로젝트: snitsars/Trainings
        //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();
            }
        }
예제 #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();
        }
예제 #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();

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

            return(grid[position[0], position[1]]);
        }
예제 #25
0
 public Program(IAnimal animal)
 {
     Animal = animal;
 }
예제 #26
0
파일: BagService.cs 프로젝트: DenKu1/bag
 public bool AddAnimal(IAnimal animal)
 {
     return(_place.AddAnimal(animal));
 }
예제 #27
0
        public static void ByGenericParameter <T>() where T : IAnimal
        {
            IAnimal animal = svcMgr.Get <T>();

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

            animal.Speak();
        }
예제 #29
0
 public DuckAdapter(IAnimal a)
 {
     this.a = a;
 }
예제 #30
0
 public void Play(IAnimal animal)
 {
     //play with the animal
     Console.WriteLine(String.Format("playing with {0} and it said {1}", animal.Name, animal.Speak()));
 }
예제 #31
0
 public void Add(IAnimal item)
 {
     animals.Add(item);
 }
예제 #32
0
    public void Groom(IAnimal animal)
    {
        var groomer = groomers[animal.GetType()];

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