Пример #1
0
        public void Run()
        {
            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                string[] animalArgs = command.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
                string[] foodArgs   = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
                IAnimal  animal     = CreateAnimal(animalArgs);
                IFood    food       = foodFactory.ProduceFood(foodArgs[0], int.Parse(foodArgs[1]));
                animals.Add(animal);

                Console.WriteLine(animal.ProduceSound());

                try
                {
                    animal.Feed(food);
                }
                catch (UneatableFoodException ufe)
                {
                    Console.WriteLine(ufe.Message);
                }
            }
            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Пример #2
0
        public void Run()
        {
            while (true)
            {
                string command = Console.ReadLine();
                if (command == "End")
                {
                    break;
                }

                string[] animalArgs = command.Split();
                animal = animalFactory.ProduceAnimal(animalArgs);

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

                animals.Add(animal);
                animal.ProduseSound();
                animal.Eat(food);
            }

            foreach (var currAnimal in animals)
            {
                Console.WriteLine(currAnimal);
            }
        }
        private IFood CreateFood()
        {
            string[] foodArgs = this.reader.ReadLine()
                                .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                .ToArray();

            string foodType     = foodArgs[0];
            int    foodQuantity = int.Parse(foodArgs[1]);

            IFood food = foodFactory.ProduceFood(foodType, foodQuantity);

            return(food);
        }