Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp4
- {
- using System;
- using System.Collections.Generic;
- namespace ZooApp
- {
- 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()
- {
- _aviarysList.Add(new Aviary("Львиный вольер", AnimalCreate.CreateAnimals("Lion", 5)));
- _aviarysList.Add(new Aviary("Крокодилий вольер", AnimalCreate.CreateAnimals("Crocodile", 4)));
- _aviarysList.Add(new Aviary("Обезьяний вольер", AnimalCreate.CreateAnimals("Monkey", 6)));
- _aviarysList.Add(new Aviary("Вольер с хищными птицами", AnimalCreate.CreateAnimals("Bird", 8)));
- }
- }
- public abstract class AnimalCreate
- {
- const string AnimalTypeLion = "Lion";
- const string AnimalTypeCrocodilen = "Crocodile";
- const string AnimalTypeMonkey = "Monkey";
- const string AnimalTypeBird = "Bird";
- public static List<Animal> CreateAnimals(string animalType, int count)
- {
- List<Animal> animals = new List<Animal>();
- Sounds sound;
- switch (animalType)
- {
- case AnimalTypeLion:
- sound = Sounds.Roar;
- break;
- case AnimalTypeCrocodilen:
- sound = Sounds.Growl;
- break;
- case AnimalTypeMonkey:
- sound = Sounds.Squeak;
- break;
- case AnimalTypeBird:
- sound = Sounds.Laugh;
- break;
- default:
- throw new ArgumentException("Invalid animal type");
- }
- for (int i = 0; i < count; i++)
- {
- animals.Add(new Animal(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 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