コード例 #1
0
ファイル: Boar.cs プロジェクト: slapshott/Homework
        /// <summary>
        /// The Boar should be able to eat any animal,
        /// which is smaller than him or as big as him.
        /// </summary>
        /// <param name="animal"></param>
        /// <returns></returns>
        public int TryEatAnimal(Animal animal)
        {
            try
            {
                MealValidation.CheckIfMealIsNull(animal);
                MealValidation.CheckIfMealIsOfSuitableSize(this.Size, animal.Size);

                var quantityOfMeatEaten = animal.GetMeatFromKillQuantity();
                return(quantityOfMeatEaten);
            }
            catch (Exception)
            {
                return(0);
            }
        }
コード例 #2
0
ファイル: Boar.cs プロジェクト: slapshott/Homework
        /// <summary>
        /// The Boar should be able to eat from any plant.
        /// The Boar always has a bite size of 2.
        /// When eating from a plant,
        /// the Boar increases its size by 1.
        /// </summary>
        /// <param name="plant"></param>
        /// <returns></returns>
        public int EatPlant(Plant plant)
        {
            try
            {
                MealValidation.CheckIfMealIsNull(plant);

                var quantityEaten = plant.GetEatenQuantity(Boar.BiteSize);

                this.GrowWhenEating(Boar.GrowWhenEatingPlantsWithAmount);

                return(quantityEaten);
            }
            catch (Exception)
            {
                return(0);
            }
        }