Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CSLight
- {
- class Menu
- {
- static void Main(string[] args)
- {
- int posTextX = 34;
- int posTextY = 3;
- bool IsActive = true;
- Renderer rendAquarium = new Renderer();
- Fish[] fishes = new Fish[0];
- Fishes allFishes = new Fishes(fishes);
- while (IsActive == true)
- {
- Console.Clear();
- Console.CursorVisible = false;
- Console.SetCursorPosition(0, 0);
- rendAquarium.WriteAquarium();
- Console.SetCursorPosition(posTextX, posTextY);
- Console.WriteLine("Список рыб в аквариуме:");
- allFishes.WriteAllFishes(posTextX, posTextY);
- posTextY = 3;
- Console.SetCursorPosition(0, 13);
- Console.WriteLine("Нажми \"1\" чтобы добавить рыбку \nНажми \"2\" чтобы забрать рыбку \nНажми \"Esc\" чтобы выйти из приложения");
- ConsoleKeyInfo userKey = Console.ReadKey(true);
- switch (userKey.Key)
- {
- case ConsoleKey.D1:
- Console.Write("\nСимвол желаемой рыбки: ");
- char inputApp = Convert.ToChar(Console.ReadLine());
- Console.Write("Здоровье рыбки: ");
- int inputHealth = Convert.ToInt32(Console.ReadLine());
- allFishes.AddFish(inputApp, inputHealth);
- break;
- case ConsoleKey.D2:
- Console.Write("\nСимвол удаляемой рыбки: ");
- char inputApp2 = Convert.ToChar(Console.ReadLine());
- allFishes.DelFish(inputApp2);
- break;
- case ConsoleKey.Escape:
- IsActive = false;
- break;
- default:
- ConsoleMessage("Неизвестная команда");
- break;
- }
- }
- }
- static void ConsoleMessage(string message)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("\n" + message);
- Console.ResetColor();
- Console.ReadKey();
- }
- }
- class Renderer
- {
- public char[,] AquariumBG =
- {
- {'=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','='},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|'},
- {'=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','='}
- };
- public void WriteAquarium()
- {
- for (int i = 0; i < AquariumBG.GetLength(0); i++)
- {
- for (int j = 0; j < AquariumBG.GetLength(1); j++)
- {
- Console.Write(AquariumBG[i, j]);
- }
- Console.WriteLine();
- }
- }
- }
- class Fish
- {
- public int Health { get; set; }
- public char Appearance { get; set; }
- public Fish(char appearance, int health)
- {
- Health = health;
- Appearance = appearance;
- }
- }
- class Fishes
- {
- public Fish[] AllFishes;
- public Fishes(Fish[] allFishes)
- {
- AllFishes = allFishes;
- }
- public void WriteAllFishes(int posTextX, int posTextY)
- {
- Random random = new Random();
- foreach (Fish fish in AllFishes)
- {
- Console.SetCursorPosition(posTextX, ++posTextY);
- Console.WriteLine("Рыбка " + fish.Appearance + " - " + fish.Health + " здоровья;");
- fish.Health--;
- Console.SetCursorPosition(random.Next(1, 29), random.Next(1, 10));
- Console.Write(fish.Appearance);
- if(fish.Health <= 0)
- {
- DelFish(fish.Appearance);
- }
- }
- }
- public void AddFish(char inputApp, int inputHealth)
- {
- if (AllFishes.Length >= 8)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("\nАквариум полный");
- Console.ResetColor();
- Console.ReadKey();
- }
- else
- {
- Fish newFish = new Fish(inputApp, inputHealth);
- Fish[] tempFishes = new Fish[AllFishes.Length + 1];
- for (int i = 0; i < AllFishes.Length; i++)
- {
- tempFishes[i] = AllFishes[i];
- }
- tempFishes[tempFishes.Length - 1] = newFish;
- AllFishes = tempFishes;
- }
- }
- public void DelFish(char inputApp)
- {
- int index = -1;
- for (int i = 0; i < AllFishes.Length; ++i)
- {
- if (inputApp == AllFishes[i].Appearance)
- {
- index = i;
- break;
- }
- }
- Fish[] tempFish = new Fish[AllFishes.Length - 1];
- for (int i = 0, j = 0; i < tempFish.Length; ++i, ++j)
- {
- if (j == index)
- ++j;
- tempFish[i] = AllFishes[j];
- }
- AllFishes = tempFish;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment