Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Win32.SafeHandles;
- using System;
- using System.ComponentModel;
- using System.Data;
- namespace Зоопарк
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Zoo zoo = new Zoo();
- zoo.Work();
- }
- }
- class Zoo
- {
- private List<Aviary> _aviaries = new List<Aviary>();
- public Zoo()
- {
- _aviaries.Add(new Aviary("Лев", "Рык"));
- _aviaries.Add(new Aviary("Волк", "Вой"));
- _aviaries.Add(new Aviary("Обезьяна", "Крик"));
- _aviaries.Add(new Aviary("Слон", "Рёв"));
- }
- public void Work()
- {
- bool isOpen = true;
- while (isOpen)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Зоопарк «Лимпопо»\n\n");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Доступные вольеры с животными:");
- for (int i = 0; i < _aviaries.Count; i++)
- {
- Console.WriteLine($"{i + 1} - {_aviaries[i].Name}");
- }
- Console.WriteLine("\nВыбери вольер:");
- int userInput = (Utility.ReturnInputNumber() - 1);
- if (userInput < 0 || userInput >= _aviaries.Count)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("\nНет такой команды\n");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Нажми любую клавишу...");
- Console.ReadKey();
- Console.Clear();
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.WriteLine("\nЖивотные в вольере:\n");
- Console.ForegroundColor = ConsoleColor.White;
- _aviaries[userInput].ShowAnimal();
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Console.WriteLine("\nНажми любую клавишу, что бы выбрать вольер");
- Console.ForegroundColor = ConsoleColor.White;
- Console.ReadKey();
- Console.Clear();
- }
- }
- }
- }
- class Aviary
- {
- private List<Animal> _animals = new List<Animal>();
- public Aviary(string genus, string sound)
- {
- FillAviary(genus, sound);
- }
- public string Name => _animals.First().Genus;
- public void ShowAnimal()
- {
- foreach (var animal in _animals)
- {
- Console.WriteLine($"Животное - {animal.Genus} || Издает звук - {animal.Sound} || Пол - {animal.Gender}");
- }
- }
- private void FillAviary(string genus, string sound)
- {
- CreateAnimals(genus, sound);
- }
- private void CreateAnimals(string genus, string sound)
- {
- int minAnimalsInAviary = 1;
- int maxAnimalsInAviary = 4;
- int quantityAnimals = Utility.GenerateRandomNumber(minAnimalsInAviary, maxAnimalsInAviary + 1);
- for (int i = 0; i < quantityAnimals; i++)
- {
- _animals.Add(new Animal(genus, sound));
- }
- }
- }
- class Animal
- {
- public Animal(string genus, string sound)
- {
- Genus = genus;
- Gender = GenerateGender();
- Sound = sound;
- }
- public string Genus { get; private set; }
- public string Gender { get; private set; }
- public string Sound { get; private set; }
- private string GenerateGender()
- {
- string[] genders = { "male", "female" };
- int randomNumber = Utility.GenerateRandomNumber(genders.Length);
- return genders[randomNumber];
- }
- }
- class Utility
- {
- private static Random s_random = new Random();
- public static int GenerateRandomNumber(int min, int max)
- {
- return s_random.Next(min, max);
- }
- public static int GenerateRandomNumber(int number)
- {
- return s_random.Next(number);
- }
- public static int ReturnInputNumber()
- {
- int number;
- while (int.TryParse(Console.ReadLine(), out number) == false)
- {
- Console.WriteLine("Введено не число, попробуйте еще раз: ");
- }
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement