Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp4
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ZooApp
- {
- public class Program
- {
- static void Main(string[] args)
- {
- Zoo zoo = new Zoo();
- zoo.Run();
- }
- }
- public enum Genders
- {
- Male,
- Female,
- }
- public class Animal
- {
- public Animal(string sound)
- {
- Sound = sound;
- CreateRandomGender();
- }
- public string 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> _animals;
- public Aviary(string name, List<Animal> animals)
- {
- Name = name;
- _animals = animals;
- }
- public string Name { get; private set; }
- public void DisplayInfo()
- {
- Console.WriteLine($"Вольер: {Name}");
- Console.WriteLine($"Количество животных: {_animals.Count}");
- Console.WriteLine("Информация о животных:");
- foreach (Animal animal in _animals)
- {
- Console.WriteLine($"- Пол: {animal.Gender}, Звук: {animal.Sound}");
- }
- }
- }
- class AviaryCreator
- {
- private readonly List<Aviary> _aviarys;
- public AviaryCreator()
- {
- _aviarys = new List<Aviary>();
- InitializeEnclosures();
- }
- public List<Aviary> GetAviaries()
- {
- return _aviarys.ToList();
- }
- private void InitializeEnclosures()
- {
- List<Animal> animalType = CreateAnimalType();
- _aviarys.Add(new Aviary("Львиный вольер", AnimalCreate.CreateAnimals(5, animalType[0])));
- _aviarys.Add(new Aviary("Крокодилий вольер", AnimalCreate.CreateAnimals(4, animalType[1])));
- _aviarys.Add(new Aviary("Обезьяний вольер", AnimalCreate.CreateAnimals(6, animalType[2])));
- _aviarys.Add(new Aviary("Вольер с хищными птицами", AnimalCreate.CreateAnimals(8, animalType[3])));
- }
- private List<Animal> CreateAnimalType()
- {
- List<Animal> animalsTypes = new List<Animal>
- {
- new Animal("Roar"),
- new Animal("Growl"),
- new Animal("Laugh"),
- new Animal("Squeak")
- };
- return animalsTypes;
- }
- }
- public class AnimalCreate
- {
- public static List<Animal> CreateAnimals(int count, Animal prototype)
- {
- List<Animal> animals = new List<Animal>();
- for (int i = 0; i < count; i++)
- {
- animals.Add(new Animal(prototype.Sound));
- }
- return animals;
- }
- }
- public class Zoo
- {
- private readonly AviaryCreator _aviaryCreator;
- private readonly List<Aviary> _aviarysList;
- public Zoo()
- {
- _aviaryCreator = new AviaryCreator();
- _aviarysList = _aviaryCreator.GetAviaries();
- }
- public void Run()
- {
- 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