Advertisement
TwinFrame

ZOO ver2

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