Esempio n. 1
0
        private static void FactoryExample()
        {
            IAnimalFactory factory   = AnimalFactory.CreateFactory();
            IAnimal        carnivore = factory.CreateAnimal(AnimalType.Carnivore);
            IAnimal        herbivore = factory.CreateAnimal(AnimalType.Herbivore);

            Console.WriteLine("I am a {0}, i sleep for {1} hours and like to eat {2}", carnivore.GetType().Name, carnivore.Sleep(), carnivore.Eat());
            Console.WriteLine("I am a {0}, i sleep for {1} hours and like to eat {2}", herbivore.GetType().Name, herbivore.Sleep(), herbivore.Eat());
        }
Esempio n. 2
0
        public void CreateGamefield()
        {
            field = _fieldFactory.CreateField();
            bool filledWithAnimals = false;

            while (!filledWithAnimals)
            {
                _facade.SetCursorPosition();
                _display.DrawAnimals(field);

                var key = _facade.ConsoleKey();

                var animalKey = key == TextParameters.AntelopeKey ||
                                key == TextParameters.LionKey;


                if (key == TextParameters.EnterKey)
                {
                    filledWithAnimals = true;
                    LifeCycle(field);
                }
                else if (animalKey)
                {
                    _animalFactory.CreateAnimal(key, field);
                }
            }
        }
Esempio n. 3
0
        public string RegisterAnimal(string type, string name, int energy, int happiness, int procedureTime)
        {
            IAnimal animal = factory.CreateAnimal(type, name, energy, happiness, procedureTime);

            hotel.Accommodate(animal);
            return($"Animal {name} registered successfully");
        }
Esempio n. 4
0
 public IAnimal GetAnimal()
 {
     return(_animalFactory.CreateAnimal(
                GenerateAnimalName(),
                GenerateFoodPerDay(),
                ChooseAnimalType()));
 }
        public Animal Breed(Animal animal, Field field)
        {
            ResetMatingValues(animal);

            var newAnimal = _animalFactory.CreateAnimal(animal.Key, field);

            return(newAnimal);
        }
 public PettingZooV70(
     Child aChild,
     IAnimalFactory factoryAnimal,
     IFoodFactory factoryFood)
 {
     TheChild  = aChild;
     TheAnimal = factoryAnimal.CreateAnimal(aChild.Age);
     TheFood   = factoryFood.CreateFood(aChild.MoneyLimit);
 }
Esempio n. 7
0
        private static IEnumerable <IAnimal> CreateAnimals(IAnimalFactory animalFactory, int numberOfAnimalsToCreate)
        {
            var animals = new List <IAnimal>();

            for (var i = 0; i < numberOfAnimalsToCreate; i++)
            {
                animals.Add(animalFactory.CreateAnimal());
            }

            return(animals);
        }
Esempio n. 8
0
 public PettingZooV60(Child aChild, IAnimalFactory aFactory)
 {
     TheChild  = aChild;
     TheAnimal = aFactory.CreateAnimal(aChild.Age);
 }
Esempio n. 9
0
 public IAnimal CreateAnimal()
 {
     return(animalFactory.CreateAnimal());
 }