Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Classes
- {
- internal class Program
- {
- static void Main()
- {
- Zoo zoo = new Zoo();
- zoo.Work();
- }
- }
- public class Zoo
- {
- private List<Cage> _cages;
- public Zoo()
- {
- _cages = new List<Cage>();
- CreateCages();
- }
- public void Work()
- {
- bool isWorking = true;
- Console.WriteLine("Welcome in Zoo");
- while (isWorking)
- {
- DisplayCages();
- isWorking = ProcessUserInput();
- }
- }
- private void CreateCages()
- {
- int cageCount = 4;
- for (int i = 0; i < cageCount; i++)
- {
- _cages.Add(new Cage(i));
- }
- }
- private void DisplayCages()
- {
- Console.WriteLine($"\nThere are {_cages.Count} cages");
- for (int i = 0; i < _cages.Count; i++)
- {
- string cageName = _cages[i].Name == null ? null : $"contains " + _cages[i].Name;
- Console.WriteLine($"Cage {i + 1} {cageName}");
- }
- }
- private bool ProcessUserInput()
- {
- const int CommandExit = 5;
- Console.WriteLine($"\nWhich cage do you want to visit? or {CommandExit} for exit..");
- int.TryParse(Console.ReadLine(), out int userInput);
- if (userInput == CommandExit)
- {
- return false;
- }
- if (TrySelectCage(userInput - 1))
- {
- int index = userInput - 1;
- _cages[index].ShowCage(index);
- _cages[index].InteractWithVisitor(index);
- _cages[index].MakeName(index);
- return true;
- }
- return true;
- }
- private bool TrySelectCage(int index)
- {
- if (index >= 0 && index < _cages.Count)
- {
- return true;
- }
- else
- {
- Console.WriteLine("No such cage");
- return false;
- }
- }
- }
- public class Cage
- {
- public event Action<int> IncreaseRequested;
- public event Action<int> RenovateRequested;
- private List<Animals> _animals;
- private Characteristic _characteristic;
- public Cage(int index)
- {
- _animals = new List<Animals>();
- Fill(index);
- IncreaseRequested += Increase;
- RenovateRequested += Renovate;
- }
- public string Name { get; private set; }
- public int GetCount() => _animals.Count;
- public void MakeName(int index)
- {
- Name = MakeColored(AssignAnimalsName(index));
- }
- public virtual void InteractWithVisitor(int index)
- {
- if (index == 0)
- {
- int maxStep = 3;
- for (int i = 0; i < maxStep; i++)
- {
- Console.WriteLine($"You are coming back. You hear a voice of {MakeColored(_characteristic.Name)}. Press something..");
- Console.ReadKey(true);
- }
- Console.WriteLine($"You became {MakeColored(_characteristic.Name)}. You understand what {MakeColored(_characteristic.Name)} say. Press something..");
- IncreaseRequested?.Invoke(index);
- Console.ReadKey(true);
- Console.WriteLine("You were reborn.. Press something..\n");
- Console.ReadKey(true);
- }
- else if (index == 1 || index == 3)
- {
- Console.WriteLine("You return to the cage selection. Press something..\n");
- Console.ReadKey(true);
- }
- else if (index == 2)
- {
- RenovateRequested?.Invoke(index);
- Console.WriteLine("You wanted to come back. But you were eaten. You were reborn.. Press something..\n");
- Console.ReadKey(true);
- }
- }
- public void ShowCage(int index)
- {
- Console.WriteLine($"\nThere are {MakeColored(_animals.Count.ToString())} {MakeColored(AssignAnimalsName(index))} in the cage, " +
- $"their gender is:\n{GetAnimalsGender()}" +
- $"\n\n{MakeSound(index)}");
- }
- private string MakeColored(string line)
- {
- string colorSet = "\u001b[32m";
- string colorReset = "\u001b[0m";
- return colorSet + line + colorReset;
- }
- private string GetAnimalsGender()
- {
- return string.Join(", ", _animals.Select(animal => animal.Characteristic.Gender).Distinct().OrderBy(gender => gender));
- }
- private string MakeSound(int index)
- {
- return index switch
- {
- 0 => $"You hear nothing from the {MakeColored(_characteristic.Name)} cage",
- 1 => "You hear: cheepcheepcheep",
- 2 => "Quiet music is playing",
- 3 => $"You hear: {MakeColored(new[] { "let's have a drink", "got a cigarette?", "hey, any spare change?" }[UserUtil.GetRandomNumber(3)])}",
- _ => ""
- };
- }
- private void Fill(int index)
- {
- for (int i = 0; i < UserUtil.GetRandomNumber(AssignMaxCount(index), AssignMinCount(index)); i++)
- {
- Increase(index);
- }
- }
- private void Increase(int index)
- {
- _characteristic = new Characteristic(AssignAnimalsName(index), AssignAnimalsGender(index));
- _animals.Add(new Animals(_characteristic));
- }
- private void Renovate(int index)
- {
- int numberRemoved = 3;
- int numberAdded = 3;
- for (int i = 0; i < UserUtil.GetRandomNumber(numberAdded + 1); i++)
- {
- if (_animals.Count == AssignMaxCount(index))
- {
- continue;
- }
- Increase(index);
- }
- for (int i = 0; i < UserUtil.GetRandomNumber(numberRemoved + 1); i++)
- {
- if (_animals.Count == AssignMinCount(index))
- {
- continue;
- }
- _animals.RemoveAt(UserUtil.GetRandomNumber(_animals.Count));
- }
- }
- private string AssignAnimalsName(int index) => new[] { "Flamibia", "Qoster", "Kedenee", "Wooni" }[index];
- private string AssignAnimalsGender(int index)
- {
- return index switch
- {
- 0 => "Gender " + (UserUtil.GetRandomNumber(784) + 1),
- 1 => new[] { "XX", "XT", "TT", "ZZ" }[UserUtil.GetRandomNumber(4)],
- 2 => "Genderless",
- 3 => "Parent " + (UserUtil.GetRandomNumber(2) + 1),
- _ => ""
- };
- }
- private int AssignMinCount(int index) => new[] { 70, 8, 1, 10 }[index];
- private int AssignMaxCount(int index) => new[] { 100, 12, 7, 20 }[index];
- }
- public class Characteristic
- {
- public Characteristic(string name, string gender)
- {
- Name = name;
- Gender = gender;
- }
- public string Name { get; private set; }
- public string Gender { get; private set; }
- }
- public class Animals
- {
- public Animals(Characteristic characteristic)
- {
- Characteristic = characteristic;
- }
- public Characteristic Characteristic { get; private set; }
- }
- public class UserUtil
- {
- private static Random s_random = new Random();
- public static int GetRandomNumber(int max, int min = 0)
- {
- return s_random.Next(min, max);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement