Advertisement
TwinFrame

ZOO ver1

Mar 6th, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 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. /*Console.WriteLine("Для выхода нажмите F5.");*/
  36.  
  37. int sumRowMainMenu = volyers.LengthVolyers() + 3;
  38. int lengthVolyers = volyers.LengthVolyers();
  39. int userInput = CheckUserInput(sumRowMainMenu, lengthVolyers);
  40. Console.Clear();
  41.  
  42. volyers.volyers[userInput - 1].ShowVolyer();
  43. Console.WriteLine("После просмотра нажмите любую клавишу.");
  44. Console.ReadKey(true);
  45. Console.Clear();
  46. }
  47. }
  48. public static int CheckUserInput(int sumRowMainMenu, int lengthVolyers)
  49. {
  50. bool isChecking;
  51. bool isCheckingCycle = true;
  52. int input = 0;
  53.  
  54. while (isCheckingCycle)
  55. {
  56. Console.SetCursorPosition(0, sumRowMainMenu);
  57. Console.Write("\nДля ознакомления с животными выберете номер вольера:");
  58.  
  59. string userInput = Console.ReadLine();
  60. isChecking = Int32.TryParse(userInput, out int value);
  61. if (isChecking && value >= 1 && value <= lengthVolyers)
  62. {
  63. input = value;
  64. isCheckingCycle = false;
  65. }
  66. else
  67. {
  68. Console.WriteLine("Не корректный номер вольера. Нажмите цифру от 1 до " + lengthVolyers + ".");
  69. Console.ReadKey(true);
  70. Console.SetCursorPosition(0, sumRowMainMenu + 1);
  71. Console.WriteLine(" ");
  72. Console.WriteLine(" ");
  73. }
  74. }
  75. return input;
  76. }
  77. }
  78. class Animal
  79. {
  80. public string genus { get; private set; }
  81. public string name { get; private set; }
  82. public int age { get; private set; }
  83. public char sex { get; private set; }
  84. public string voice { get; private set; }
  85.  
  86. public Animal(string name, char sex, int age, string genus, string voice)
  87. {
  88. this.name = name;
  89. this.sex = sex;
  90. this.age = age;
  91. this.genus = genus;
  92. this.voice = voice;
  93. }
  94.  
  95. public void ShowInfo()
  96. {
  97. Console.WriteLine($"Род: {genus}\n Имя: {name}\nПол: {sex}\nВозраст: {age}\nЗвук: {voice}");
  98. }
  99.  
  100. public void ShowCutInfo()
  101. {
  102. Console.WriteLine($"Имя: {name}\nПол: {sex}\nВозраст: {age}");
  103. }
  104.  
  105. }
  106. class Fox : Animal
  107. {
  108. public Fox(string name, char sex, int age, string genus = "Лисицы", string voice = "Шшшш") : base(name, sex, age, genus, voice)
  109. { }
  110. }
  111.  
  112. class Bear : Animal
  113. {
  114. public Bear(string name, char sex, int age, string genus = "Медведи", string voice = "Грраах") : base(name, sex, age, genus, voice)
  115. { }
  116. }
  117.  
  118. class Eagle : Animal
  119. {
  120. public Eagle(string name, char sex, int age, string genus = "Орлы", string voice = "Ааии") : base(name, sex, age, genus, voice)
  121. { }
  122. }
  123.  
  124. class Snake : Animal
  125. {
  126. public Snake(string name, char sex, int age, string genus = "Змеи", string voice = "Ссшсс") : base(name, sex, age, genus, voice)
  127. { }
  128. }
  129.  
  130. class Zoo
  131. {
  132. public string nameZoo;
  133. public Volyer[] volyers { get; private set; }
  134.  
  135. public Zoo(string nameZoo, Volyer[] volyers)
  136. {
  137. this.nameZoo = nameZoo;
  138. this.volyers = volyers;
  139. }
  140.  
  141. public void ShowZoo()
  142. {
  143. for (int i = 0; i < volyers.Length; i++)
  144. {
  145. Console.WriteLine($"{i + 1} - {volyers[i].nameVolyer}");
  146. }
  147. }
  148. public int LengthVolyers()
  149. {
  150. int sumVolyers = volyers.Length;
  151. return sumVolyers;
  152. }
  153. }
  154. class Volyer
  155. {
  156. public string nameVolyer { get; private set; }
  157. public Animal[] zoo { get; private set; }
  158.  
  159. public Volyer(string nameVolyer, Animal[] animals)
  160. {
  161. this.nameVolyer = nameVolyer;
  162. this.zoo = animals;
  163. }
  164.  
  165. public void ShowVolyer()
  166. {
  167. Console.WriteLine($"Вольер - {nameVolyer}\nРод - {zoo[0].genus}\nХарактерный звук - {zoo[0].voice}\nКол-во животных - {zoo.Length}\n");
  168. for (int i = 0; i < zoo.Length; i++)
  169. {
  170. zoo[i].ShowCutInfo();
  171. Console.WriteLine();
  172. }
  173. }
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement