Skip to content

Instantly share code, notes, and snippets.

@Dnk095
Created July 3, 2024 03:42
Show Gist options
  • Save Dnk095/8369bdf7fc06acd5ebf537a935d7494e to your computer and use it in GitHub Desktop.
Save Dnk095/8369bdf7fc06acd5ebf537a935d7494e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
namespace _6_12
{
internal class Program
{
static void Main()
{
Zoo zoo = new Zoo();
zoo.Work();
}
}
class Animal
{
public Animal(string className, string sound,string name="bob", string sex = "male")
{
Sex = sex;
ClassName = className;
Sound = sound;
Name = name;
}
public string Name { get;}
public string Sex { get; }
public string ClassName { get; }
public string Sound { get; }
}
class Aviary
{
private List<Animal> _animals;
public Aviary(Animal animal, int maxQuantityAnimal = 5)
{
_animals = new List<Animal>();
MaxQuantityAnimal = maxQuantityAnimal;
Fill(animal);
}
public int MaxQuantityAnimal { get; }
public List<Animal> GetAnimalsList()
{
return _animals;
}
public void ShowAllAnimals()
{
if (_animals.Count > 0)
{
Console.WriteLine($"В вольере {_animals.Count} животных, они издает звук {_animals[0].Sound}");
foreach (Animal animal in _animals)
{
Console.WriteLine($"{animal.Name} - {animal.Sex}");
}
}
else
{
Console.WriteLine("Нет животных в вольере");
}
}
private void Fill(Animal animal)
{
List<string> nameList = new List<string>
{
"Bob","Jack","Tiny","Axe","Jon","Bane","Kriss","Troll","Titan","Boss"
};
int maxValueForRandomSex = 1;
int quantityAnimals = Utils.GetRandom(MaxQuantityAnimal + 1);
string sex;
bool sexBoolean;
for (int i = 0; i < quantityAnimals; i++)
{
string name = nameList[Utils.GetRandom(nameList.Count)];
sexBoolean = Convert.ToBoolean(Utils.GetRandom(maxValueForRandomSex + 1));
if (sexBoolean)
sex = "male";
else
sex = "famale";
_animals.Add(new Animal(animal.ClassName, animal.Sound,name, sex));
}
}
}
class Zoo
{
private List<Aviary> _aviarys;
public Zoo()
{
_aviarys = new List<Aviary>();
FillAviary();
}
public void Work()
{
string inputData;
bool working = true;
while (working)
{
Console.WriteLine("Выберете какоq вольер посмотреть или введите exit для выхода ");
ShowAllAviary();
inputData = Console.ReadLine();
if (inputData == "exit")
return;
if (int.TryParse(inputData, out int number) == false || number < 1 || number > _aviarys.Count)
{
Console.WriteLine("Введен некоректный номер");
Console.ReadKey();
Console.Clear();
continue;
}
DrowInfoAviary(number - 1);
Console.ReadKey();
Console.Clear();
}
}
private void FillAviary()
{
_aviarys.Add(new Aviary(new Animal("Собака", "Гав"), 3));
_aviarys.Add(new Aviary(new Animal("Кошка", "Мяу"), 4));
_aviarys.Add(new Aviary(new Animal("Обезьяна", "Уууу уу "), 7));
_aviarys.Add(new Aviary(new Animal("Тигр", "РРррр"), 6));
}
private void DrowInfoAviary(int number)
{
List<Animal> animals = _aviarys[number].GetAnimalsList();
if (animals.Count > 0)
{
Console.WriteLine($"В этом вольере сидят {animals[0].ClassName}");
_aviarys[number].ShowAllAnimals();
}
else
{
Console.WriteLine("В этом вольере нет животных");
}
}
private void ShowAllAviary()
{
for (int i = 0; i < _aviarys.Count; i++)
{
Console.WriteLine($"{i + 1} - вольер ");
}
}
}
static class Utils
{
private static Random s_random;
static Utils()
{
s_random = new Random();
}
public static int GetRandom(int maxValue, int minValue = 0)
{
return s_random.Next(minValue, maxValue);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment