Last active
July 30, 2023 14:17
-
-
Save ShamilAitov/e7b9ed13b9ab241d3cbff18df85d4e2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace ООП12Задание | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Zoo zoo = new Zoo(); | |
zoo.OpenMenu(); | |
} | |
} | |
class Zoo | |
{ | |
private List<Aviary> _aviaries = new List<Aviary>(); | |
public Zoo() | |
{ | |
AddAviaries(); | |
} | |
public void OpenMenu() | |
{ | |
int minNumberAviaries = 0; | |
bool isWork = true; | |
int aviaryIndex; | |
while (isWork == true) | |
{ | |
Console.WriteLine("Добро пожаловать в зоопарк!!!"); | |
ShowAviary(); | |
Console.Write("Выберите вольер: "); | |
aviaryIndex = GetNumber(); | |
if (aviaryIndex >= minNumberAviaries && aviaryIndex < _aviaries.Count) | |
{ | |
_aviaries[aviaryIndex].ShowAnimals(); | |
} | |
else | |
{ | |
Console.Write("Такого вольера нет!"); | |
} | |
Console.ReadKey(); | |
Console.Clear(); | |
} | |
} | |
private void ShowAviary() | |
{ | |
for (int i = 0; i < _aviaries.Count; i++) | |
{ | |
Console.Write("Вольер №" + (i)); | |
_aviaries[i].ShowInfo(); | |
} | |
} | |
private int GetNumber() | |
{ | |
int index; | |
while (int.TryParse(Console.ReadLine(), out index) == false) | |
{ | |
Console.WriteLine("Нужно ввести именно число!"); | |
} | |
return index; | |
} | |
private List<Animal> AddAnimals(string name, string roar) | |
{ | |
List<Animal> animals = new List<Animal>(); | |
int minNumberAnimals = 2; | |
int maxNumberAnimals = 7; | |
int numberAnimals = UserUtils.GetRandomNumber(minNumberAnimals, maxNumberAnimals); | |
for (int i = 0; i < numberAnimals; i++) | |
{ | |
Animal animal = new Animal(name, roar); | |
animals.Add(animal); | |
} | |
return animals; | |
} | |
private void AddAviaries() | |
{ | |
Dictionary<string, string> animals = new Dictionary<string, string> | |
{ { "Тигр", "Рррр" }, | |
{ "Лев", "Аррр" }, | |
{ "Ишак", "ИаИаИа" }, | |
{ "Слон", "Уззз" } }; | |
foreach (var animal in animals) | |
{ | |
FillAviaries(animal.Key, animal.Value); | |
} | |
} | |
private void FillAviaries(string name, string roar) | |
{ | |
Aviary aviary = new Aviary(AddAnimals(name, roar)); | |
_aviaries.Add(aviary); | |
} | |
} | |
class Aviary | |
{ | |
private List<Animal> _animals = new List<Animal>(); | |
public Aviary(List<Animal> animals) | |
{ | |
_animals = animals; | |
} | |
public void ShowAnimals() | |
{ | |
for (int i = 0; i < _animals.Count; i++) | |
{ | |
_animals[i].ShowInfo(); | |
} | |
} | |
public void ShowInfo() | |
{ | |
if (_animals.Count > 0) | |
{ | |
Console.WriteLine($" - вид животных: {_animals[0].Name}"); | |
} | |
else | |
{ | |
Console.WriteLine("Это вольер пуст!"); | |
} | |
} | |
} | |
class Animal | |
{ | |
private string _gender; | |
private string _roar; | |
public Animal(string name, string roar) | |
{ | |
Name = name; | |
_roar = roar; | |
_gender = GetRandomGender(); | |
} | |
public string Name { get; private set; } | |
public string GetRandomGender() | |
{ | |
string[] gender = { "M", "Ж" }; | |
int number = UserUtils.GetRandomNumber(0, gender.Length); | |
return gender[number]; | |
} | |
public void ShowInfo() | |
{ | |
Console.WriteLine($"{Name}: пол - {_gender}, звук издает - {_roar}"); | |
} | |
} | |
class UserUtils | |
{ | |
private static Random _random = new Random(); | |
public static int GetRandomNumber(int min, int max) | |
{ | |
return _random.Next(min, max); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment