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[] foxVolyer = new Animal[] { new Fox("Рыжуля", 'Ж', 5), new Fox("Хитрюгин", 'М', 9), new Fox("Леся", 'Ж', 1) };
- Animal[] bearVolyer = new Animal[] { new Bear("Папаша", 'М', 7), new Bear("Мамаша", 'Ж', 6) };
- Animal[] eagleVolyer = new Animal[] { new Eagle("Зорька", 'М', 25), new Eagle("Орешек", 'М', 3), new Eagle("Перлина", 'Ж', 5) };
- Animal[] snakeVolyer = new Animal[] { new Snake("Шнура", 'Ж', 2) };
- Volyer volyer1 = new Volyer("Дикие животные (Лисы)", foxVolyer);
- Volyer volyer2 = new Volyer("Дикие животные (Медведи)", bearVolyer);
- Volyer volyer3 = new Volyer("Дикие птицы (Орлы)", eagleVolyer);
- Volyer volyer4 = new Volyer("Террариум", snakeVolyer);
- Zoo zoo = new Zoo("Зооландия", new Volyer[] { volyer1, volyer2, volyer3, volyer4 });
- while (true)
- {
- Console.CursorVisible = false;
- Console.WriteLine($"Добро пожаловать в зоопарк \"{zoo.nameZoo}\"!\n");
- Console.WriteLine("Вольеры зоопарка:");
- zoo.ShowZoo();
- int sumRowMainMenu = zoo.LengthVolyers() + 3;
- int lengthVolyers = zoo.LengthVolyers();
- int userInput = CheckUserInput(sumRowMainMenu, lengthVolyers);
- Console.Clear();
- zoo.volyers[userInput - 1].ShowVolyer();
- Console.WriteLine("\nПосле просмотра нажмите любую клавишу.");
- 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;
- }
- }
- abstract 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)
- {
- this.name = name;
- this.sex = sex;
- this.age = age;
- this.genus = SetGenius();
- this.voice = SetVoice();
- }
- protected abstract string SetVoice();
- protected abstract string SetGenius();
- 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
- {
- protected string genusAnimal = "Лисицы";
- protected string voiceAnimal = "Шшшш";
- public Fox(string name, char sex, int age) : base(name, sex, age)
- { }
- protected override string SetGenius()
- {
- return genusAnimal;
- }
- protected override string SetVoice()
- {
- return voiceAnimal;
- }
- }
- class Bear : Animal
- {
- protected string genusAnimal = "Медведи";
- protected string voiceAnimal = "Грраах";
- public Bear(string name, char sex, int age) : base(name, sex, age)
- { }
- protected override string SetGenius()
- {
- return genusAnimal;
- }
- protected override string SetVoice()
- {
- return voiceAnimal;
- }
- }
- class Eagle : Animal
- {
- protected string genusAnimal = "Орлы";
- protected string voiceAnimal = "Ааии";
- public Eagle(string name, char sex, int age) : base(name, sex, age)
- { }
- protected override string SetGenius()
- {
- return genusAnimal;
- }
- protected override string SetVoice()
- {
- return voiceAnimal;
- }
- }
- class Snake : Animal
- {
- protected string genusAnimal = "Змеи";
- protected string voiceAnimal = "Ссшсс";
- public Snake(string name, char sex, int age) : base(name, sex, age)
- { }
- protected override string SetGenius()
- {
- return genusAnimal;
- }
- protected override string SetVoice()
- {
- return voiceAnimal;
- }
- }
- 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\nРод - {zoo[0].genus}\nХарактерный звук - {zoo[0].voice}\nКол-во животных - {zoo.Length}\n\n");
- for (int i = 0; i < zoo.Length; i++)
- {
- zoo[i].ShowCutInfo();
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement