Beispiel #1
0
        public void Run()
        {
            List <IAnimal> animals = new List <IAnimal>();

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] animalElements = input
                                          .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                          .ToArray();

                IAnimal animal = AnimalFactory.Create(animalElements);
                animals.Add(animal);

                Console.WriteLine(animal.ProduceSound());

                string[] foodElements = Console.ReadLine()
                                        .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                        .ToArray();

                IFood food = FoodFactory.Create(foodElements);

                try
                {
                    animal.Eat(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (IAnimal animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Beispiel #2
0
        public void Run()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }

                string[] animalArgs = input.Split();

                Animal animal = AnimalFactory.CreateAnimal(animalArgs);

                string[] foodArgs = Console.ReadLine().Split();

                Food food = FoodFactory.CreateFood(foodArgs);

                Console.WriteLine(animal.ProduceSound());

                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }

                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Beispiel #3
0
 public Engine()
 {
     animals     = new List <IAnimal>();
     foodFactory = new FoodFactory();
 }
 public Engine()
 {
     this.animals     = new List <Animal>();
     this.foodFactory = new FoodFactory();
 }
Beispiel #5
0
 public Engine()
 {
     this.animalFactory = new AnimalFactory();
     this.foodFactory   = new FoodFactory();
     this.animals       = new HashSet <Animal>();
 }
Beispiel #6
0
 public Engine()
 {
     this.foodFactory   = new FoodFactory();
     this.animalFactory = new AnimalFactory();
 }
        public void Run()
        {
            BirdFactory   birdFactory   = new BirdFactory();
            MammalFactory mammalFactory = new MammalFactory();
            FelineFactory felineFactory = new FelineFactory();
            FoodFactory   foodFactory   = new FoodFactory();

            List <Animal> animals = new List <Animal>();

            while (true)
            {
                string[] currentAnimal = Console.ReadLine().Split();

                if (currentAnimal[0] == "End")
                {
                    break;
                }

                string[] currentFood = Console.ReadLine().Split();

                string animalType   = currentAnimal[0];
                string animalName   = currentAnimal[1];
                double animalWeight = double.Parse(currentAnimal[2]);

                string foodType     = currentFood[0];
                int    foodQuantity = int.Parse(currentFood[1]);
                Food   food         = foodFactory.CreateFood(foodType, foodQuantity);

                try
                {
                    if (animalType == "Hen" || animalType == "Owl")
                    {
                        double wingSize = double.Parse(currentAnimal[3]);
                        Animal animal   = birdFactory.CreateBird(animalType, animalName, animalWeight, wingSize);

                        animal.ProduceSound();
                        animals.Add(animal);
                        animal.Eat(food);
                    }
                    else if (animalType == "Mouse" || animalType == "Dog")
                    {
                        string livingRegion = currentAnimal[3];
                        Animal animal       = mammalFactory.CreateMammal(animalType, animalName, animalWeight, livingRegion);

                        animal.ProduceSound();
                        animals.Add(animal);
                        animal.Eat(food);
                    }
                    else if (animalType == "Cat" || animalType == "Tiger")
                    {
                        string livingRegion = currentAnimal[3];
                        string breed        = currentAnimal[4];
                        Animal animal       = felineFactory.CreateFeline(animalType, animalName, animalWeight, livingRegion, breed);

                        animal.ProduceSound();
                        animals.Add(animal);
                        animal.Eat(food);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (Animal animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Beispiel #8
0
 public Engine()
 {
     animals       = new HashSet <Animal>();
     animalFactory = new AnimalFactory();
     foodFactory   = new FoodFactory();
 }