/// <summary>
        ///		Add the babies stored in the Babies list to the main list.  This is an
        ///		internal method that may only be called by classes in the Rabies_Model_Core
        ///		namespace.
        /// </summary>
        /// <param name="EHandler">An event handler for the AnimalInfected event.</param>
        internal void AddBabiesToList(AnimalInfectedEventHandler EHandler)
        {
            //System.Diagnostics.Debug.WriteLine("");
            //System.Diagnostics.Debug.WriteLine("cMasterAnimalList.cs: AddBabiesToList()");

            if (Babies.Count > 0)
            {
                // loop through all animals in the babies list
                foreach (cAnimal BabyAnimal in Babies)
                {
                    // set the event handler
                    if (EHandler != null)
                    {
                        BabyAnimal.AnimalInfected += EHandler;
                    }
                    // add to main list
                    this.Add(BabyAnimal);
                    // add to all animals list
                    if (mvarKeepAllAnimals)
                    {
                        AllAnimals.Add(BabyAnimal);
                    }
                }
                // destroy this version of the BabyAnimal list and create a new one
                Babies = new cAnimalList(null);
            }
        }
Пример #2
0
        public void Run()
        {
            string     command = Console.ReadLine();
            AllAnimals animals = new AllAnimals();

            while (command != "End")
            {
                string[] animalInfo = command.Split();
                string[] foodInfo   = Console.ReadLine().Split();

                string animalType = animalInfo[0];
                string name       = animalInfo[1];
                double weight     = double.Parse(animalInfo[2]);

                string foodType = foodInfo[0];
                int    quantity = int.Parse(foodInfo[1]);

                FoodFactory   foodFactory   = new FoodFactory(quantity, foodType);
                Food          food          = foodFactory.CheckFood();
                AnimalFactory animalFactory = new AnimalFactory(animalType, name, weight, quantity, food, animalInfo);
                Animal        animal        = animalFactory.CheckAnimal();

                animals.Add(animal);

                command = Console.ReadLine();
            }
            animals.Print();
        }
Пример #3
0
        public void FeedGroup()
        {
            var animalgroup = AllAnimals.Where(animal => animal.Type == SelctFeedType);

            foreach (Animal animal in animalgroup)
            {
                animal.Eat();
            }
        }
Пример #4
0
        public void AddAnimal()
        {
            //Instantiate animal, connect event handler, add animal to collection.
            var tempAnimal = GetAnimal(SelctAddType);

            tempAnimal.IsStarving += Animal_IsStarving;
            tempAnimal.HasDied    += Animal_HasDied;
            AllAnimals.Add(tempAnimal);
        }
Пример #5
0
 public bool IsAbleToFeedGroup()
 {
     if (HasAnimals())
     {
         if (AllAnimals.Where(ani => ani.Type == SelctFeedType).Any())
         {
             return(true);
         }
     }
     return(false);
 }
Пример #6
0
 public bool HasMultipleTypes()
 {
     if (HasAnimals())
     {
         if (AllAnimals.GroupBy(ani => ani.Type).Count() > 1)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #7
0
 public void Animal_HasDied(object sender, EventArgs e)
 {
     try
     {
         Animal animal = sender as Animal;
         Messages.Add(new Message {
             Text = (new string(string.Format("{0} has died.", animal.Name))), Urgency = Urgency.Medium
         });
         AllAnimals.Remove(animal);
     }
     catch (InvalidCastException exc)
     {
         Console.WriteLine("Invalid Cast Exception: {0}", exc.Message);
     }
 }
Пример #8
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            //Cast AllAnimals.ToList to be able to enumerate through it.
            //Whilst possibly removing animals from collection.
            foreach (Animal animal in AllAnimals.ToList())
            {
                animal.UseEnergy();

                //Old (more efficient) method to check if animal has starved. Currently replaced with HasDied event.

                /*if (HasAnimalStarved(animal))
                 * {
                 *  AllAnimals.Remove(animal);
                 * }*/
            }
        }
 /// <summary>
 ///		Add the babies stored in the Babies list to the main list.  This is an
 ///		internal method that may only be called by classes in the Rabies_Model_Core
 ///		namespace.
 /// </summary>
 internal void AddBabiesToList()
 {
     if (Babies.Count > 0)
     {
         // loop through all animals in the babies list
         foreach (cAnimal BabyAnimal in Babies)
         {
             // add to main list
             this.Add(BabyAnimal);
             // add to all animals list
             if (mvarKeepAllAnimals)
             {
                 AllAnimals.Add(BabyAnimal);
             }
         }
         // destroy this version of the BabyAnimal list and create a new one
         Babies = new cAnimalList(null);
     }
 }
Пример #10
0
 public static void InitAnimals() => AllAnimals.InitAnimalsList();
Пример #11
0
 public void SortAnimalEnergy()
 {
     AllAnimals.Sort(ani => ani.RelativeEnergy, IsAscendSortG);
     IsAscendSortG = !IsAscendSortG;
 }
Пример #12
0
 /// <summary>
 /// Sorts by group, ascending or descending.
 /// </summary>
 public void SortAnimalType()
 {
     AllAnimals.Sort(ani => ani.Type, IsAscendSortT);
     //Switch boolean to sort in opposite order next click.
     IsAscendSortT = !IsAscendSortT;
 }