Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Clight_27_OOP_Zoo
- {
- class Program
- {
- static void Main(string[] args)
- {
- Animal fox1 = new Fox("Рыжуля", 'Ж', 5);
- Animal fox2 = new Fox("Хитрюгин", 'М', 9);
- Animal fox3 = new Fox("Леся", 'Ж', 1);
- Animal bear1 = new Bear("Папаша", 'М', 7);
- Animal bear2 = new Bear("Мамаша", 'Ж', 6);
- Animal eagle1 = new Eagle("Зорька", 'М', 25);
- Animal eagle2 = new Eagle("Орешек", 'М', 3);
- Animal eagle3 = new Eagle("Перлина", 'Ж', 5);
- Animal snake1 = new Snake("Шнура", 'Ж', 2);
- Volyer volyer1 = new Volyer("Дикие животные (Лисы)", new Animal[] { fox1, fox2 });
- Volyer volyer2 = new Volyer("Дикие животные (Медведи)", new Animal[] { bear1, bear2 });
- Volyer volyer3 = new Volyer("Дикие птицы (Орлы)", new Animal[] { eagle1, eagle2, eagle3 });
- Volyer volyer4 = new Volyer("Террариум", new Animal[] { snake1 });
- Volyer volyer5 = new Volyer("Террариум2", new Animal[] { snake1, snake1 });
- Zoo volyers = new Zoo("Зооландия", new Volyer[] { volyer1, volyer2, volyer3, volyer4 });
- while (true)
- {
- Console.CursorVisible = false;
- Console.WriteLine($"Добро пожаловать в зоопарк \"{volyers.nameZoo}\"!\n");
- Console.WriteLine("Вольеры зоопарка:");
- volyers.ShowZoo();
- /*Console.WriteLine("Для выхода нажмите F5.");*/
- int sumRowMainMenu = volyers.LengthVolyers() + 3;
- int lengthVolyers = volyers.LengthVolyers();
- int userInput = CheckUserInput(sumRowMainMenu, lengthVolyers);
- Console.Clear();
- volyers.volyers[userInput - 1].ShowVolyer();
- Console.WriteLine("После просмотра нажмите любую клавишу.");
- Console.ReadKey(true);
- Console.Clear();
- }
- }
- public static int CheckUserInput(int sumRowMainMenu, int lengthVolyers)
- {
- bool isChecking;
- bool isCheckingCycle = true;
- int input = 0;
- while (isCheckingCycle)
- {
- Console.SetCursorPosition(0, sumRowMainMenu);
- Console.Write("\nДля ознакомления с животными выберете номер вольера:");
- string userInput = Console.ReadLine();
- isChecking = Int32.TryParse(userInput, out int value);
- if (isChecking && value >= 1 && value <= lengthVolyers)
- {
- input = value;
- isCheckingCycle = false;
- }
- else
- {
- Console.WriteLine("Не корректный номер вольера. Нажмите цифру от 1 до " + lengthVolyers + ".");
- Console.ReadKey(true);
- Console.SetCursorPosition(0, sumRowMainMenu + 1);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- }
- }
- return input;
- }
- }
- class Animal
- {
- public string genus { get; private set; }
- public string name { get; private set; }
- public int age { get; private set; }
- public char sex { get; private set; }
- public string voice { get; private set; }
- public Animal(string name, char sex, int age, string genus, string voice)
- {
- this.name = name;
- this.sex = sex;
- this.age = age;
- this.genus = genus;
- this.voice = voice;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Род: {genus}\n Имя: {name}\nПол: {sex}\nВозраст: {age}\nЗвук: {voice}");
- }
- public void ShowCutInfo()
- {
- Console.WriteLine($"Имя: {name}\nПол: {sex}\nВозраст: {age}");
- }
- }
- class Fox : Animal
- {
- public Fox(string name, char sex, int age, string genus = "Лисицы", string voice = "Шшшш") : base(name, sex, age, genus, voice)
- { }
- }
- class Bear : Animal
- {
- public Bear(string name, char sex, int age, string genus = "Медведи", string voice = "Грраах") : base(name, sex, age, genus, voice)
- { }
- }
- class Eagle : Animal
- {
- public Eagle(string name, char sex, int age, string genus = "Орлы", string voice = "Ааии") : base(name, sex, age, genus, voice)
- { }
- }
- class Snake : Animal
- {
- public Snake(string name, char sex, int age, string genus = "Змеи", string voice = "Ссшсс") : base(name, sex, age, genus, voice)
- { }
- }
- class Zoo
- {
- public string nameZoo;
- public Volyer[] volyers { get; private set; }
- public Zoo(string nameZoo, Volyer[] volyers)
- {
- this.nameZoo = nameZoo;
- this.volyers = volyers;
- }
- public void ShowZoo()
- {
- for (int i = 0; i < volyers.Length; i++)
- {
- Console.WriteLine($"{i + 1} - {volyers[i].nameVolyer}");
- }
- }
- public int LengthVolyers()
- {
- int sumVolyers = volyers.Length;
- return sumVolyers;
- }
- }
- class Volyer
- {
- public string nameVolyer { get; private set; }
- public Animal[] zoo { get; private set; }
- public Volyer(string nameVolyer, Animal[] animals)
- {
- this.nameVolyer = nameVolyer;
- this.zoo = animals;
- }
- public void ShowVolyer()
- {
- Console.WriteLine($"Вольер - {nameVolyer}\nРод - {zoo[0].genus}\nХарактерный звук - {zoo[0].voice}\nКол-во животных - {zoo.Length}\n");
- for (int i = 0; i < zoo.Length; i++)
- {
- zoo[i].ShowCutInfo();
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement