SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | - | namespace C_sharp_Light |
| 3 | + | |
| 4 | namespace CLights | |
| 5 | {
| |
| 6 | class Program | |
| 7 | - | static void Main(string[] args) |
| 7 | + | |
| 8 | public static void Main() | |
| 9 | - | |
| 9 | + | |
| 10 | new Zoo().Work(); | |
| 11 | } | |
| 12 | } | |
| 13 | public static class RandomStatic | |
| 14 | {
| |
| 15 | static private Random _rand = new Random(); | |
| 16 | static public int GetNext(int min, int max) | |
| 17 | {
| |
| 18 | return _rand.Next(min, max); | |
| 19 | } | |
| 20 | } | |
| 21 | public static class Messager | |
| 22 | {
| |
| 23 | static public void ShowMessageWithColor(string message, ConsoleColor color, bool delay) | |
| 24 | {
| |
| 25 | ConsoleColor defaultColor = Console.ForegroundColor; | |
| 26 | Console.ForegroundColor = color; | |
| 27 | Console.WriteLine(message); | |
| 28 | Console.ForegroundColor = defaultColor; | |
| 29 | if (delay) | |
| 30 | Console.ReadKey(); | |
| 31 | } | |
| 32 | } | |
| 33 | class Zoo | |
| 34 | {
| |
| 35 | private List<Aviary> _aviaries = new List<Aviary>(); | |
| 36 | private Aviary _activeAviray; | |
| 37 | public Zoo() | |
| 38 | {
| |
| 39 | for (int i = 0; i < 13; i++) | |
| 40 | {
| |
| 41 | _aviaries.Add(new Aviary($"Номер:{i}"));
| |
| 42 | } | |
| 43 | } | |
| 44 | public void Work() | |
| 45 | {
| |
| 46 | bool isOpen = true; | |
| 47 | while (isOpen) | |
| 48 | {
| |
| 49 | Console.Clear(); | |
| 50 | ShowInfo(); | |
| 51 | ||
| 52 | if (_activeAviray == null) | |
| 53 | {
| |
| 54 | Console.WriteLine("\n1 - Подойти к вольеру \nEsc - Выйти из программы");
| |
| 55 | switch (Console.ReadKey(true).Key) | |
| 56 | {
| |
| 57 | case ConsoleKey.D1: | |
| 58 | ComeUp(); | |
| 59 | break; | |
| 60 | case ConsoleKey.Escape: | |
| 61 | isOpen = false; | |
| 62 | break; | |
| 63 | } | |
| 64 | } | |
| 65 | else | |
| 66 | {
| |
| 67 | Console.WriteLine("\nEsc - Отойти от вольера");
| |
| 68 | switch (Console.ReadKey(true).Key) | |
| 69 | {
| |
| 70 | case ConsoleKey.Escape: | |
| 71 | MoveAway(); | |
| 72 | break; | |
| 73 | } | |
| 74 | } | |
| 75 | } | |
| 76 | } | |
| 77 | private void ComeUp() | |
| 78 | {
| |
| 79 | Console.Write("Введите индекс вольера, к которому хотите подойте: ");
| |
| 80 | int index = Convert.ToInt32(Console.ReadLine()); | |
| 81 | if (index < 0) | |
| 82 | index = 0; | |
| 83 | if (index >= _aviaries.Count) | |
| 84 | index = _aviaries.Count - 1; | |
| 85 | _activeAviray = _aviaries[index]; | |
| 86 | } | |
| 87 | private void MoveAway() | |
| 88 | {
| |
| 89 | _activeAviray = null; | |
| 90 | } | |
| 91 | private void ShowInfo() | |
| 92 | {
| |
| 93 | if (_activeAviray == null) | |
| 94 | {
| |
| 95 | Messager.ShowMessageWithColor($"Вы находитесь в запораке. В нем есть следующие вольеры: ", ConsoleColor.Magenta, false); | |
| 96 | for (int i = 0; i < _aviaries.Count; i++) | |
| 97 | {
| |
| 98 | _aviaries[i].ShowSimpelInfo(i); | |
| 99 | } | |
| 100 | } | |
| 101 | else | |
| 102 | {
| |
| 103 | _activeAviray.ShowDetailInfo(); | |
| 104 | } | |
| 105 | } | |
| 106 | } | |
| 107 | class Aviary | |
| 108 | {
| |
| 109 | public string Name { get; private set; }
| |
| 110 | private List<Animal> _animals = new List<Animal>(); | |
| 111 | public Aviary(string name) | |
| 112 | {
| |
| 113 | Name = name; | |
| 114 | FillAviary(); | |
| 115 | } | |
| 116 | public void ShowDetailInfo() | |
| 117 | {
| |
| 118 | Messager.ShowMessageWithColor($"Название вольера - {Name}\nВольер содержит {_animals.Count} животных", ConsoleColor.Yellow, false);
| |
| 119 | for (int i = 0; i < _animals.Count; i++) | |
| 120 | {
| |
| 121 | Messager.ShowMessageWithColor(_animals[i].GetInfo(), ConsoleColor.White, false); | |
| 122 | } | |
| 123 | } | |
| 124 | public void ShowSimpelInfo(int ordinalIndex) | |
| 125 | {
| |
| 126 | Messager.ShowMessageWithColor($"{ordinalIndex}: Название вольера - {Name};", ConsoleColor.Yellow, false);
| |
| 127 | } | |
| 128 | private void FillAviary() | |
| 129 | {
| |
| 130 | int amountAnimal = RandomStatic.GetNext(2, 10); | |
| 131 | int chance = RandomStatic.GetNext(0, 5); | |
| 132 | for (int i = 0; i < amountAnimal; i++) | |
| 133 | {
| |
| 134 | switch (chance) | |
| 135 | {
| |
| 136 | case 0: | |
| 137 | _animals.Add(new Lion()); | |
| 138 | break; | |
| 139 | case 1: | |
| 140 | _animals.Add(new Owl()); | |
| 141 | break; | |
| 142 | case 2: | |
| 143 | _animals.Add(new Bear()); | |
| 144 | break; | |
| 145 | case 3: | |
| 146 | _animals.Add(new Rabbit()); | |
| 147 | break; | |
| 148 | case 4: | |
| 149 | _animals.Add(new Toucan()); | |
| 150 | break; | |
| 151 | } | |
| 152 | } | |
| 153 | } | |
| 154 | } | |
| 155 | abstract class Animal | |
| 156 | {
| |
| 157 | public string Volume { get; protected set; }
| |
| 158 | private bool _isMale; | |
| 159 | ||
| 160 | public Animal() | |
| 161 | {
| |
| 162 | _isMale = Convert.ToBoolean(RandomStatic.GetNext(0, 2)); | |
| 163 | } | |
| 164 | virtual public string GetInfo() | |
| 165 | {
| |
| 166 | if (_isMale) | |
| 167 | return $"Пол мужской. Издает звук \"{Volume}\"";
| |
| 168 | else | |
| 169 | return $"Пол женский. Издает звук \"{Volume}\"";
| |
| 170 | } | |
| 171 | } | |
| 172 | class Lion : Animal | |
| 173 | {
| |
| 174 | public Lion() : base() | |
| 175 | {
| |
| 176 | Volume = "Рр-р-р"; | |
| 177 | } | |
| 178 | public override string GetInfo() | |
| 179 | {
| |
| 180 | return "Лев - " + base.GetInfo(); | |
| 181 | } | |
| 182 | } | |
| 183 | class Owl : Animal | |
| 184 | {
| |
| 185 | public Owl() : base() | |
| 186 | {
| |
| 187 | Volume = "Уфу-у-у... Угу-у-у"; | |
| 188 | } | |
| 189 | public override string GetInfo() | |
| 190 | {
| |
| 191 | return "Сова - " + base.GetInfo(); | |
| 192 | } | |
| 193 | } | |
| 194 | class Bear : Animal | |
| 195 | {
| |
| 196 | public Bear() : base() | |
| 197 | {
| |
| 198 | Volume = "Ря-я-яв"; | |
| 199 | } | |
| 200 | public override string GetInfo() | |
| 201 | {
| |
| 202 | return "Медведь - " + base.GetInfo(); | |
| 203 | } | |
| 204 | } | |
| 205 | class Rabbit : Animal | |
| 206 | {
| |
| 207 | public Rabbit() : base() | |
| 208 | {
| |
| 209 | Volume = "Хрум-хрум"; | |
| 210 | } | |
| 211 | public override string GetInfo() | |
| 212 | {
| |
| 213 | return "Кролик - " + base.GetInfo(); | |
| 214 | } | |
| 215 | } | |
| 216 | class Toucan : Animal | |
| 217 | {
| |
| 218 | public Toucan() : base() | |
| 219 | {
| |
| 220 | Volume = "*Тук тук тук*"; | |
| 221 | } | |
| 222 | public override string GetInfo() | |
| 223 | {
| |
| 224 | return "Тукан - " + base.GetInfo(); | |
| 225 | } | |
| 226 | } | |
| 227 | } |