Пример #1
0
        private bool Starve(IAnimal animal)
        {
            if (!animal.Hungry)
            {
                return(false);
            }
            if (animal.NoFreeFat)
            {
                return(true);
            }
            var fatCards     = animal.Upgrades.Where(x => x.UpgradeType == UpgradeType.Fat);
            var fullFatCards = fatCards.Where(x => (x as UpgradeFat).Full);

            if (!fullFatCards.Any())
            {
                return(true);
            }
            if (fullFatCards.Count() < animal.FoodNeeded - animal.FoodGot)
            {
                return(true);
            }
            for (int i = 0; i < animal.FoodNeeded - animal.FoodGot; i++)
            {
                (fullFatCards.First(x => (x as UpgradeFat).Full) as UpgradeFat).Full = false;
                animal.AddFood(new FoodToken(false), null);
                if (!animal.Hungry)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
 public void Feed(IAnimal animal)
 {
     if (animal == null)
     {
         throw new ArgumentNullException();
     }
     if (!Animals.Contains(animal))
     {
         throw new AnimalNotFoundException();
     }
     if (animal.Hungry)
     {
         animal.AddFood(new FoodToken(true), null);
     }
     else if (animal.CanEat)
     {
         ((UpgradeFat)animal.Upgrades.First(x => x.UpgradeType == UpgradeType.Fat)).Full = true;
     }
     else
     {
         throw new AnimalAlreadyFedException();
     }
 }