Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- internal class Program
- {
- static void Main(string[] args)
- {
- ManagerAquarium managerAquarium = new ManagerAquarium();
- managerAquarium.Run();
- }
- }
- public static class UserUtils
- {
- private static Random s_random = new Random();
- public static int GenerateRandomNumber(int minRandom, int maxRandom)
- {
- return s_random.Next(minRandom, maxRandom + 1);
- }
- }
- public class Fish
- {
- private int _lifeTime;
- public Fish(string name)
- {
- Name = name;
- int minLifeTime = 6;
- int maxLifeTime = 15;
- _lifeTime = UserUtils.GenerateRandomNumber(minLifeTime, maxLifeTime);
- }
- public string Name { get; private set; }
- public void DecreaseLifetime()
- {
- if (_lifeTime > 0)
- {
- _lifeTime--;
- }
- }
- public void ShowInfo()
- {
- Console.Write("Рыбка ");
- if (_lifeTime > 0)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- }
- Console.Write(Name + " ");
- Console.ForegroundColor = ConsoleColor.Gray;
- if (_lifeTime > 0)
- {
- Console.WriteLine($"осталось жить {_lifeTime} цикла беспощадного кода.");
- }
- else
- {
- Console.WriteLine(" всплыла вверх пузом. Пора ее убрать.");
- }
- }
- }
- public class Aquarium
- {
- private List<Fish> _fishes = new List<Fish>();
- private int _capacity;
- public Aquarium()
- {
- _capacity = 5;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"В аквариуме {_fishes.Count}/{_capacity} рыб.");
- foreach (Fish fish in _fishes)
- {
- fish.ShowInfo();
- }
- }
- public void AddFish()
- {
- if (_fishes.Count < _capacity)
- {
- Console.Write("Придумай имя рыбке: ");
- _fishes.Add(new Fish(Console.ReadLine()));
- Console.WriteLine("Рыбка добавлена.");
- }
- else
- {
- Console.WriteLine("В аквариуме нет места.");
- Console.ReadKey();
- }
- }
- public void RemoveFish()
- {
- if (_fishes.Count == 0)
- {
- Console.WriteLine("Аквариум и так пуст.");
- Console.ReadKey();
- return;
- }
- Console.Write("Имя рыбки: ");
- string name = Console.ReadLine();
- bool fishFound = false;
- for (int i = 0; i < _fishes.Count; i++)
- {
- if (_fishes[i].Name == name)
- {
- _fishes.RemoveAt(i);
- fishFound = true;
- Console.WriteLine("Рыбка убрана.");
- break;
- }
- }
- if (fishFound == false)
- {
- Console.WriteLine("Рыбки с таким именем нет.");
- Console.ReadKey();
- }
- }
- public void CycleTimes()
- {
- foreach (Fish fish in _fishes)
- {
- fish.DecreaseLifetime();
- }
- }
- }
- public class ManagerAquarium
- {
- private Aquarium _aquarium = new Aquarium();
- public void Run()
- {
- const string CommandAddFish = "1";
- const string CommandRemoveFish = "2";
- const string CommandExit = "3";
- bool nearAquarium = true;
- while (nearAquarium)
- {
- _aquarium.ShowInfo();
- Console.WriteLine($"\nТы подошел к аквариуму.\n" +
- $"{CommandAddFish} - Добавить рыбку.\n" +
- $"{CommandRemoveFish} - Убрать рыбку.\n" +
- $"{CommandExit} - Уйти.\n" +
- "Можешь просто наблюдать (любая клавиша).");
- switch (Console.ReadLine())
- {
- case CommandAddFish:
- _aquarium.AddFish();
- break;
- case CommandRemoveFish:
- _aquarium.RemoveFish();
- break;
- case CommandExit:
- nearAquarium = false;
- break;
- }
- _aquarium.CycleTimes();
- Console.ReadKey();
- Console.Clear();
- }
- Console.WriteLine("Приходи еще!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment