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 Task49
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Zoo zoo = new Zoo();
- zoo.Work();
- }
- }
- class Zoo
- {
- private Random _random = new Random();
- private List<Aviary> _aviaries = new List<Aviary>();
- public void Work()
- {
- AddAviary(4);
- bool isExit = false;
- string menu =
- "Введи номер одного из вальеров или цифру 0 (выход) если хочешь уйти: ";
- while (isExit == false)
- {
- Console.WriteLine($"Доступно вольеров - {_aviaries.Count}");
- int userInput = GetInt(menu);
- if (userInput > 0 && userInput <= _aviaries.Count)
- ShowAviary(userInput);
- else if (userInput == 0)
- isExit = true;
- else
- Console.WriteLine("Такого вальера или команды не существует.");
- Console.WriteLine("Чтобы отправиться назад нажмите любую кнопку. ");
- Console.ReadKey();
- Console.Clear();
- }
- }
- private void AddAviary(int numberAviary)
- {
- for (int i = 0; i < numberAviary; i++)
- {
- _aviaries.Add(new Aviary(_random));
- }
- }
- private void ShowAviary(int index)
- {
- _aviaries[index-1].ShowAnimal();
- }
- private int GetInt(string requestInputNumber)
- {
- string errorConversion = "Ошибка,вы вели не цифры! Попробуйте снова.";
- string userInput;
- bool resultConverted = false;
- int number = 0;
- while (resultConverted == false)
- {
- Console.Write(requestInputNumber);
- userInput = Console.ReadLine();
- resultConverted = int.TryParse(userInput, out int numberConvert);
- if (resultConverted != true)
- Console.WriteLine(errorConversion);
- else
- number = numberConvert;
- }
- return number;
- }
- }
- class Aviary
- {
- private Dictionary<int, Animal> _animals = new Dictionary<int, Animal>();
- private List<Animal> _listAnimals = new List<Animal>();
- public Aviary(Random random)
- {
- AddAnimals();
- int minCountAnimals = 2;
- int maxCountAnimals = 25;
- int index = random.Next(0, _listAnimals.Count-1);
- int countAnimals = random.Next(minCountAnimals, maxCountAnimals);
- AddAviary(index, countAnimals, random);
- }
- public void ShowAnimal()
- {
- Console.WriteLine($"Кол-во животных в вольере: {_animals.Count}");
- for (int i = 0; i < _animals.Count; i++)
- {
- Console.WriteLine($"{_animals[i].Name}. Пол - {_animals[i].Gender}. Звук который издаёт - {_animals[i].Sound}");
- }
- }
- private void AddAviary(int index, int countAnimals, Random random)
- {
- for (int i = 0; i < countAnimals; i++)
- {
- _animals.Add(i, new Animal(GetAnimalName(index), GetAnimalSound(index), GetGenderAnimal(random)));
- }
- }
- private string GetAnimalName(int animalIndex)
- {
- return _listAnimals[animalIndex].Name;
- }
- private string GetAnimalSound(int animalIndex)
- {
- return _listAnimals[animalIndex].Sound;
- }
- private string GetGenderAnimal(Random random)
- {
- int Gender = random.Next(0, 100);
- if (Gender < 50)
- return "Самец";
- else
- return "Самка";
- }
- private void AddAnimals()
- {
- _listAnimals.Add(new Animal("Попугай(-и)", "АРРР", "null"));
- _listAnimals.Add(new Animal("Пингвин(-ы)", "Уваа", "null"));
- _listAnimals.Add(new Animal("Медведь(-и)", "РЫЫЫВ", "null"));
- _listAnimals.Add(new Animal("Обезьяны", "Уооааа", "null"));
- }
- }
- class Animal
- {
- public string Name { get; private set; }
- public string Gender { get; set; }
- public string Sound { get; private set; }
- public Animal(string name, string sound, string gender)
- {
- Name = name;
- Gender = gender;
- Sound = sound;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement