Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- Zoo zoo = new Zoo();
- bool isInZoo = true;
- while (isInZoo)
- isInZoo = zoo.Update();
- }
- }
- public class Zoo
- {
- private List<Aviary> _aviaries;
- private Random _random;
- private bool _isShowAviary;
- private int _aviarySelected;
- private int _aviariesAmountMinimum = 4;
- private int _aviariesAmountMaximum = 10;
- public Zoo()
- {
- _random = new Random();
- _aviaries = new List<Aviary>();
- _aviarySelected = -1;
- _isShowAviary = false;
- CreateAviaries();
- }
- public bool Update()
- {
- bool isExit = true;
- if (_isShowAviary)
- ShowAviary();
- else
- isExit = ShowMenu();
- return isExit;
- }
- private void CreateAviaries()
- {
- int amountAviaries = _random.Next(_aviariesAmountMinimum, _aviariesAmountMaximum);
- Aviary aviary;
- for (int i = 0; i < amountAviaries; ++i)
- {
- aviary = new Aviary(i, _random);
- _aviaries.Add(aviary);
- }
- }
- private bool ShowMenu()
- {
- string keyExit = "q";
- bool isInput = true;
- bool isParse = false;
- bool isInZoo = true;
- int inputNumber = 0;
- string input;
- do
- {
- Console.Clear();
- Console.WriteLine("Menu : ");
- Console.WriteLine($"Please input number between 0 and {_aviaries.Count - 1} or input {keyExit} for exit.");
- input = Console.ReadLine();
- isParse = int.TryParse(input, out inputNumber);
- if (isParse)
- {
- if (inputNumber >= 0 && inputNumber < _aviaries.Count)
- {
- isInput = false;
- _isShowAviary = true;
- _aviarySelected = inputNumber;
- }
- }
- else
- {
- if (input.Equals(keyExit))
- {
- isInput = false;
- isInZoo = false;
- Console.WriteLine("Exit from zoo ...");
- }
- }
- }
- while (isInput);
- return isInZoo;
- }
- private void ShowAviary()
- {
- string keyExit = "q";
- bool isInput = true;
- string input;
- do
- {
- Console.Clear();
- Console.WriteLine("Aviary : ");
- Console.WriteLine(_aviaries[_aviarySelected]);
- Console.WriteLine($"Exit - {keyExit}");
- input = Console.ReadLine();
- if (input.Equals(keyExit))
- {
- _aviarySelected = -1;
- _isShowAviary = false;
- isInput = false;
- }
- }
- while (isInput);
- }
- }
- public class Aviary
- {
- private List<Animal> _animals;
- private Random _random;
- private int _aviaryNumber;
- private string[] _animalTypes =
- {
- "Tiger",
- "Monkey",
- "Wolf",
- "Parrot"
- };
- private string[] _animalSounds =
- {
- "*Roar*",
- "*Scream*",
- "*Woof*",
- "*Squawk*"
- };
- private int _animalsAmountMinimum = 4;
- private int _animalsAmountMaximum = 20;
- private int _malePercent = 50;
- private int _percentRangeRandom = 100;
- public Aviary(int aviaryNumber, Random random)
- {
- _random = random;
- _animals = new List<Animal>();
- _aviaryNumber = aviaryNumber;
- CreateAnimals();
- }
- public override string ToString()
- {
- string result = "";
- result += "Aviary number: " + _aviaryNumber + "\n";
- result += "Amount animals in aviary : " + _animals.Count + "\n";
- result += "Animals : \n";
- for (int i = 0; i < _animals.Count; ++i)
- result += i + ".\n" + _animals[i].ToString() + "\n";
- return result;
- }
- private void CreateAnimals()
- {
- int animalsAmount = _random.Next(_animalsAmountMinimum, _animalsAmountMaximum);
- Animal animal = null;
- bool isMale = false;
- int animalType = 0;
- for (int i = 0; i < animalsAmount; ++i)
- {
- animalType = _random.Next(_animalTypes.Length);
- isMale = (_random.Next(_percentRangeRandom) / _malePercent) == 1;
- animal = new Animal(_animalTypes[animalType], _animalSounds[animalType], isMale);
- _animals.Add(animal);
- }
- }
- }
- public class Animal
- {
- private bool _isMale;
- private string _sound;
- private string _type;
- public Animal(string type, string sound, bool isMale)
- {
- _type = type;
- _sound = sound;
- _isMale = isMale;
- }
- public override string ToString()
- {
- string result = "";
- result += "Type of animal : " + _type + ".\n";
- if (_isMale)
- result += "Sex : male\n";
- else
- result += "Sex : female\n";
- result += "Sound of animal : " + _sound + ".\n";
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement