static void Main(string[] args) { IReader reader = new Reader(); IWriter writer = new Writer(); IAnimalCreator animalCreator = new AnimalCreator(); IFoodCreator foodCreator = new FoodCreator(); IEngine engine = new Engine(reader, writer, animalCreator, foodCreator); engine.Run(); }
public void Run() { string input = string.Empty; while ((input = Console.ReadLine()) != "End") { string[] animalInput = input .Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); IAnimal newAnimal = AnimalCreator.CreateAnimal(animalInput); string[] foodInput = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); newAnimal.Eat(foodInput[0], int.Parse(foodInput[1])); listOfAnimals.Add(newAnimal); } Printing(); }
static void Main() { List <Animal> animals = new List <Animal>(); string command = Console.ReadLine(); while (command != "End") { Animal newAnimal = AnimalCreator.CreateAnimal(command); try { Food newFood = FoodCreator.CreateFood(Console.ReadLine()); newAnimal.AskForFood(); if (newAnimal.AcceptedFoods.Contains(newFood.GetType().Name)) { newAnimal.FoodEaten += newFood.Quantity; newAnimal.Weight += newAnimal.WeightIncrease * newFood.Quantity; } else { throw new ArgumentException($"{newAnimal.GetType().Name} does not eat {newFood.GetType().Name}!"); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } animals.Add(newAnimal); command = Console.ReadLine(); } foreach (Animal animal in animals) { Console.WriteLine(animal.ToString()); } }
static void Main(string[] args) { List <Animal> animals = new List <Animal>(); string command = Console.ReadLine(); while (command != "End") { AnimalCreator animalCreator = null; FoodCreator foodCreator = null; string[] animalInput = command.Split(); string animalType = animalInput[0]; string name = animalInput[1]; double weight = double.Parse(animalInput[2]); switch (animalType) { case "Hen": double wingSize = double.Parse(animalInput[3]); animalCreator = new HenCreator(name, weight, wingSize); break; case "Owl": wingSize = double.Parse(animalInput[3]); animalCreator = new OwlCreator(name, weight, wingSize); break; case "Mouse": string livingRegion = animalInput[3]; animalCreator = new MouseCreator(name, weight, livingRegion); break; case "Cat": livingRegion = animalInput[3]; string breed = animalInput[4]; animalCreator = new CatCreator(name, weight, livingRegion, breed); break; case "Dog": livingRegion = animalInput[3]; animalCreator = new DogCreator(name, weight, livingRegion); break; case "Tiger": livingRegion = animalInput[3]; breed = animalInput[4]; animalCreator = new TigerCreator(name, weight, livingRegion, breed); break; } string[] foodInput = Console.ReadLine().Split(); string foodType = foodInput[0]; int quantity = int.Parse(foodInput[1]); switch (foodType) { case "Vegetable": foodCreator = new VegetableCreator(quantity); break; case "Fruit": foodCreator = new FruitCreator(quantity); break; case "Meat": foodCreator = new MeatCreator(quantity); break; case "Seeds": foodCreator = new SeedsCreator(quantity); break; } Animal animal = animalCreator.CreateAnimal(); Food food = foodCreator.CreateFood(); Console.WriteLine(animal.AskForFood()); try { animal.Feed(food); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } animals.Add(animal); command = Console.ReadLine(); } Console.WriteLine(string.Join(Environment.NewLine, animals)); }
public Engine() { this.animals = new List <Animal>(); this.animalCreator = new AnimalCreator(); this.foodCreator = new FoodCreator(); }