Advertisement
vovanhik_24

#49

Jan 12th, 2025 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. namespace ConsoleApp4
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. namespace ZooApp
  8. {
  9. public class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Zoo zoo = new Zoo();
  14. zoo.Run();
  15. }
  16. }
  17.  
  18. public enum Genders
  19. {
  20. Male,
  21. Female,
  22. }
  23.  
  24. public class Animal
  25. {
  26. public Animal(string sound)
  27. {
  28. Sound = sound;
  29. CreateRandomGender();
  30. }
  31.  
  32. public string Sound { get; private set; }
  33. public Genders Gender { get; private set; }
  34.  
  35. private void CreateRandomGender()
  36. {
  37. Genders gender = (Genders)UserUtils.GenerateRandom(1);
  38. Gender = gender;
  39. }
  40. }
  41.  
  42. public class Aviary
  43. {
  44. private readonly List<Animal> _animals;
  45.  
  46. public Aviary(string name, List<Animal> animals)
  47. {
  48. Name = name;
  49. _animals = animals;
  50. }
  51.  
  52. public string Name { get; private set; }
  53.  
  54. public void DisplayInfo()
  55. {
  56. Console.WriteLine($"Вольер: {Name}");
  57. Console.WriteLine($"Количество животных: {_animals.Count}");
  58. Console.WriteLine("Информация о животных:");
  59.  
  60. foreach (Animal animal in _animals)
  61. {
  62. Console.WriteLine($"- Пол: {animal.Gender}, Звук: {animal.Sound}");
  63. }
  64. }
  65. }
  66.  
  67. class AviaryCreator
  68. {
  69. private readonly List<Aviary> _aviarys;
  70.  
  71. public AviaryCreator()
  72. {
  73. _aviarys = new List<Aviary>();
  74. InitializeEnclosures();
  75. }
  76.  
  77. public List<Aviary> GetAviaries()
  78. {
  79. return _aviarys.ToList();
  80. }
  81.  
  82. private void InitializeEnclosures()
  83. {
  84. List<Animal> animalType = CreateAnimalType();
  85.  
  86. _aviarys.Add(new Aviary("Львиный вольер", AnimalCreate.CreateAnimals(5, animalType[0])));
  87. _aviarys.Add(new Aviary("Крокодилий вольер", AnimalCreate.CreateAnimals(4, animalType[1])));
  88. _aviarys.Add(new Aviary("Обезьяний вольер", AnimalCreate.CreateAnimals(6, animalType[2])));
  89. _aviarys.Add(new Aviary("Вольер с хищными птицами", AnimalCreate.CreateAnimals(8, animalType[3])));
  90. }
  91.  
  92. private List<Animal> CreateAnimalType()
  93. {
  94. List<Animal> animalsTypes = new List<Animal>
  95. {
  96. new Animal("Roar"),
  97. new Animal("Growl"),
  98. new Animal("Laugh"),
  99. new Animal("Squeak")
  100. };
  101.  
  102. return animalsTypes;
  103. }
  104. }
  105.  
  106. public class AnimalCreate
  107. {
  108. public static List<Animal> CreateAnimals(int count, Animal prototype)
  109. {
  110. List<Animal> animals = new List<Animal>();
  111.  
  112. for (int i = 0; i < count; i++)
  113. {
  114. animals.Add(new Animal(prototype.Sound));
  115. }
  116.  
  117. return animals;
  118. }
  119. }
  120.  
  121. public class Zoo
  122. {
  123. private readonly AviaryCreator _aviaryCreator;
  124. private readonly List<Aviary> _aviarysList;
  125.  
  126. public Zoo()
  127. {
  128. _aviaryCreator = new AviaryCreator();
  129. _aviarysList = _aviaryCreator.GetAviaries();
  130. }
  131.  
  132. public void Run()
  133. {
  134. const int ExitCommand = 0;
  135.  
  136. bool isWorking = true;
  137.  
  138. while (isWorking)
  139. {
  140. Console.Clear();
  141. Console.WriteLine("Выберите вольер, к которому вы хотите подойти:\n");
  142.  
  143. for (int i = 0; i < _aviarysList.Count; i++)
  144. {
  145. Console.WriteLine($"{i + 1}. {_aviarysList[i].Name}");
  146. }
  147.  
  148. Console.WriteLine($"\n{ExitCommand}. Выход");
  149. Console.Write("\nВведите номер: ");
  150.  
  151. if (int.TryParse(Console.ReadLine(), out int choice))
  152. {
  153. if (choice == ExitCommand)
  154. {
  155. isWorking = false;
  156. }
  157. else if (choice >= 1 && choice <= _aviarysList.Count)
  158. {
  159. Console.Clear();
  160. Aviary selectedEnclosure = _aviarysList[choice - 1];
  161. selectedEnclosure.DisplayInfo();
  162. Console.WriteLine("Нажмите Enter, чтобы вернуться в меню.");
  163. Console.ReadLine();
  164. }
  165. else
  166. {
  167. Console.WriteLine("Неверный выбор. Попробуйте еще раз.");
  168. Console.ReadLine();
  169. }
  170. }
  171. else
  172. {
  173. Console.WriteLine("Некорректный ввод. Пожалуйста, введите число.");
  174. Console.ReadLine();
  175. }
  176. }
  177. }
  178. }
  179.  
  180. class UserUtils
  181. {
  182. private static Random s_random = new Random();
  183.  
  184. public static int GenerateRandom(int maxValue, int minValue = 0)
  185. {
  186. return s_random.Next(minValue, maxValue + 1);
  187. }
  188. }
  189. }
  190. }
  191.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement