Rodunskiy

Untitled

Jul 31st, 2023
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         Zoo zoo = new Zoo();
  9.  
  10.         bool isWorking = true;
  11.  
  12.         while (isWorking)
  13.         {
  14.             Console.Clear();
  15.             zoo.ShowVallier();
  16.         }
  17.     }
  18. }
  19.  
  20. class Zoo
  21. {
  22.     List<Valliere> Vallieres = new List<Valliere>();
  23.  
  24.     public Zoo()
  25.     {
  26.         Fill();
  27.     }
  28.  
  29.     public void Fill()
  30.     {
  31.         Vallieres.Add(new Valliere(new Monkey(), "Обезьяны", 1));
  32.         Vallieres.Add(new Valliere(new Elephant(), "Слоны", 2));
  33.         Vallieres.Add(new Valliere(new Giraffe(), "Жирафы", 3));
  34.         Vallieres.Add(new Valliere(new Bird(), "Птицы", 4));
  35.     }
  36.  
  37.     public void ShowVallier()
  38.     {
  39.         Console.WriteLine("Добро пожаловать в зоопарк! К какому вальеру вы хотели бы подойти?");
  40.  
  41.         ShowInfo();
  42.  
  43.         int userInput = Utils.ConvertToInt();
  44.  
  45.         Console.Clear();
  46.  
  47.         for (int i = 0; i < Vallieres[userInput - 1]._animals.Count; i++)
  48.         {
  49.             Console.WriteLine($"{Vallieres[userInput - 1]._animals[i].Name}|{Vallieres[userInput - 1]._animals[i].Gender}|{Vallieres[userInput - 1]._animals[i].Sound}");
  50.         }
  51.  
  52.         Console.ReadKey();
  53.     }
  54.  
  55.     public void ShowInfo()
  56.     {
  57.         foreach (var valliere in Vallieres)
  58.         {
  59.             Console.WriteLine($"{valliere.IdentificationNumber}){valliere.Name}");
  60.         }
  61.     }
  62. }
  63.  
  64. class Valliere
  65. {
  66.     public List<Animal> _animals = new List<Animal>();
  67.  
  68.     public Valliere(Animal animal, string name, int identificationNumber)
  69.     {
  70.         IdentificationNumber = identificationNumber;
  71.         Name = name;
  72.         AddToValliere(animal);
  73.     }
  74.  
  75.     public int IdentificationNumber { get; private set; }
  76.     public string Name { get; private set; }
  77.  
  78.     public void AddToValliere(Animal animal)
  79.     {
  80.         int maxPlaces = 5;
  81.         for (int i = 0; i < maxPlaces; i++)
  82.         {
  83.             _animals.Add(animal.Clone());
  84.         }
  85.     }
  86. }
  87.  
  88. class Animal
  89. {
  90.     public Animal(string name, string sound)
  91.     {
  92.         Name = name;
  93.         Sound = sound;
  94.         Gender = GenderRandomizer.GetRandomGender();
  95.     }
  96.  
  97.     public string Name { get; private set; }
  98.     public string Gender { get; private set; }
  99.     public string Sound { get; private set; }
  100.  
  101.     public virtual Animal Clone()
  102.     {
  103.         return new Animal(Name, Sound);
  104.     }
  105. }
  106.  
  107. class Monkey : Animal
  108. {
  109.     public override Animal Clone()
  110.     {
  111.         return new Monkey();
  112.     }
  113.  
  114.     public Monkey() : base("Обезьяна", "Ухахахах уа") { }
  115. }
  116.  
  117. class Elephant : Animal
  118. {
  119.     public override Animal Clone()
  120.     {
  121.         return new Elephant();
  122.     }
  123.  
  124.     public Elephant() : base("Слон", "Трубит") { }
  125. }
  126.  
  127. class Giraffe : Animal
  128. {
  129.     public override Animal Clone()
  130.     {
  131.         return new Giraffe();
  132.     }
  133.  
  134.     public Giraffe() : base("Жираф", "Молчит") { }
  135. }
  136.  
  137. class Bird : Animal
  138. {
  139.     public override Animal Clone()
  140.     {
  141.         return new Bird();
  142.     }
  143.  
  144.     public Bird() : base("Птица", "Курлык") { }
  145. }
  146.  
  147. class GenderRandomizer
  148. {
  149.     private static Random _random = new Random();
  150.  
  151.     public static string GetRandomGender()
  152.     {
  153.         string[] genders = { "Женский", "Мужской" };
  154.  
  155.         int randomIndex = _random.Next(genders.Length);
  156.         return genders[randomIndex];
  157.     }
  158. }
  159.  
  160. class Utils
  161. {
  162.     public static int ConvertToInt()
  163.     {
  164.         int templateNumber;
  165.         string userInput = string.Empty;
  166.  
  167.         while (int.TryParse(userInput, out templateNumber) == false)
  168.         {
  169.             Console.WriteLine("Введите номер вальера:");
  170.             userInput = Console.ReadLine();
  171.         }
  172.  
  173.         return templateNumber;
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment