Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- Zoo zoo = new Zoo();
- bool isWorking = true;
- while (isWorking)
- {
- Console.Clear();
- zoo.ShowVallier();
- }
- }
- }
- class Zoo
- {
- List<Valliere> Vallieres = new List<Valliere>();
- public Zoo()
- {
- Fill();
- }
- public void Fill()
- {
- Vallieres.Add(new Valliere(new Monkey(), "Обезьяны", 1));
- Vallieres.Add(new Valliere(new Elephant(), "Слоны", 2));
- Vallieres.Add(new Valliere(new Giraffe(), "Жирафы", 3));
- Vallieres.Add(new Valliere(new Bird(), "Птицы", 4));
- }
- public void ShowVallier()
- {
- Console.WriteLine("Добро пожаловать в зоопарк! К какому вальеру вы хотели бы подойти?");
- ShowInfo();
- int userInput = Utils.ConvertToInt();
- Console.Clear();
- for (int i = 0; i < Vallieres[userInput - 1]._animals.Count; i++)
- {
- Console.WriteLine($"{Vallieres[userInput - 1]._animals[i].Name}|{Vallieres[userInput - 1]._animals[i].Gender}|{Vallieres[userInput - 1]._animals[i].Sound}");
- }
- Console.ReadKey();
- }
- public void ShowInfo()
- {
- foreach (var valliere in Vallieres)
- {
- Console.WriteLine($"{valliere.IdentificationNumber}){valliere.Name}");
- }
- }
- }
- class Valliere
- {
- public List<Animal> _animals = new List<Animal>();
- public Valliere(Animal animal, string name, int identificationNumber)
- {
- IdentificationNumber = identificationNumber;
- Name = name;
- AddToValliere(animal);
- }
- public int IdentificationNumber { get; private set; }
- public string Name { get; private set; }
- public void AddToValliere(Animal animal)
- {
- int maxPlaces = 5;
- for (int i = 0; i < maxPlaces; i++)
- {
- _animals.Add(animal.Clone());
- }
- }
- }
- class Animal
- {
- public Animal(string name, string sound)
- {
- Name = name;
- Sound = sound;
- Gender = GenderRandomizer.GetRandomGender();
- }
- public string Name { get; private set; }
- public string Gender { get; private set; }
- public string Sound { get; private set; }
- public virtual Animal Clone()
- {
- return new Animal(Name, Sound);
- }
- }
- class Monkey : Animal
- {
- public override Animal Clone()
- {
- return new Monkey();
- }
- public Monkey() : base("Обезьяна", "Ухахахах уа") { }
- }
- class Elephant : Animal
- {
- public override Animal Clone()
- {
- return new Elephant();
- }
- public Elephant() : base("Слон", "Трубит") { }
- }
- class Giraffe : Animal
- {
- public override Animal Clone()
- {
- return new Giraffe();
- }
- public Giraffe() : base("Жираф", "Молчит") { }
- }
- class Bird : Animal
- {
- public override Animal Clone()
- {
- return new Bird();
- }
- public Bird() : base("Птица", "Курлык") { }
- }
- class GenderRandomizer
- {
- private static Random _random = new Random();
- public static string GetRandomGender()
- {
- string[] genders = { "Женский", "Мужской" };
- int randomIndex = _random.Next(genders.Length);
- return genders[randomIndex];
- }
- }
- class Utils
- {
- public static int ConvertToInt()
- {
- int templateNumber;
- string userInput = string.Empty;
- while (int.TryParse(userInput, out templateNumber) == false)
- {
- Console.WriteLine("Введите номер вальера:");
- userInput = Console.ReadLine();
- }
- return templateNumber;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment