Anonim_999

Zoo

Oct 10th, 2021
1,515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. namespace ConsoleApp2
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Zoo zoo = new Zoo();
  11.             zoo.StartWork();
  12.         }
  13.     }
  14.  
  15.     class Zoo
  16.     {
  17.         private List<string> _sounds;
  18.         private List<Aviary> _aviaries = new List<Aviary>();
  19.  
  20.         public Zoo()
  21.         {
  22.             Random random = new Random();
  23.             int countAviary = random.Next(1,10);
  24.             _sounds = new List<string> { "Фить-фить", "вуп-вуп", "ааааа", "ААААААААА"};
  25.  
  26.             for (int i = 0; i < countAviary; i++)
  27.             {
  28.                 _aviaries.Add(new Aviary(_sounds[random.Next(0,_sounds.Count)]));
  29.             }
  30.         }
  31.  
  32.         public void StartWork()
  33.         {
  34.             bool isWorking = true;
  35.             string userInput;
  36.  
  37.             while (isWorking)
  38.             {
  39.                 Console.Clear();
  40.                 Console.WriteLine("Меню:");
  41.                 ShowInfo();
  42.                 Console.Write("Выберете вальер: ");
  43.                 userInput = Console.ReadLine();
  44.                 int number;
  45.  
  46.                 if (int.TryParse(userInput, out number))
  47.                 {
  48.                     if (Convert.ToInt32(userInput) <= _aviaries.Count && Convert.ToInt32(userInput) > 0)
  49.                     {
  50.                         _aviaries[Convert.ToInt32(userInput) - 1].ShowInfo();
  51.                     }
  52.                     else
  53.                     {
  54.                         Console.WriteLine("Нет такого вальера");
  55.                     }
  56.                 }
  57.                 else
  58.                 {
  59.                     Console.WriteLine("Напишите номер вальера");
  60.                 }
  61.                 Console.ReadKey();
  62.             }
  63.         }
  64.  
  65.         private void ShowInfo()
  66.         {
  67.             Console.WriteLine($"Кол-во вальеров: {_aviaries.Count}");
  68.         }
  69.     }
  70.  
  71.     class Aviary
  72.     {
  73.         private List<Animal> _animals = new List<Animal>();
  74.  
  75.         public Aviary(string sound)
  76.         {
  77.             Random random = new Random();
  78.             int countAnimals = random.Next(1,8);
  79.            
  80.             for (int i = 0; i < countAnimals; i++)
  81.             {
  82.                 _animals.Add(new Animal(sound));
  83.             }
  84.         }
  85.  
  86.         public void ShowInfo()
  87.         {
  88.             Console.WriteLine($"Кол-во животных в вольере: {_animals.Count}");
  89.  
  90.             for (int i = 0; i < _animals.Count; i++)
  91.             {
  92.                 Console.Write($"{i + 1}. ");
  93.                 _animals[i].ShowInfo();
  94.             }
  95.         }
  96.     }
  97.  
  98.     class Animal
  99.     {
  100.         private string _gender;
  101.         private string _sound;
  102.         private List<string> _genders;
  103.  
  104.         public Animal(string sound)
  105.         {
  106.             Random random = new Random();
  107.             _genders = new List<string> { "Мужской", "Женский" };
  108.             _gender = _genders[random.Next(0,_genders.Count)];
  109.             _sound = sound;
  110.         }
  111.  
  112.         public void ShowInfo()
  113.         {
  114.             Console.WriteLine($"Пол: {_gender} || Издает звук: {_sound}");
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment