Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Program
- {
- static void Main(string[] args)
- {
- Zoo zoo = new Zoo();
- zoo.RunApp();
- }
- }
- public enum Genders
- {
- Male,
- Female
- }
- public enum Sounds
- {
- Roar,
- Growl,
- Squeak,
- Laugh,
- Cluck
- }
- public class Animal
- {
- public Animal(Sounds sound)
- {
- Sound = sound;
- CreateRandomGender();
- }
- public Sounds Sound { get; private set; }
- public Genders Gender { get; private set; }
- private void CreateRandomGender()
- {
- Genders gender = (Genders)UserUtils.GenerateRandom(1);
- Gender = gender;
- }
- }
- public class Aviary
- {
- private readonly List<Animal> _animalsList;
- public Aviary(string name, List<Animal> animals)
- {
- Name = name;
- _animalsList = animals;
- }
- public string Name { get; private set; }
- public void DisplayInfo()
- {
- Console.WriteLine($"Вольер: {Name}");
- Console.WriteLine($"Количество животных: {_animalsList.Count}");
- Console.WriteLine("Информация о животных:");
- foreach (Animal animal in _animalsList)
- {
- Console.WriteLine($"- Пол: {animal.Gender}, Звук: {animal.Sound}");
- }
- }
- }
- class AviaryCreator
- {
- private readonly List<Aviary> _aviarysList;
- public AviaryCreator()
- {
- _aviarysList = new List<Aviary>();
- InitializeEnclosures();
- }
- public List<Aviary> GetAviaries()
- {
- return _aviarysList;
- }
- private void InitializeEnclosures()
- {
- AnimalCreate lionFactory = new Lion();
- List<Animal> lions = lionFactory.CreateAnimals(5);
- _aviarysList.Add(new Aviary("Львиный вольер", lions));
- AnimalCreate crocodileFactory = new Crocodile();
- List<Animal> crocodiles = crocodileFactory.CreateAnimals(4);
- _aviarysList.Add(new Aviary("Крокодилий вольер", crocodiles));
- AnimalCreate monkeyFactory = new Monkey();
- List<Animal> monkeys = monkeyFactory.CreateAnimals(6);
- _aviarysList.Add(new Aviary("Обезьяний вольер", monkeys));
- AnimalCreate birdFactory = new Bird();
- List<Animal> birds = birdFactory.CreateAnimals(8);
- _aviarysList.Add(new Aviary("Вольер с хищными птицами", birds));
- }
- }
- public abstract class AnimalCreate
- {
- public abstract List<Animal> CreateAnimals(int count);
- }
- public class Lion : AnimalCreate
- {
- public override List<Animal> CreateAnimals(int count)
- {
- List<Animal> lions = new List<Animal>();
- for (int i = 0; i < count; i++)
- {
- lions.Add(new Animal(Sounds.Roar));
- }
- return lions;
- }
- }
- public class Crocodile : AnimalCreate
- {
- public override List<Animal> CreateAnimals(int count)
- {
- List<Animal> crocodiles = new List<Animal>();
- for (int i = 0; i < count; i++)
- {
- crocodiles.Add(new Animal(Sounds.Growl));
- }
- return crocodiles;
- }
- }
- public class Monkey : AnimalCreate
- {
- public override List<Animal> CreateAnimals(int count)
- {
- List<Animal> monkeys = new List<Animal>();
- for (int i = 0; i < count; i++)
- {
- monkeys.Add(new Animal(Sounds.Laugh));
- }
- return monkeys;
- }
- }
- public class Bird : AnimalCreate
- {
- public override List<Animal> CreateAnimals(int count)
- {
- List<Animal> Birds = new List<Animal>();
- for (int i = 0; i < count; i++)
- {
- Birds.Add(new Animal(Sounds.Cluck));
- }
- return Birds;
- }
- }
- public class Zoo
- {
- private readonly AviaryCreator _aviaryCreator;
- private readonly List<Aviary> _aviarysList;
- public Zoo()
- {
- _aviaryCreator = new AviaryCreator();
- _aviarysList = _aviaryCreator.GetAviaries();
- }
- public void RunApp()
- {
- const int ExitCommand = 0;
- bool isWorking = true;
- while (isWorking)
- {
- Console.Clear();
- Console.WriteLine("Выберите вольер, к которому вы хотите подойти:\n");
- for (int i = 0; i < _aviarysList.Count; i++)
- {
- Console.WriteLine($"{i + 1}. {_aviarysList[i].Name}");
- }
- Console.WriteLine($"\n{ExitCommand}. Выход");
- Console.Write("\nВведите номер: ");
- if (int.TryParse(Console.ReadLine(), out int choice))
- {
- if (choice == ExitCommand)
- {
- isWorking = false;
- }
- else if (choice >= 1 && choice <= _aviarysList.Count)
- {
- Console.Clear();
- Aviary selectedEnclosure = _aviarysList[choice - 1];
- selectedEnclosure.DisplayInfo();
- Console.WriteLine("Нажмите Enter, чтобы вернуться в меню.");
- Console.ReadLine();
- }
- else
- {
- Console.WriteLine("Неверный выбор. Попробуйте еще раз.");
- Console.ReadLine();
- }
- }
- else
- {
- Console.WriteLine("Некорректный ввод. Пожалуйста, введите число.");
- Console.ReadLine();
- }
- }
- }
- }
- class UserUtils
- {
- private static Random s_random = new Random();
- public static int GenerateRandom(int maxValue, int minValue = 0)
- {
- return s_random.Next(minValue, maxValue + 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement