Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CLights
- {
- class Program
- {
- public static void Main()
- {
- new Zoo().Work();
- }
- }
- public static class RandomStatic
- {
- static private Random _rand = new Random();
- static public int GetNext(int min, int max)
- {
- return _rand.Next(min, max);
- }
- }
- public static class Messager
- {
- static public void ShowMessageWithColor(string message, ConsoleColor color, bool delay)
- {
- ConsoleColor defaultColor = Console.ForegroundColor;
- Console.ForegroundColor = color;
- Console.WriteLine(message);
- Console.ForegroundColor = defaultColor;
- if (delay)
- Console.ReadKey();
- }
- }
- class Zoo
- {
- private List<Aviary> _aviaries = new List<Aviary>();
- private Aviary _activeAviray;
- public Zoo()
- {
- for (int i = 0; i < 13; i++)
- {
- _aviaries.Add(new Aviary($"Номер:{i}"));
- }
- }
- public void Work()
- {
- bool isOpen = true;
- while (isOpen)
- {
- Console.Clear();
- ShowInfo();
- if (_activeAviray == null)
- {
- Console.WriteLine("\n1 - Подойти к вольеру \nEsc - Выйти из программы");
- switch (Console.ReadKey(true).Key)
- {
- case ConsoleKey.D1:
- ComeUp();
- break;
- case ConsoleKey.Escape:
- isOpen = false;
- break;
- }
- }
- else
- {
- Console.WriteLine("\nEsc - Отойти от вольера");
- switch (Console.ReadKey(true).Key)
- {
- case ConsoleKey.Escape:
- MoveAway();
- break;
- }
- }
- }
- }
- private void ComeUp()
- {
- Console.Write("Введите индекс вольера, к которому хотите подойте: ");
- int index = Convert.ToInt32(Console.ReadLine());
- if (index < 0)
- index = 0;
- if (index >= _aviaries.Count)
- index = _aviaries.Count - 1;
- _activeAviray = _aviaries[index];
- }
- private void MoveAway()
- {
- _activeAviray = null;
- }
- private void ShowInfo()
- {
- if (_activeAviray == null)
- {
- Messager.ShowMessageWithColor($"Вы находитесь в запораке. В нем есть следующие вольеры: ", ConsoleColor.Magenta, false);
- for (int i = 0; i < _aviaries.Count; i++)
- {
- _aviaries[i].ShowSimpelInfo(i);
- }
- }
- else
- {
- _activeAviray.ShowDetailInfo();
- }
- }
- }
- class Aviary
- {
- public string Name { get; private set; }
- private List<Animal> _animals = new List<Animal>();
- public Aviary(string name)
- {
- Name = name;
- FillAviary();
- }
- public void ShowDetailInfo()
- {
- Messager.ShowMessageWithColor($"Название вольера - {Name}\nВольер содержит {_animals.Count} животных", ConsoleColor.Yellow, false);
- for (int i = 0; i < _animals.Count; i++)
- {
- Messager.ShowMessageWithColor(_animals[i].GetInfo(), ConsoleColor.White, false);
- }
- }
- public void ShowSimpelInfo(int ordinalIndex)
- {
- Messager.ShowMessageWithColor($"{ordinalIndex}: Название вольера - {Name};", ConsoleColor.Yellow, false);
- }
- private void FillAviary()
- {
- int amountAnimal = RandomStatic.GetNext(2, 10);
- int chance = RandomStatic.GetNext(0, 5);
- for (int i = 0; i < amountAnimal; i++)
- {
- switch (chance)
- {
- case 0:
- _animals.Add(new Lion());
- break;
- case 1:
- _animals.Add(new Owl());
- break;
- case 2:
- _animals.Add(new Bear());
- break;
- case 3:
- _animals.Add(new Rabbit());
- break;
- case 4:
- _animals.Add(new Toucan());
- break;
- }
- }
- }
- }
- abstract class Animal
- {
- public string Volume { get; protected set; }
- private bool _isMale;
- public Animal()
- {
- _isMale = Convert.ToBoolean(RandomStatic.GetNext(0, 2));
- }
- virtual public string GetInfo()
- {
- if (_isMale)
- return $"Пол мужской. Издает звук \"{Volume}\"";
- else
- return $"Пол женский. Издает звук \"{Volume}\"";
- }
- }
- class Lion : Animal
- {
- public Lion() : base()
- {
- Volume = "Рр-р-р";
- }
- public override string GetInfo()
- {
- return "Лев - " + base.GetInfo();
- }
- }
- class Owl : Animal
- {
- public Owl() : base()
- {
- Volume = "Уфу-у-у... Угу-у-у";
- }
- public override string GetInfo()
- {
- return "Сова - " + base.GetInfo();
- }
- }
- class Bear : Animal
- {
- public Bear() : base()
- {
- Volume = "Ря-я-яв";
- }
- public override string GetInfo()
- {
- return "Медведь - " + base.GetInfo();
- }
- }
- class Rabbit : Animal
- {
- public Rabbit() : base()
- {
- Volume = "Хрум-хрум";
- }
- public override string GetInfo()
- {
- return "Кролик - " + base.GetInfo();
- }
- }
- class Toucan : Animal
- {
- public Toucan() : base()
- {
- Volume = "*Тук тук тук*";
- }
- public override string GetInfo()
- {
- return "Тукан - " + base.GetInfo();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement