示例#1
0
        public void Run()
        {
            string command;

            while ((command = reader.ReadLine()) != "End")
            {
                string[] animalArgs = command.Split();
                animal = animalFactory.CreatAnimal(animalArgs);
                if (animal != null)
                {
                    animals.Add(animal);
                }

                string[] foodArgs = reader.ReadLine().Split();
                food = foodFactory.CreatFood(foodArgs);

                writer.WriteLine(animal.ProduceSound());

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

            foreach (var animal in animals)
            {
                writer.WriteLine(animal.ToString());
            }
        }