Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Zoo zoo = new Zoo();
- zoo.StartWork();
- }
- }
- class Zoo
- {
- private List<string> _sounds;
- private List<Aviary> _aviaries = new List<Aviary>();
- public Zoo()
- {
- Random random = new Random();
- int countAviary = random.Next(1,10);
- _sounds = new List<string> { "Фить-фить", "вуп-вуп", "ааааа", "ААААААААА"};
- for (int i = 0; i < countAviary; i++)
- {
- _aviaries.Add(new Aviary(_sounds[random.Next(0,_sounds.Count)]));
- }
- }
- public void StartWork()
- {
- bool isWorking = true;
- string userInput;
- while (isWorking)
- {
- Console.Clear();
- Console.WriteLine("Меню:");
- ShowInfo();
- Console.Write("Выберете вальер: ");
- userInput = Console.ReadLine();
- int number;
- if (int.TryParse(userInput, out number))
- {
- if (Convert.ToInt32(userInput) <= _aviaries.Count && Convert.ToInt32(userInput) > 0)
- {
- _aviaries[Convert.ToInt32(userInput) - 1].ShowInfo();
- }
- else
- {
- Console.WriteLine("Нет такого вальера");
- }
- }
- else
- {
- Console.WriteLine("Напишите номер вальера");
- }
- Console.ReadKey();
- }
- }
- private void ShowInfo()
- {
- Console.WriteLine($"Кол-во вальеров: {_aviaries.Count}");
- }
- }
- class Aviary
- {
- private List<Animal> _animals = new List<Animal>();
- public Aviary(string sound)
- {
- Random random = new Random();
- int countAnimals = random.Next(1,8);
- for (int i = 0; i < countAnimals; i++)
- {
- _animals.Add(new Animal(sound));
- }
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Кол-во животных в вольере: {_animals.Count}");
- for (int i = 0; i < _animals.Count; i++)
- {
- Console.Write($"{i + 1}. ");
- _animals[i].ShowInfo();
- }
- }
- }
- class Animal
- {
- private string _gender;
- private string _sound;
- private List<string> _genders;
- public Animal(string sound)
- {
- Random random = new Random();
- _genders = new List<string> { "Мужской", "Женский" };
- _gender = _genders[random.Next(0,_genders.Count)];
- _sound = sound;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Пол: {_gender} || Издает звук: {_sound}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment