Advertisement
TwinFrame

ZOO ver3

Mar 9th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Clight_27_OOP_Zoo
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Animal[] foxVolyer = new Animal[] { new Fox("Рыжуля", 'Ж', 5), new Fox("Хитрюгин", 'М', 9), new Fox("Леся", 'Ж', 1) };
  10. Animal[] bearVolyer = new Animal[] { new Bear("Папаша", 'М', 7), new Bear("Мамаша", 'Ж', 6) };
  11. Animal[] eagleVolyer = new Animal[] { new Eagle("Зорька", 'М', 25), new Eagle("Орешек", 'М', 3), new Eagle("Перлина", 'Ж', 5) };
  12. Animal[] snakeVolyer = new Animal[] { new Snake("Шнура", 'Ж', 2) };
  13.  
  14. Volyer volyer1 = new Volyer("Дикие животные (Лисы)", foxVolyer);
  15. Volyer volyer2 = new Volyer("Дикие животные (Медведи)", bearVolyer);
  16. Volyer volyer3 = new Volyer("Дикие птицы (Орлы)", eagleVolyer);
  17. Volyer volyer4 = new Volyer("Террариум", snakeVolyer);
  18.  
  19. Zoo zoo = new Zoo("Зооландия", new Volyer[] { volyer1, volyer2, volyer3, volyer4 });
  20.  
  21. while (true)
  22. {
  23. Console.CursorVisible = false;
  24.  
  25. Console.WriteLine($"Добро пожаловать в зоопарк \"{zoo.nameZoo}\"!\n");
  26. Console.WriteLine("Вольеры зоопарка:");
  27. zoo.ShowZoo();
  28.  
  29. int sumRowMainMenu = zoo.LengthVolyers() + 3;
  30. int lengthVolyers = zoo.LengthVolyers();
  31. int userInput = CheckUserInput(sumRowMainMenu, lengthVolyers);
  32. Console.Clear();
  33.  
  34. zoo.volyers[userInput - 1].ShowVolyer();
  35. Console.WriteLine("\nПосле просмотра нажмите любую клавишу.");
  36. Console.ReadKey(true);
  37. Console.Clear();
  38. }
  39. }
  40. public static int CheckUserInput(int sumRowMainMenu, int lengthVolyers)
  41. {
  42. bool isChecking;
  43. bool isCheckingCycle = true;
  44. int input = 0;
  45.  
  46. while (isCheckingCycle)
  47. {
  48. Console.SetCursorPosition(0, sumRowMainMenu);
  49. Console.Write("\nДля ознакомления с животными выберете номер вольера:");
  50.  
  51. string userInput = Console.ReadLine();
  52. isChecking = Int32.TryParse(userInput, out int value);
  53. if (isChecking && value >= 1 && value <= lengthVolyers)
  54. {
  55. input = value;
  56. isCheckingCycle = false;
  57. }
  58. else
  59. {
  60. Console.WriteLine("Не корректный номер вольера. Нажмите цифру от 1 до " + lengthVolyers + ".");
  61. Console.ReadKey(true);
  62. Console.SetCursorPosition(0, sumRowMainMenu + 1);
  63. Console.WriteLine(" ");
  64. Console.WriteLine(" ");
  65. }
  66. }
  67. return input;
  68. }
  69. }
  70. abstract class Animal
  71. {
  72. public string genus { get; private set; }
  73. public string name { get; private set; }
  74. public int age { get; private set; }
  75. public char sex { get; private set; }
  76. public string voice { get; private set; }
  77.  
  78. public Animal(string name, char sex, int age)
  79. {
  80. this.name = name;
  81. this.sex = sex;
  82. this.age = age;
  83. this.genus = SetGenius();
  84. this.voice = SetVoice();
  85. }
  86. protected abstract string SetVoice();
  87. protected abstract string SetGenius();
  88. public void ShowInfo()
  89. {
  90. Console.WriteLine($"Род: {genus}\n Имя: {name}\nПол: {sex}\nВозраст: {age}\nЗвук: {voice}");
  91. }
  92. public void ShowCutInfo()
  93. {
  94. Console.WriteLine($"Имя: {name}\nПол: {sex}\nВозраст: {age}");
  95. }
  96. }
  97. class Fox : Animal
  98. {
  99. protected string genusAnimal = "Лисицы";
  100. protected string voiceAnimal = "Шшшш";
  101. public Fox(string name, char sex, int age) : base(name, sex, age)
  102. { }
  103. protected override string SetGenius()
  104. {
  105. return genusAnimal;
  106. }
  107. protected override string SetVoice()
  108. {
  109. return voiceAnimal;
  110. }
  111. }
  112. class Bear : Animal
  113. {
  114. protected string genusAnimal = "Медведи";
  115. protected string voiceAnimal = "Грраах";
  116. public Bear(string name, char sex, int age) : base(name, sex, age)
  117. { }
  118. protected override string SetGenius()
  119. {
  120. return genusAnimal;
  121. }
  122. protected override string SetVoice()
  123. {
  124. return voiceAnimal;
  125. }
  126. }
  127. class Eagle : Animal
  128. {
  129. protected string genusAnimal = "Орлы";
  130. protected string voiceAnimal = "Ааии";
  131. public Eagle(string name, char sex, int age) : base(name, sex, age)
  132. { }
  133. protected override string SetGenius()
  134. {
  135. return genusAnimal;
  136. }
  137. protected override string SetVoice()
  138. {
  139. return voiceAnimal;
  140. }
  141. }
  142. class Snake : Animal
  143. {
  144. protected string genusAnimal = "Змеи";
  145. protected string voiceAnimal = "Ссшсс";
  146. public Snake(string name, char sex, int age) : base(name, sex, age)
  147. { }
  148. protected override string SetGenius()
  149. {
  150. return genusAnimal;
  151. }
  152. protected override string SetVoice()
  153. {
  154. return voiceAnimal;
  155. }
  156. }
  157. class Zoo
  158. {
  159. public string nameZoo;
  160. public Volyer[] volyers { get; private set; }
  161.  
  162. public Zoo(string nameZoo, Volyer[] volyers)
  163. {
  164. this.nameZoo = nameZoo;
  165. this.volyers = volyers;
  166. }
  167.  
  168. public void ShowZoo()
  169. {
  170. for (int i = 0; i < volyers.Length; i++)
  171. {
  172. Console.WriteLine($"{i + 1} - {volyers[i].nameVolyer}");
  173. }
  174. }
  175. public int LengthVolyers()
  176. {
  177. int sumVolyers = volyers.Length;
  178. return sumVolyers;
  179. }
  180. }
  181. class Volyer
  182. {
  183. public string nameVolyer { get; private set; }
  184. public Animal[] zoo { get; private set; }
  185.  
  186. public Volyer(string nameVolyer, Animal[] animals)
  187. {
  188. this.nameVolyer = nameVolyer;
  189. this.zoo = animals;
  190. }
  191.  
  192. public void ShowVolyer()
  193. {
  194. Console.WriteLine($"Вольер - {nameVolyer}\n\nРод - {zoo[0].genus}\nХарактерный звук - {zoo[0].voice}\nКол-во животных - {zoo.Length}\n\n");
  195. for (int i = 0; i < zoo.Length; i++)
  196. {
  197. zoo[i].ShowCutInfo();
  198. Console.WriteLine();
  199. }
  200. }
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement