From 0ab91a7bf3bdd18f02058eb3919cc140399d2d29 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 8 Oct 2023 12:21:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20PlanesGenericCollecti?= =?UTF-8?q?on,=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4=D0=B8=D0=BC?= =?UTF-8?q?=D0=BE=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B5=D0=B3=D0=BE=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlanesGenericCollection.cs | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 ProjectStormtrooper/ProjectStormtrooper/PlanesGenericCollection.cs diff --git a/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericCollection.cs b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericCollection.cs new file mode 100644 index 0000000..4801023 --- /dev/null +++ b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericCollection.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper +{ + /// + /// Параметризованный класс для набора объектов DrawningPlane + /// + /// + /// + internal class PlanesGenericCollection + where T : DrawingPlane + where U : IMoveableObject + { + /// + /// Ширина окна прорисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна прорисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 110; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 110; + /// + /// Набор объектов + /// + private readonly SetGeneric _collection; + /// + /// Конструктор + /// + /// + /// + public PlanesGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(PlanesGenericCollection collect, T? obj) + { + if (obj == null) + { + return false; + } + return collect?._collection.Insert(obj) ?? false; + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static T? operator -(PlanesGenericCollection collect, int pos) + { + T? obj = collect._collection.Get(pos); + if (obj != null) + { + collect._collection.Remove(pos); + } + return obj; + } + /// + /// Получение объекта IMoveableObject + /// + /// + /// + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowPlanes() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + // TODO отрисовка фона + } + /// Метод прорисовки объектов + /// + /// + private void DrawObjects(Graphics g) + { + for (int i = 0; i < _collection.Count; i++) + { + // TODO получение объекта + // TODO установка позиции + // TODO прорисовка объекта + } + } + } +}