Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Home_Work
- {
- class Program
- {
- static void Main()
- {
- Zoo zoo = new Zoo();
- zoo.Work();
- }
- }
- class Zoo
- {
- private List<Aviary> _aviares;
- public Zoo()
- {
- _aviares = new List<Aviary>();
- FillAviares();
- }
- public void Work()
- {
- bool isWorking = true;
- string userInput;
- while (isWorking == true)
- {
- Console.WriteLine($"В зоопарке {_aviares.Count} вольеров.");
- for (int i = 0; i < _aviares.Count; i++)
- {
- Console.WriteLine($"{i + 1}. {_aviares[i].GetName()}.");
- }
- Console.WriteLine($"{_aviares.Count + 1}. Выход.");
- Console.Write("Выберите, к какому хотите подойти: ");
- userInput = Console.ReadLine();
- Console.Clear();
- if (Int32.TryParse(userInput, out int index))
- {
- if (index > 0 && index <= _aviares.Count)
- {
- _aviares[index - 1].ShowInfo();
- }
- else if (index == _aviares.Count + 1)
- {
- isWorking = false;
- Console.WriteLine("Будем рады увидеть вас снова.");
- }
- else
- {
- Console.WriteLine("Нет такого вольера.");
- }
- }
- else
- {
- Console.WriteLine("Вы ввели не число.");
- }
- Console.WriteLine("Нажмите любую клавишу.");
- Console.ReadKey();
- Console.Clear();
- }
- }
- private void FillAviares()
- {
- int countAnimal = Enum.GetNames(typeof(TypeAnimal)).Length;
- for (int indexAnimal = 1; indexAnimal <= countAnimal; indexAnimal++)
- {
- _aviares.Add(new Aviary(indexAnimal));
- }
- }
- }
- class Aviary
- {
- private List<Animal> _animals;
- private int _maxCountAnimal;
- private int _indexAnimal;
- public Aviary(int indexAnimal)
- {
- _maxCountAnimal = 5;
- _indexAnimal = indexAnimal;
- _animals = new List<Animal>();
- Fill();
- }
- public string GetName()
- {
- return "Тут " + (TypeAnimal)_indexAnimal;
- }
- public void ShowInfo()
- {
- int index = 1;
- Console.WriteLine($"В вольере {_maxCountAnimal} животных.\n");
- foreach(Animal animal in _animals)
- {
- Console.Write(index + ". ");
- animal.ShowInfo();
- index++;
- }
- }
- private void Fill()
- {
- for (int i = 0; i < _maxCountAnimal; i++)
- {
- _animals.Add(new Animal(_indexAnimal));
- }
- }
- }
- class Animal
- {
- private static readonly Random _random;
- private TypeAnimal _type;
- private SoundAnimal _sound;
- private bool _isMan;
- static Animal()
- {
- _random = new Random();
- }
- public Animal(int indexAnimal)
- {
- int maxCountSex = 2;
- _type = (TypeAnimal)indexAnimal;
- _sound = (SoundAnimal)indexAnimal;
- _isMan = Convert.ToBoolean(_random.Next(maxCountSex));
- }
- public string TypeName => Convert.ToString(_type);
- private string _sex => _isMan ? "Мужской" : "Женский";
- public void ShowInfo()
- {
- Console.WriteLine($"{_type} говорит \"{_sound}\". Пол: {_sex}.");
- }
- }
- enum TypeAnimal
- {
- Лев = 1,
- Гиена,
- Медведь,
- Лиса
- }
- enum SoundAnimal
- {
- Мяу = 1,
- Хыхыхы,
- Сгущёночка,
- Фыр
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement