Advertisement
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 bidloCodVZdanii
- {
- class Program
- {
- static void Main(string[] args)
- {
- int namber;
- string command;
- Renderer renderer = new Renderer();
- Map map = new Map();
- Сarp[] carp = new Сarp[0];
- NotCarp[] notCarp = new NotCarp[0];
- DefinitelyNotCarp[] definitelyNotCarp = new DefinitelyNotCarp[0];
- ListCarp listCarp = new ListCarp(carp,3);
- ListNotCarp listNotCarp = new ListNotCarp(notCarp,3);
- ListDefinitelyNotCarp listDefinitelyNotCarp = new ListDefinitelyNotCarp(definitelyNotCarp,3);
- Console.CursorVisible = false;
- while (true)
- {
- Console.Clear();
- renderer.WriteMap();
- renderer.WriteListCarp(listCarp);
- renderer.WriteFishList2(listNotCarp);
- renderer.WriteFishList3(listDefinitelyNotCarp);
- renderer.WriteFish1(listCarp.Carps);
- renderer.WriteFish2(listNotCarp.NotCarp);
- renderer.WriteFish3(listDefinitelyNotCarp.DefinitelyNotCarp);
- listCarp.Demeanor();
- listNotCarp.Demeanor();
- listDefinitelyNotCarp.Demeanor();
- Console.SetCursorPosition(51, 00);
- Console.Write("1. Достать рыбку 2. Забрать рыбку 3. Выход");
- command = Console.ReadLine();
- if (command == "1")
- {
- Console.SetCursorPosition(51, 01);
- Console.Write("Какую?");
- command = Console.ReadLine();
- switch (command)
- {
- case "1":
- listCarp.AddNewCarp();
- break;
- case "2":
- listNotCarp.AddNotCarp();
- break;
- case "3":
- listDefinitelyNotCarp.AddNewDNC();
- break;
- }
- }
- else if (command == "2")
- {
- Console.SetCursorPosition(51, 01);
- Console.Write("Какой тип и номер ");
- command = Console.ReadLine();
- Console.SetCursorPosition(72, 01);
- namber = Convert.ToInt32(Console.ReadLine());
- switch (command)
- {
- case "1":
- listCarp.RemoveCarp(namber-1);
- break;
- case "2":
- listNotCarp.RemoveNotCarp(namber-1);
- break;
- case "3":
- listDefinitelyNotCarp.RemoveDNC(namber-1);
- break;
- }
- }
- else if (command == "3")
- {
- break;
- }
- }
- }
- }
- class Fish
- {
- protected int _pozitionX;
- protected int _pozitionY;
- protected int _hp;
- protected char _symbol;
- protected Random _random = new Random();
- public int PozitionX
- {
- get
- {
- return _pozitionX;
- }
- }
- public int PozitionY
- {
- get
- {
- return _pozitionY;
- }
- }
- public int Hp
- {
- get
- {
- return _hp;
- }
- }
- public char Symbol
- {
- get
- {
- return _symbol;
- }
- }
- public Fish(int pozitionX, int pozitionY, int hp, char simvol)
- {
- _pozitionX = pozitionX;
- _pozitionY = pozitionY;
- _hp = hp;
- _symbol = simvol;
- }
- }
- class Сarp : Fish
- {
- public Сarp(int pozitionX = 5, int pozitionY = 1 , int hp=400, char simbol= '@') : base(pozitionX, pozitionY, hp, simbol)
- {
- }
- public void Demeanor()
- {
- Move move = new Move(_pozitionX, _pozitionY);
- _hp -= 2;
- switch (_random.Next(1,9))
- {
- case 1:
- move.MoveDown();
- break;
- case 2:
- move.MoveDownLeft();
- break;
- case 3:
- move.MoveDownRight();
- break;
- case 4:
- move.MoveLeft();
- break;
- case 5:
- move.MoveUP();
- break;
- case 6:
- move.MoveUPLeft();
- break;
- case 7:
- move.MoveUPRight();
- break;
- case 8:
- move.MoveRight();
- break;
- }
- _pozitionX = move.PozitionX;
- _pozitionY = move.PozitionY;
- }
- }
- class NotCarp : Fish
- {
- public NotCarp(int pozitionX= 10, int pozitionY = 1, int hp = 500, char simbol = '%') : base(pozitionX, pozitionY, hp, simbol)
- {
- }
- public void Demeanor()
- {
- Move move = new Move(_pozitionX, _pozitionY);
- _hp -= 5;
- switch (_random.Next(1, 5))
- {
- case 1:
- move.MoveDown();
- break;
- case 2:
- move.MoveLeft();
- break;
- case 3:
- move.MoveRight();
- break;
- case 4:
- move.MoveUP();
- break;
- }
- _pozitionX = move.PozitionX;
- _pozitionY = move.PozitionY;
- }
- }
- class DefinitelyNotCarp : Fish
- {
- public DefinitelyNotCarp(int pozitionX = 1, int pozitionY = 1, int hp = 200, char simbol = '&') : base(pozitionX, pozitionY, hp, simbol)
- {
- }
- public void Demeanor()
- {
- Move move = new Move(_pozitionX, _pozitionY);
- _hp -= 2;
- switch (_random.Next(1, 5))
- {
- case 1:
- move.MoveDownLeft();
- break;
- case 2:
- move.MoveDownRight();
- break;
- case 3:
- move.MoveUPLeft();
- break;
- case 4:
- move.MoveUPRight();
- break;
- }
- _pozitionX = move.PozitionX;
- _pozitionY = move.PozitionY;
- }
- }
- class ListCarp
- {
- public Сarp[] Carps { get; private set; }
- public int MaxCarps { get; private set; }
- public ListCarp(Сarp[] carps, int maxCarps)
- {
- Carps = carps;
- MaxCarps = maxCarps;
- }
- public void AddNewCarp()
- {
- Сarp newCarp = new Сarp();
- Сarp[] localCarps = new Сarp[Carps.Length + 1];
- if (localCarps.Length <= MaxCarps)
- {
- for (int i = 0; i < Carps.Length; i++)
- {
- localCarps[i] = Carps[i];
- }
- localCarps[localCarps.Length - 1] = newCarp;
- Carps = localCarps;
- }
- }
- public void RemoveCarp(int namber)
- {
- if (Carps.Length > 0 && namber< Carps.Length)
- {
- Сarp[] localCarps = new Сarp[Carps.Length - 1];
- int j = 0;
- for (int i = 0; i < Carps.Length; i++)
- {
- if (i != namber)
- {
- localCarps[j] = Carps[i];
- j++;
- }
- }
- Carps = localCarps;
- }
- }
- public void Demeanor()
- {
- for (int i = 0; i < Carps.Length; i++)
- {
- if(Carps[i].Hp <= 0)
- {
- RemoveCarp(i);
- }
- else
- {
- Carps[i].Demeanor();
- }
- }
- }
- }
- class ListNotCarp
- {
- public NotCarp[] NotCarp { get; private set; }
- public int MaxNotCarp { get; private set; }
- public ListNotCarp(NotCarp[] fish2, int maxNotCarp)
- {
- NotCarp = fish2;
- MaxNotCarp = maxNotCarp;
- }
- public void AddNotCarp()
- {
- NotCarp newNotCarp = new NotCarp();
- NotCarp[] localNotCarp = new NotCarp[NotCarp.Length + 1];
- if (localNotCarp.Length <= MaxNotCarp)
- {
- for (int i = 0; i < NotCarp.Length; i++)
- {
- localNotCarp[i] = NotCarp[i];
- }
- localNotCarp[localNotCarp.Length - 1] = newNotCarp;
- NotCarp = localNotCarp;
- }
- }
- public void RemoveNotCarp(int namber)
- {
- NotCarp[] localNotCarp = new NotCarp[NotCarp.Length - 1];
- int j = 0;
- for (int i = 0; i < NotCarp.Length; i++)
- {
- if (i != namber)
- {
- localNotCarp[j] = NotCarp[i];
- j++;
- }
- }
- NotCarp = localNotCarp;
- }
- public void Demeanor()
- {
- for (int i = 0; i < NotCarp.Length; i++)
- {
- if (NotCarp[i].Hp <= 0)
- {
- RemoveNotCarp(i);
- }
- else
- {
- NotCarp[i].Demeanor();
- }
- }
- }
- }
- class ListDefinitelyNotCarp
- {
- public DefinitelyNotCarp[] DefinitelyNotCarp { get; private set; }
- public int MaxDNC { get; private set; }
- public ListDefinitelyNotCarp(DefinitelyNotCarp[] definitelyNotCarp, int maxDNC)
- {
- DefinitelyNotCarp = definitelyNotCarp;
- MaxDNC = maxDNC;
- }
- public void AddNewDNC()
- {
- DefinitelyNotCarp newDNC = new DefinitelyNotCarp();
- DefinitelyNotCarp[] localDNC = new DefinitelyNotCarp[DefinitelyNotCarp.Length + 1];
- if (localDNC.Length <= MaxDNC)
- {
- for (int i = 0; i < DefinitelyNotCarp.Length; i++)
- {
- localDNC[i] = DefinitelyNotCarp[i];
- }
- localDNC[localDNC.Length - 1] = newDNC;
- DefinitelyNotCarp = localDNC;
- }
- }
- public void RemoveDNC(int namber)
- {
- DefinitelyNotCarp[] localDNC = new DefinitelyNotCarp[DefinitelyNotCarp.Length - 1];
- int j = 0;
- for (int i = 0; i < DefinitelyNotCarp.Length; i++)
- {
- if (i != namber)
- {
- localDNC[j] = DefinitelyNotCarp[i];
- j++;
- }
- }
- DefinitelyNotCarp = localDNC;
- }
- public void Demeanor()
- {
- for (int i = 0; i < DefinitelyNotCarp.Length; i++)
- {
- if (DefinitelyNotCarp[i].Hp <= 0)
- {
- RemoveDNC(i);
- }
- else
- {
- DefinitelyNotCarp[i].Demeanor();
- }
- }
- }
- }
- class Move
- {
- public int PozitionX { get; protected set; }
- public int PozitionY { get; protected set; }
- private Map _map = new Map();
- public Move(int pozitionX, int pozitionY)
- {
- PozitionX = pozitionX;
- PozitionY = pozitionY;
- }
- public void MoveUP()
- {
- if (_map.GetMap[PozitionY, PozitionX - 1] != '#')
- {
- PozitionX--;
- }
- }
- public void MoveDown()
- {
- if (_map.GetMap[PozitionY, PozitionX + 1] != '#')
- {
- PozitionX++;
- }
- }
- public void MoveRight()
- {
- if (_map.GetMap[PozitionY + 1, PozitionX] != '#')
- {
- PozitionY++;
- }
- }
- public void MoveLeft()
- {
- if (_map.GetMap[PozitionY - 1, PozitionX] != '#')
- {
- PozitionY--;
- }
- }
- public void MoveUPRight()
- {
- if (_map.GetMap[PozitionY + 1, PozitionX - 1] != '#')
- {
- PozitionX--;
- PozitionY++;
- }
- }
- public void MoveUPLeft()
- {
- if (_map.GetMap[PozitionY - 1, PozitionX - 1] != '#')
- {
- PozitionX--;
- PozitionY--;
- }
- }
- public void MoveDownRight()
- {
- if (_map.GetMap[PozitionY + 1, PozitionX + 1] != '#')
- {
- PozitionX++;
- PozitionY++;
- }
- }
- public void MoveDownLeft()
- {
- if (_map.GetMap[PozitionY - 1, PozitionX + 1] != '#')
- {
- PozitionX++;
- PozitionY--;
- }
- }
- }
- class Map
- {
- private char[,] _map =
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
- };
- public char[,] GetMap
- {
- get
- {
- return _map;
- }
- }
- public int LengthMap
- {
- get
- {
- return _map.GetLength(0);
- }
- }
- public int HeightMap
- {
- get
- {
- return _map.GetLength(1);
- }
- }
- }
- class Renderer
- {
- public void WriteMap()
- {
- Map map = new Map();
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < map.LengthMap; i++)
- {
- for (int j = 0; j < map.HeightMap; j++)
- {
- Console.Write(map.GetMap[i, j]);
- }
- Console.WriteLine();
- }
- }
- public void WriteListCarp(ListCarp listCarp)
- {
- Console.SetCursorPosition(0, 12);
- Console.WriteLine("Караси:");
- if (listCarp.Carps.Length == 0)
- {
- Console.WriteLine("Их нет");
- }
- for (int i = 0; i < listCarp.Carps.Length; i++)
- {
- Console.WriteLine($"Номер: {i + 1}; Жизни: {listCarp.Carps[i].Hp}; Вид: {listCarp.Carps[i].Symbol}");
- }
- }
- public void WriteFishList2(ListNotCarp ListFish2)
- {
- Console.SetCursorPosition(0, 17);
- Console.WriteLine("Не караси:");
- if (ListFish2.NotCarp.Length == 0)
- {
- Console.WriteLine("Инвентарь пусть");
- }
- for (int i = 0; i < ListFish2.NotCarp.Length; i++)
- {
- Console.WriteLine($"Номер: {i + 1}; Жизни: {ListFish2.NotCarp[i].Hp}; Вид: {ListFish2.NotCarp[i].Symbol}");
- }
- }
- public void WriteFishList3(ListDefinitelyNotCarp ListFish3)
- {
- Console.SetCursorPosition(0, 22);
- Console.WriteLine("Совсем не караси:");
- if (ListFish3.DefinitelyNotCarp.Length == 0)
- {
- Console.WriteLine("Инвентарь пусть");
- }
- for (int i = 0; i < ListFish3.DefinitelyNotCarp.Length; i++)
- {
- Console.WriteLine($"Номер: {i + 1}; Жизни: {ListFish3.DefinitelyNotCarp[i].Hp}; Вид: {ListFish3.DefinitelyNotCarp[i].Symbol}");
- }
- }
- public void WriteFish1(Сarp[] Fish1)
- {
- if (Fish1.Length == 0)
- {
- Console.WriteLine("");
- }
- for (int i = 0; i < Fish1.Length; i++)
- {
- Console.SetCursorPosition(Fish1[i].PozitionX, Fish1[i].PozitionY);
- Console.WriteLine(Fish1[i].Symbol);
- }
- }
- public void WriteFish2(NotCarp[] Fish2)
- {
- if (Fish2.Length == 0)
- {
- Console.WriteLine("");
- }
- for (int i = 0; i < Fish2.Length; i++)
- {
- Console.SetCursorPosition(Fish2[i].PozitionX, Fish2[i].PozitionY);
- Console.WriteLine(Fish2[i].Symbol);
- }
- }
- public void WriteFish3(DefinitelyNotCarp[] Fish3)
- {
- if (Fish3.Length == 0)
- {
- Console.WriteLine("");
- }
- for (int i = 0; i < Fish3.Length; i++)
- {
- Console.SetCursorPosition(Fish3[i].PozitionX, Fish3[i].PozitionY);
- Console.WriteLine(Fish3[i].Symbol);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement