diff --git a/ProjectTank №3/ProjectTank.sln b/ProjectTank №3/ProjectTank.sln
new file mode 100644
index 0000000..a1561d4
--- /dev/null
+++ b/ProjectTank №3/ProjectTank.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.7.34024.191
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectTank", "ProjectTank\ProjectTank.csproj", "{E84822F4-E6D0-4691-A08D-4241A54BE837}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {E84822F4-E6D0-4691-A08D-4241A54BE837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E84822F4-E6D0-4691-A08D-4241A54BE837}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E84822F4-E6D0-4691-A08D-4241A54BE837}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E84822F4-E6D0-4691-A08D-4241A54BE837}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {90F6A650-635F-4AF8-BFD4-CC2A28015CD9}
+ EndGlobalSection
+EndGlobal
diff --git a/ProjectTank №3/ProjectTank/CollectionGenericObjects/AbsrtactCompany.cs b/ProjectTank №3/ProjectTank/CollectionGenericObjects/AbsrtactCompany.cs
new file mode 100644
index 0000000..0730e8f
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/CollectionGenericObjects/AbsrtactCompany.cs
@@ -0,0 +1,115 @@
+using ProjectTank.Drawnings;
+using ProjectTank.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 100;
+
+ ///
+ /// Ширина окна
+ ///
+ protected readonly int _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ protected readonly int _pictureHeight;
+
+ ///
+ /// Коллекция автомобилей
+ ///
+ protected ICollectionGenericObjects? _collection = null;
+
+ ///
+ /// Вычисление максимального количества элементов, который можно разместить в окне
+ ///
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+
+ ///
+ /// Конструктор
+ ///
+ /// Ширина окна
+ /// Высота окна
+ /// Коллекция автомобилей
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ {
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = collection;
+ _collection.SetMaxCount = GetMaxCount;
+ }
+
+ ///
+ /// Перегрузка оператора сложения для класса
+ ///
+ /// Компания
+ /// Добавляемый объект
+ ///
+ public static int operator +(AbstractCompany company, DrawningTank2 tank)
+ {
+ return company?._collection.Insert(tank) ?? -1;
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningTank2? operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position) ?? null;
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningTank2? GetRandomObject()
+ {
+ Random rnd = new();
+ return _collection?.Get(rnd.Next(GetMaxCount));
+ }
+
+ ///
+ /// Вывод всей коллекции
+ ///
+ ///
+ public Bitmap? Show()
+ {
+ Bitmap bitmap = new(_pictureWidth, _pictureHeight);
+ Graphics graphics = Graphics.FromImage(bitmap);
+ DrawBackgound(graphics);
+
+ SetObjectsPosition();
+ for (int i = 0; i < (_collection?.Count ?? 0); ++i)
+ {
+ DrawningTank2? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectTank №3/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..4f00b75
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,49 @@
+namespace ProjectTank.CollectionGenericObjects
+{
+ ///
+ /// Интерфейс описания действий для набора хранимых данных
+ ///
+ ///
+ public interface ICollectionGenericObjects
+ where T : class
+ {
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj);
+
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло удачно, false - удаление не удалось
+ T? Remove(int position);
+
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTank №3/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..4326cf4
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,113 @@
+using ProjectTank.CollectionGenericObjects;
+///
+/// Параметризованный набор объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public class MassiveGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private T?[] _collection;
+
+ public int Count => _collection.Length;
+
+ public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
+
+ ///
+ /// Конструктор
+ ///
+ public MassiveGenericObjects()
+ {
+ _collection = Array.Empty();
+ }
+
+ public T? Get(int position)
+ {
+ if (position >= 0 && position < Count)
+ {
+ return _collection[position];
+ }
+
+ return null;
+ }
+
+ public int Insert(T obj)
+ {
+ // вставка в свободное место набора
+ for (int i = 0; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ // проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
+
+ // проверка, что элемент массива по этой позиции пустой, если нет, то
+ // ищется свободное место после этой позиции и идет вставка туда
+ // если нет после, ищем до
+ if (_collection[position] != null)
+ {
+ bool pushed = false;
+ for (int index = position + 1; index < Count; index++)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+
+ if (!pushed)
+ {
+ for (int index = position - 1; index >= 0; index--)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+ }
+
+ if (!pushed)
+ {
+ return position;
+ }
+ }
+
+ // вставка
+ _collection[position] = obj;
+ return position;
+ }
+
+ public T? Remove(int position)
+ {
+ // проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+
+ if (_collection[position] == null) return null;
+
+ T? temp = _collection[position];
+ _collection[position] = null;
+ return temp;
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/CollectionGenericObjects/TankBase.cs b/ProjectTank №3/ProjectTank/CollectionGenericObjects/TankBase.cs
new file mode 100644
index 0000000..f1eac54
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/CollectionGenericObjects/TankBase.cs
@@ -0,0 +1,56 @@
+using ProjectTank.Drawnings;
+
+namespace ProjectTank.CollectionGenericObjects
+{
+ public class TankBase : AbstractCompany
+ {
+ public TankBase(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+
+ }
+ protected override void DrawBackgound(Graphics g)
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+ Pen pen = new(Color.Black, 2);
+ for (int i = 0; i < width + 1; i++)
+ {
+ for (int j = 0; j < height + 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5 + _placeSizeWidth - 45, j * _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5, j * _placeSizeHeight - _placeSizeHeight);
+ }
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ int TankWidth = 0;
+ int TankHeight = 0;
+
+ for (int i = 0; i < (_collection?.Count ?? 0); i++)
+ {
+ if (_collection?.Get(i) != null)
+ {
+ _collection.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i)?.SetPosition(_placeSizeWidth * TankWidth + 20, TankHeight * _placeSizeHeight + 5);
+ }
+
+ if (TankWidth < width)
+ TankWidth++;
+ else
+ {
+ TankWidth = 0;
+ TankHeight++;
+ }
+ if (TankHeight > height - 1)
+ {
+ return;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/Drawnings/DirectionType.cs b/ProjectTank №3/ProjectTank/Drawnings/DirectionType.cs
new file mode 100644
index 0000000..12d0cdf
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/Drawnings/DirectionType.cs
@@ -0,0 +1,30 @@
+namespace ProjectTank.Drawnings
+{
+ ///
+ /// направление перемещенния
+ ///
+ public enum DirectionType
+ {
+ ///
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+ ///
+ /// Влево
+ ///
+ Left = 3,
+ ///
+ /// Вправо
+ ///
+ Right = 4,
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/Drawnings/DrawningTank1.cs b/ProjectTank №3/ProjectTank/Drawnings/DrawningTank1.cs
new file mode 100644
index 0000000..0b5acd6
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/Drawnings/DrawningTank1.cs
@@ -0,0 +1,63 @@
+using ProjectTank.Entities;
+
+namespace ProjectTank.Drawnings;
+///
+/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+///
+public class DrawningTank1 : DrawningTank2
+{
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия пушки
+ /// признак наличия пулемета
+ ///
+ public DrawningTank1(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machinGun) : base(150, 87)
+ {
+ EntityTank2 = new EntityTank1(speed, weight, bodyColor, additionalColor, gun, machinGun);
+ }
+
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityTank2 == null || EntityTank2 is not EntityTank1 Tank1 || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+ Pen pen = new(Color.Black);
+ Brush additionalBrush = new SolidBrush(Tank1.AdditionalColor);
+
+ if (Tank1.Gun)
+ {
+ g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 30, 45, 5);
+
+ g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 30, 45, 5);
+ }
+
+ //пулемет
+ if (Tank1.MachinGun)
+ {
+ g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 15, 16, 5);
+ g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 10, 5, 5);
+ g.DrawRectangle(pen, _startPosX.Value + 71, _startPosY.Value + 3, 7, 7);
+ g.DrawRectangle(pen, _startPosX.Value + 55, _startPosY.Value + 5, 15, 3);
+
+ g.FillRectangle(additionalBrush, _startPosX.Value + 65, _startPosY.Value + 15, 16, 5);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 72, _startPosY.Value + 10, 5, 5);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 71, _startPosY.Value + 3, 7, 7);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 55, _startPosY.Value + 5, 15, 3);
+ }
+ _startPosY += 20;
+ base.DrawTransport(g);
+ _startPosY -= 20;
+
+ }
+
+}
diff --git a/ProjectTank №3/ProjectTank/Drawnings/DrawningTank2.cs b/ProjectTank №3/ProjectTank/Drawnings/DrawningTank2.cs
new file mode 100644
index 0000000..63d9c11
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/Drawnings/DrawningTank2.cs
@@ -0,0 +1,240 @@
+using ProjectTank.Entities;
+namespace ProjectTank.Drawnings
+{
+ public class DrawningTank2
+ {
+ ///
+ /// класс - сущность
+ ///
+ public EntityTank2? EntityTank2 { get; protected set; }
+
+ ///
+ /// ширина окна
+ ///
+ private int? _pictureWidth;
+
+ ///
+ /// высота окна
+ ///
+ private int? _pictureHeight;
+
+ ///
+ /// Левая координата прорисовки танка
+ ///
+ protected int? _startPosX;
+
+ ///
+ /// Верхняя координата прорисовки танка
+ ///
+ protected int? _startPosY;
+
+ ///
+ /// ширина прорисовки танка
+ /// ///
+ private readonly int _drawningTankWidth = 150;
+
+ ///
+ /// высота прорисовки танка
+ ///
+ private readonly int _drawningTankHeight = 67;
+
+ ///
+ /// Координата X объекта
+ ///
+ public int? GetPosX => _startPosX;
+
+ ///
+ /// Координата Y объекта
+ ///
+ public int? GetPosY => _startPosY;
+
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningTankWidth;
+
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningTankHeight;
+
+ ///
+ /// Пустой конструктор
+ ///
+ private DrawningTank2()
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+ }
+
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес танка
+ /// Основной цвет
+ public DrawningTank2(int speed, double weight, Color bodyColor) : this()
+ {
+ EntityTank2 = new EntityTank2(speed, weight, bodyColor);
+ }
+ ///
+ /// Конструктор
+ ///
+ /// Ширина прорисовки танка
+ /// Высота прорисовки танка
+ protected DrawningTank2(int drawningTankWidth, int drawningTankHeight) : this()
+ {
+ _drawningTankWidth = drawningTankWidth;
+ _drawningTankHeight = drawningTankHeight;
+ }
+
+ ///
+ /// Установка границ поля
+ ///
+ /// Ширина поля
+ /// Высота поля
+ /// true - границы заданы, false - проверка не пройдена , нельзя разместить объект в этих размерах
+ public bool SetPictureSize(int width, int height)
+ {
+
+ if (height < _drawningTankHeight || width < _drawningTankWidth)
+ {
+ return false;
+ }
+ _pictureHeight = height;
+ _pictureWidth = width;
+ if (_startPosX != null && _startPosY != null)
+ {
+ if (_startPosX < 0) _startPosX = 0;
+ if (_startPosY < 0) _startPosY = 0;
+ if (_pictureHeight.Value < _startPosY + _drawningTankHeight)
+ {
+ _startPosY = _pictureHeight - _drawningTankHeight;
+ }
+ if (_pictureWidth.Value < _startPosX + _drawningTankWidth)
+ {
+ _startPosX = _pictureWidth - _drawningTankWidth;
+ }
+ }
+
+ return true;
+ }
+ ///
+ /// Установка позиции
+ ///
+ /// Координата X
+ /// Координата Y
+ public void SetPosition(int x, int y)
+ {
+ if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
+ {
+ return;
+ }
+ _startPosX = x;
+ _startPosY = y;
+ if (_startPosX < 0) _startPosX = 0;
+ if (_startPosY < 0) _startPosY = 0;
+ if (_pictureHeight.Value < _startPosY + _drawningTankHeight)
+ {
+ _startPosY = _pictureHeight - _drawningTankHeight;
+ }
+ if (_pictureWidth.Value < _startPosX + _drawningTankWidth)
+ {
+ _startPosX = _pictureWidth - _drawningTankWidth;
+ }
+
+ }
+ ///
+ /// Изменение направления перемещения
+ ///
+ /// направление
+ ///
+ public bool MoveTransport(DirectionType dicretion)
+ {
+ if (EntityTank2 == null || _startPosX == null || _startPosY == null)
+ {
+ return false;
+ }
+ switch (dicretion)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX.Value - EntityTank2.Step > 0)
+ {
+ _startPosX -= (int)EntityTank2.Step;
+ }
+ return true;
+ //вправо
+ case DirectionType.Right:
+ if (_startPosX.Value + _drawningTankWidth + EntityTank2.Step < _pictureWidth)
+ {
+ _startPosX += (int)EntityTank2.Step;
+ }
+ return true;
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY.Value - EntityTank2.Step > 0)
+ {
+ _startPosY -= (int)EntityTank2.Step;
+ }
+ return true;
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY + EntityTank2.Step + _drawningTankHeight < _pictureHeight)
+ {
+ _startPosY += (int)EntityTank2.Step;
+ }
+ return true;
+ default:
+ return false;
+ }
+
+ }
+
+ ///
+ /// прорисовка танка
+ ///
+ ///
+ public virtual void DrawTransport(Graphics g)
+ {
+ if (EntityTank2 == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+ Pen pen = new(Color.Black);
+ Brush Br = new SolidBrush(EntityTank2.BodyColor);
+ //основная часть танка
+ g.DrawRectangle(pen, _startPosX.Value + 6, _startPosY.Value + 20, 135, 20);
+ g.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value, 55, 20);
+
+ g.FillRectangle(Br, _startPosX.Value + 6, _startPosY.Value + 20, 135, 20);
+ g.FillRectangle(Br, _startPosX.Value + 45, _startPosY.Value, 55, 20);
+
+ //гусеницы
+
+ g.DrawArc(pen, _startPosX.Value, _startPosY.Value + 40, 15, 30, 100, 170);
+ g.DrawArc(pen, _startPosX.Value + 135, _startPosY.Value + 40, 15, 30, -90, 170);
+ g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 40, _startPosX.Value + 145, _startPosY.Value + 40);
+ g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 70, _startPosX.Value + 145, _startPosY.Value + 70);
+ Pen WidePen = new(Color.Black);
+ WidePen.Width = 2;
+ g.DrawEllipse(WidePen, _startPosX.Value, _startPosY.Value + 40, 24, 24);
+ g.DrawEllipse(WidePen, _startPosX.Value + 125, _startPosY.Value + 40, 24, 24);
+
+ //катки
+ g.DrawEllipse(pen, _startPosX.Value + 26, _startPosY.Value + 50, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 52, _startPosY.Value + 50, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 50, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 104, _startPosY.Value + 50, 20, 20);
+
+
+ g.DrawEllipse(pen, _startPosX.Value + 49, _startPosY.Value + 40, 5, 5);
+ g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 40, 5, 5);
+ g.DrawEllipse(pen, _startPosX.Value + 101, _startPosY.Value + 40, 5, 5);
+
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/Entities/EntityTank1.cs b/ProjectTank №3/ProjectTank/Entities/EntityTank1.cs
new file mode 100644
index 0000000..9275607
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/Entities/EntityTank1.cs
@@ -0,0 +1,44 @@
+using ProjectTank.Entities;
+
+namespace ProjectTank
+{
+ ///
+ /// Класс-сущность танк
+ ///
+ public class EntityTank1 : EntityTank2
+
+ {
+ ///
+ /// Дополнительный цвет (для опциональных элементов)
+ ///
+ public Color AdditionalColor { get; private set; }
+
+ ///
+ /// Признак (опция) наличия пушки
+ ///
+ public bool Gun { get; private set; }
+
+
+ ///
+ /// Признак (опция) наличия Пулемета на башне
+ /// ///
+ public bool MachinGun { get; private set; }
+
+ ///
+ /// Конструктор объекта-класса Танка
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Пушка танка
+ /// Пулемет на башне
+ public EntityTank1(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machinGun) : base(speed, weight, bodyColor)
+ {
+ AdditionalColor = additionalColor;
+ MachinGun = machinGun;
+ Gun = gun;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/Entities/EntityTank2.cs b/ProjectTank №3/ProjectTank/Entities/EntityTank2.cs
new file mode 100644
index 0000000..56fc366
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/Entities/EntityTank2.cs
@@ -0,0 +1,37 @@
+namespace ProjectTank.Entities
+{
+ public class EntityTank2
+ {
+ ///
+ /// скорость
+ ///
+ public int Speed { get; private set; }
+
+ ///
+ /// вес
+ ///
+ public double Weight { get; private set; }
+
+ ///
+ /// основный цвет
+ ///
+ public Color BodyColor { get; private set; }
+ ///
+ /// шаг
+ ///
+ public double Step => Speed * 100 / Weight;
+ ///
+ /// Конструктор сущности
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+
+ public EntityTank2(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+ }
+}
diff --git a/ProjectTank №3/ProjectTank/FormTank.Designer.cs b/ProjectTank №3/ProjectTank/FormTank.Designer.cs
new file mode 100644
index 0000000..9890852
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/FormTank.Designer.cs
@@ -0,0 +1,159 @@
+using static System.Net.Mime.MediaTypeNames;
+using System.Windows.Forms;
+using System.Xml.Linq;
+
+namespace ProjectTank
+{
+ partial class FormTank
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ pictureBoxTanks = new PictureBox();
+ buttonLeft = new Button();
+ buttonUp = new Button();
+ buttonRight = new Button();
+ buttonDown = new Button();
+ СomboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxTanks).BeginInit();
+ SuspendLayout();
+ //
+ // pictureBoxTanks
+ //
+ pictureBoxTanks.Dock = DockStyle.Fill;
+ pictureBoxTanks.Location = new Point(0, 0);
+ pictureBoxTanks.Margin = new Padding(3, 4, 3, 4);
+ pictureBoxTanks.Name = "pictureBoxTanks";
+ pictureBoxTanks.Size = new Size(950, 637);
+ pictureBoxTanks.TabIndex = 0;
+ pictureBoxTanks.TabStop = false;
+ pictureBoxTanks.Click += ButtonMove_Click;
+ //
+ // buttonLeft
+ //
+ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
+ buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonLeft.Location = new Point(768, 568);
+ buttonLeft.Margin = new Padding(3, 4, 3, 4);
+ buttonLeft.Name = "buttonLeft";
+ buttonLeft.Size = new Size(46, 53);
+ buttonLeft.TabIndex = 2;
+ buttonLeft.UseVisualStyleBackColor = true;
+ buttonLeft.Click += ButtonMove_Click;
+ //
+ // buttonUp
+ //
+ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonUp.BackgroundImage = Properties.Resources.arrowUp;
+ buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUp.Location = new Point(821, 507);
+ buttonUp.Margin = new Padding(3, 4, 3, 4);
+ buttonUp.Name = "buttonUp";
+ buttonUp.Size = new Size(46, 53);
+ buttonUp.TabIndex = 3;
+ buttonUp.UseVisualStyleBackColor = true;
+ buttonUp.Click += ButtonMove_Click;
+ //
+ // buttonRight
+ //
+ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonRight.BackgroundImage = Properties.Resources.arrowRight;
+ buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
+ buttonRight.Location = new Point(873, 568);
+ buttonRight.Margin = new Padding(3, 4, 3, 4);
+ buttonRight.Name = "buttonRight";
+ buttonRight.Size = new Size(46, 53);
+ buttonRight.TabIndex = 4;
+ buttonRight.UseVisualStyleBackColor = true;
+ buttonRight.Click += ButtonMove_Click;
+ //
+ // buttonDown
+ //
+ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonDown.BackgroundImage = Properties.Resources.arrowDown;
+ buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDown.Location = new Point(821, 568);
+ buttonDown.Margin = new Padding(3, 4, 3, 4);
+ buttonDown.Name = "buttonDown";
+ buttonDown.Size = new Size(46, 53);
+ buttonDown.TabIndex = 5;
+ buttonDown.UseVisualStyleBackColor = true;
+ buttonDown.Click += ButtonMove_Click;
+ //
+ // СomboBoxStrategy
+ //
+ СomboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ СomboBoxStrategy.FormattingEnabled = true;
+ СomboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
+ СomboBoxStrategy.Location = new Point(798, 16);
+ СomboBoxStrategy.Margin = new Padding(3, 4, 3, 4);
+ СomboBoxStrategy.Name = "СomboBoxStrategy";
+ СomboBoxStrategy.Size = new Size(138, 28);
+ СomboBoxStrategy.TabIndex = 7;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(850, 67);
+ buttonStrategyStep.Margin = new Padding(3, 4, 3, 4);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(86, 31);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += ButtonStrategyStep_Ckick;
+ //
+ // FormTank
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(950, 637);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(СomboBoxStrategy);
+ Controls.Add(buttonDown);
+ Controls.Add(buttonRight);
+ Controls.Add(buttonUp);
+ Controls.Add(buttonLeft);
+ Controls.Add(pictureBoxTanks);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormTank";
+ Text = "FormTank";
+ ((System.ComponentModel.ISupportInitialize)pictureBoxTanks).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxTanks;
+ private Button buttonLeft;
+ private Button buttonUp;
+ private Button buttonRight;
+ private Button buttonDown;
+ private ComboBox СomboBoxStrategy;
+ private Button buttonStrategyStep;
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/FormTank.cs b/ProjectTank №3/ProjectTank/FormTank.cs
new file mode 100644
index 0000000..9a4dfa7
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/FormTank.cs
@@ -0,0 +1,122 @@
+using ProjectTank.Drawnings;
+using ProjectTank.Entities;
+using ProjectTank.MovementStrategy;
+
+namespace ProjectTank
+{
+ ///
+ /// Форма работы с объектом "Танк"
+ ///
+ public partial class FormTank : Form
+ {
+ ///
+ /// Поле-объект для прорисовки объекта
+ ///
+ private DrawningTank2? _drawningTank;
+
+ ///
+ /// Стратегия перемещения
+ ///
+ private AbstractStrategy? _strategy;
+ public DrawningTank2 SetTank
+ {
+ set
+ {
+ _drawningTank = value;
+ _drawningTank.SetPictureSize(pictureBoxTanks.Width, pictureBoxTanks.Height);
+ СomboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+ ///
+ /// Конструктор формы
+ ///
+ public FormTank()
+ {
+ InitializeComponent();
+ _strategy = null;
+ }
+ ///
+ /// Метод прорисовки танка
+ ///
+ private void Draw()
+ {
+ if (_drawningTank == null)
+ {
+ return;
+ }
+ Bitmap bmp = new(pictureBoxTanks.Width, pictureBoxTanks.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningTank.DrawTransport(gr);
+ pictureBoxTanks.Image = bmp;
+ }
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_drawningTank == null)
+ {
+ return;
+ }
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ bool result = false;
+ switch (name)
+ {
+ case "buttonUp":
+ result = _drawningTank.MoveTransport(DirectionType.Up);
+ break;
+ case "buttonLeft":
+ result = _drawningTank.MoveTransport(DirectionType.Left);
+ break;
+ case "buttonRight":
+ result = _drawningTank.MoveTransport(DirectionType.Right);
+ break;
+ case "buttonDown":
+ result = _drawningTank.MoveTransport(DirectionType.Down);
+ break;
+ }
+ if (result)
+ {
+ Draw();
+ }
+ }
+ ///
+ /// Обработка нажатия кнопки "Шаг"
+ ///
+ ///
+ ///
+ private void ButtonStrategyStep_Ckick(object sender, EventArgs e)
+ {
+ if (_drawningTank == null)
+ {
+ return;
+ }
+ if (СomboBoxStrategy.Enabled)
+ {
+ _strategy = СomboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(new MoveableTank(_drawningTank),
+ pictureBoxTanks.Width, pictureBoxTanks.Height);
+ }
+ if (_strategy == null)
+ {
+ return;
+ }
+ СomboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ СomboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/FormTank.resx b/ProjectTank №3/ProjectTank/FormTank.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/FormTank.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/FormTankCollection.Designer.cs b/ProjectTank №3/ProjectTank/FormTankCollection.Designer.cs
new file mode 100644
index 0000000..5c77734
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/FormTankCollection.Designer.cs
@@ -0,0 +1,188 @@
+using static System.Net.Mime.MediaTypeNames;
+using System.Windows.Forms;
+using System.Xml.Linq;
+
+namespace ProjectTank
+{
+ partial class FormTankCollection
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ groupBoxTools = new GroupBox();
+ buttonRefresh = new Button();
+ buttonGoToCheck = new Button();
+ buttonRemoveTank = new Button();
+ maskedTextBox = new MaskedTextBox();
+ buttonAddTank1 = new Button();
+ buttonAddTank2 = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGoToCheck);
+ groupBoxTools.Controls.Add(buttonRemoveTank);
+ groupBoxTools.Controls.Add(maskedTextBox);
+ groupBoxTools.Controls.Add(buttonAddTank1);
+ groupBoxTools.Controls.Add(buttonAddTank2);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(700, 0);
+ groupBoxTools.Margin = new Padding(3, 4, 3, 4);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Padding = new Padding(3, 4, 3, 4);
+ groupBoxTools.Size = new Size(214, 600);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(7, 505);
+ buttonRefresh.Margin = new Padding(3, 4, 3, 4);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(200, 47);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonGoToCheck.Location = new Point(7, 403);
+ buttonGoToCheck.Margin = new Padding(3, 4, 3, 4);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(200, 47);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveTank
+ //
+ buttonRemoveTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveTank.Location = new Point(7, 321);
+ buttonRemoveTank.Margin = new Padding(3, 4, 3, 4);
+ buttonRemoveTank.Name = "buttonRemoveTank";
+ buttonRemoveTank.Size = new Size(200, 47);
+ buttonRemoveTank.TabIndex = 4;
+ buttonRemoveTank.Text = "Удаление танка";
+ buttonRemoveTank.UseVisualStyleBackColor = true;
+ buttonRemoveTank.Click += buttonRemoveTank_Click;
+ //
+ // maskedTextBox
+ //
+ maskedTextBox.Location = new Point(7, 283);
+ maskedTextBox.Margin = new Padding(3, 4, 3, 4);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(193, 27);
+ maskedTextBox.TabIndex = 3;
+ maskedTextBox.ValidatingType = typeof(int);
+ //
+ // buttonAddTank1
+ //
+ buttonAddTank1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTank1.Location = new Point(7, 177);
+ buttonAddTank1.Margin = new Padding(3, 4, 3, 4);
+ buttonAddTank1.Name = "buttonAddTank1";
+ buttonAddTank1.Size = new Size(200, 47);
+ buttonAddTank1.TabIndex = 2;
+ buttonAddTank1.Text = "Добавление Tank1";
+ buttonAddTank1.UseVisualStyleBackColor = true;
+ buttonAddTank1.Click += ButtonAddBattleTank_Click;
+ //
+ // buttonAddTank2
+ //
+ buttonAddTank2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTank2.Location = new Point(7, 123);
+ buttonAddTank2.Margin = new Padding(3, 4, 3, 4);
+ buttonAddTank2.Name = "buttonAddTank2";
+ buttonAddTank2.Size = new Size(200, 47);
+ buttonAddTank2.TabIndex = 1;
+ buttonAddTank2.Text = "Добавление Tank2";
+ buttonAddTank2.UseVisualStyleBackColor = true;
+ buttonAddTank2.Click += ButtonAddTank_Click;
+ //
+ // comboBoxSelectorCompany
+ //
+ comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectorCompany.FormattingEnabled = true;
+ comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
+ comboBoxSelectorCompany.Location = new Point(7, 33);
+ comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(199, 28);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // pictureBox
+ //
+ pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Location = new Point(0, 0);
+ pictureBox.Margin = new Padding(3, 4, 3, 4);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(700, 600);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormTankCollection
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(914, 600);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormTankCollection";
+ Text = "Коллекция танков";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddTank1;
+ private Button buttonAddTank2;
+ private MaskedTextBox maskedTextBox;
+ private PictureBox pictureBox;
+ private Button buttonRemoveTank;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/FormTankCollection.cs b/ProjectTank №3/ProjectTank/FormTankCollection.cs
new file mode 100644
index 0000000..04909f8
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/FormTankCollection.cs
@@ -0,0 +1,151 @@
+using ProjectTank.CollectionGenericObjects;
+using ProjectTank.Drawnings;
+using System.Windows.Forms;
+
+namespace ProjectTank
+{
+ ///
+ ///
+ ///
+ public partial class FormTankCollection : Form
+ {
+ ///
+ ///
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormTankCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new TankBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создоваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null) return;
+
+ Random random = new();
+ DrawningTank2 drawningTank;
+ switch (type)
+ {
+ case nameof(DrawningTank2):
+ drawningTank = new DrawningTank2(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random));
+ break;
+ case nameof(DrawningTank1):
+ bool randomTrack = Convert.ToBoolean(random.Next(0, 2));
+ drawningTank = new DrawningTank1(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), randomTrack, (randomTrack ? Convert.ToBoolean(random.Next(0, 2)) : true));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawningTank != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ ///
+ /// Получение цвета
+ ///
+ /// Генератор случайных чесел
+ ///
+ private static Color GetColor(Random random)
+ {
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new ColorDialog();
+
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
+ return color;
+ }
+
+ private void ButtonAddTank_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningTank2));
+ }
+
+ private void ButtonAddBattleTank_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningTank1));
+ }
+
+ private void buttonRemoveTank_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return;
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
+
+ int position = Convert.ToInt32(maskedTextBox.Text);
+
+ if (_company - position != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null) return;
+
+ DrawningTank2? tank = null;
+ int coutner = 100;
+
+ while (tank == null)
+ {
+ tank = _company.GetRandomObject();
+ coutner--;
+ if (coutner <= 0) break;
+ }
+
+ if (tank == null) return;
+
+ FormTank form = new()
+ {
+ SetTank = tank
+ };
+ form.ShowDialog();
+ }
+
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null) return;
+ pictureBox.Image = _company.Show();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/FormTankCollection.resx b/ProjectTank №3/ProjectTank/FormTankCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/FormTankCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/MovementStrategy/AbstractStrategy.cs b/ProjectTank №3/ProjectTank/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..b012cf0
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,118 @@
+namespace ProjectTank.MovementStrategy
+{
+ public abstract class AbstractStrategy
+ {
+ ///
+ /// Перемещаемый объект
+ ///
+ private IMoveableObject? _moveableObject;
+ ///
+ /// Статус перемещения
+ ///
+ private StrategyStatus _state = StrategyStatus.NotInit;
+ ///
+ /// Ширина поля
+ ///
+ protected int FieldWidth { get; private set; }
+ ///
+ /// Высота поля
+ ///
+ protected int FieldHeight { get; private set; }
+ ///
+ /// Статус перемещения
+ ///
+ public StrategyStatus GetStatus() { return _state; }
+ ///
+ /// Установка данных
+ ///
+ /// Перемещаемый объект
+ /// Ширина поля
+ /// Высота поля
+ public void SetData(IMoveableObject moveableObject, int width, int height)
+ {
+ if (moveableObject == null)
+ {
+ _state = StrategyStatus.NotInit;
+ return;
+ }
+ _state = StrategyStatus.InProgress;
+ _moveableObject = moveableObject;
+ FieldWidth = width;
+ FieldHeight = height;
+ }
+ ///
+ /// Шаг перемещения
+ ///
+ public void MakeStep()
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return;
+ }
+ if (IsTargetDestinaion())
+ {
+ _state = StrategyStatus.Finish;
+ return;
+ }
+ MoveToTarget();
+ }
+ ///
+ /// Перемещение влево
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveLeft() => MoveTo(MovementDirection.Left);
+ ///
+ /// Перемещение вправо
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveRight() => MoveTo(MovementDirection.Right);
+ ///
+ /// Перемещение вверх
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveUp() => MoveTo(MovementDirection.Up);
+ ///
+ /// Перемещение вниз
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveDown() => MoveTo(MovementDirection.Down);
+ ///
+ /// Параметры объекта
+ ///
+ protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
+ ///
+ /// Шаг объекта
+ ///
+ ///
+ protected int? GetStep()
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return null;
+ }
+ return _moveableObject?.GetStep;
+ }
+ ///
+ /// Перемещение к цели
+ ///
+ protected abstract void MoveToTarget();
+ ///
+ /// Достигнута ли цель
+ ///
+ ///
+ protected abstract bool IsTargetDestinaion();
+ ///
+ /// Попытка перемещения в требуемом направлении
+ ///
+ /// Направление
+ /// Результат попытки (true - удалось переместиться, false - неудача)
+ private bool MoveTo(MovementDirection movementDirection)
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return false;
+ }
+ return _moveableObject?.TryMoveObject(movementDirection) ?? false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/MovementStrategy/IMoveableObject.cs b/ProjectTank №3/ProjectTank/MovementStrategy/IMoveableObject.cs
new file mode 100644
index 0000000..1a1422f
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/MovementStrategy/IMoveableObject.cs
@@ -0,0 +1,23 @@
+namespace ProjectTank.MovementStrategy
+{
+ public interface IMoveableObject
+ {
+ ///
+ /// Получение координаты объекта
+ ///
+
+ ObjectParameters? GetObjectPosition { get; }
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ /// Направление
+ /// true - объект перемещен, false - перемещение невозможно
+ bool TryMoveObject(MovementDirection direction);
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/MovementStrategy/MoveToBorder.cs b/ProjectTank №3/ProjectTank/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..366e6a3
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,38 @@
+namespace ProjectTank.MovementStrategy;
+
+internal class MoveToBorder : AbstractStrategy
+{
+ ///
+ /// Стратегия перемещения объекта к Краю экрана
+ ///
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.RightBorder + GetStep() >= FieldWidth &&
+ objParams.DownBorder + GetStep() >= FieldHeight;
+ }
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+
+ int diffX = objParams.RightBorder - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ MoveRight();
+ }
+
+ int diffY = objParams.DownBorder - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ MoveDown();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/MovementStrategy/MoveToCenter.cs b/ProjectTank №3/ProjectTank/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..df46ff5
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,53 @@
+namespace ProjectTank.MovementStrategy
+{
+ ///
+ /// Стратегия перемещения объекта в центр экрана
+ ///
+ public class MoveToCenter : AbstractStrategy
+ {
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2
+ && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
+ objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
+ && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
+ }
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/MovementStrategy/MoveableTank.cs b/ProjectTank №3/ProjectTank/MovementStrategy/MoveableTank.cs
new file mode 100644
index 0000000..4f4b947
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/MovementStrategy/MoveableTank.cs
@@ -0,0 +1,59 @@
+using ProjectTank.Drawnings;
+
+namespace ProjectTank.MovementStrategy
+{
+ public class MoveableTank : IMoveableObject
+ {
+ ///
+ /// Поле-объект класса или его DrawningTank наследника
+ ///
+ private readonly DrawningTank2? _tank = null;
+ ///
+ /// Конструктор
+ ///
+ /// Объект класса DrawningBoat
+ public MoveableTank(DrawningTank2 tank)
+ {
+ _tank = tank;
+ }
+
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_tank == null || _tank.EntityTank2 == null ||
+ !_tank.GetPosX.HasValue || !_tank.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(_tank.GetPosX.Value,
+ _tank.GetPosY.Value, _tank.GetWidth, _tank.GetHeight);
+ }
+ }
+ public int GetStep => (int)(_tank?.EntityTank2?.Step ?? 0);
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (_tank == null || _tank.EntityTank2 == null)
+ {
+ return false;
+ }
+ return _tank.MoveTransport(GetDirectionType(direction));
+ }
+ ///
+ /// Конвертация из MovementDirection в DirectionType
+ ///
+ /// MovementDirection
+ /// DirectionType
+ private static DirectionType GetDirectionType(MovementDirection direction)
+ {
+ return direction switch
+ {
+ MovementDirection.Left => DirectionType.Left,
+ MovementDirection.Right => DirectionType.Right,
+ MovementDirection.Up => DirectionType.Up,
+ MovementDirection.Down => DirectionType.Down,
+ _ => DirectionType.Unknow,
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/MovementStrategy/MovementDirection.cs b/ProjectTank №3/ProjectTank/MovementStrategy/MovementDirection.cs
new file mode 100644
index 0000000..10ffa6b
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/MovementStrategy/MovementDirection.cs
@@ -0,0 +1,22 @@
+namespace ProjectTank.MovementStrategy
+{
+ public enum MovementDirection
+ {
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+ ///
+ /// Влево
+ ///
+ Left = 3,
+ ///
+ /// Вправо
+ ///
+ Right = 4,
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/MovementStrategy/ObjectParameters.cs b/ProjectTank №3/ProjectTank/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..656c9c2
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,60 @@
+namespace ProjectTank.MovementStrategy
+{
+ public class ObjectParameters
+ {
+ ///
+ /// Координата X
+ ///
+ private readonly int _x;
+ ///
+ /// Координата Y
+ ///
+ private readonly int _y;
+ ///
+ /// Ширина объекта
+ ///
+ private readonly int _width;
+ ///
+ /// Высота объекта
+ ///
+ private readonly int _height;
+ ///
+ /// Левая граница
+ ///
+ public int LeftBorder => _x;
+ ///
+ /// Верхняя граница
+ ///
+ public int TopBorder => _y;
+ ///
+ /// Правая граница
+ ///
+ public int RightBorder => _x + _width;
+ ///
+ /// Нижняя граница
+ ///
+ public int DownBorder => _y + _height;
+ ///
+ /// Середина объекта
+ ///
+ public int ObjectMiddleHorizontal => _x + _width / 2;
+ ///
+ /// Середина объекта
+ ///
+ public int ObjectMiddleVertical => _y + _height / 2;
+ ///
+ /// Конструктор
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина объекта
+ /// Высота объекта
+ public ObjectParameters(int x, int y, int width, int height)
+ {
+ _x = x;
+ _y = y;
+ _width = width;
+ _height = height;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/MovementStrategy/StrategyStatus.cs b/ProjectTank №3/ProjectTank/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..c10e61d
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,18 @@
+namespace ProjectTank.MovementStrategy
+{
+ public enum StrategyStatus
+ {
+ ///
+ /// Все готово к началу
+ ///
+ NotInit,
+ ///
+ /// Выполняется
+ ///
+ InProgress,
+ ///
+ /// Завершино
+ ///
+ Finish
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/Program.cs b/ProjectTank №3/ProjectTank/Program.cs
new file mode 100644
index 0000000..94ae4d7
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/Program.cs
@@ -0,0 +1,17 @@
+namespace ProjectTank
+{
+ internal static class Program
+ {
+ ///
+ /// The main entry point for the application.
+ ///
+ [STAThread]
+ static void Main()
+ {
+ // To customize application configuration such as set high DPI settings or default font,
+ // see https://aka.ms/applicationconfiguration.
+ ApplicationConfiguration.Initialize();
+ Application.Run(new FormTankCollection());
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/ProjectTank.csproj b/ProjectTank №3/ProjectTank/ProjectTank.csproj
new file mode 100644
index 0000000..244387d
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/ProjectTank.csproj
@@ -0,0 +1,26 @@
+
+
+
+ WinExe
+ net7.0-windows
+ enable
+ true
+ enable
+
+
+
+
+ True
+ True
+ Resources.resx
+
+
+
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+
+
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/Properties/Resources.Designer.cs b/ProjectTank №3/ProjectTank/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..e20507b
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/Properties/Resources.Designer.cs
@@ -0,0 +1,103 @@
+//------------------------------------------------------------------------------
+//
+// Этот код создан программой.
+// Исполняемая версия:4.0.30319.42000
+//
+// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
+// повторной генерации кода.
+//
+//------------------------------------------------------------------------------
+
+namespace ProjectTank.Properties {
+ using System;
+
+
+ ///
+ /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
+ ///
+ // Этот класс создан автоматически классом StronglyTypedResourceBuilder
+ // с помощью такого средства, как ResGen или Visual Studio.
+ // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
+ // с параметром /str или перестройте свой проект VS.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectTank.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Перезаписывает свойство CurrentUICulture текущего потока для всех
+ /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowDown {
+ get {
+ object obj = ResourceManager.GetObject("arrowDown", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowLeft {
+ get {
+ object obj = ResourceManager.GetObject("arrowLeft", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowRight {
+ get {
+ object obj = ResourceManager.GetObject("arrowRight", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowUp {
+ get {
+ object obj = ResourceManager.GetObject("arrowUp", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+ }
+}
diff --git a/ProjectTank №3/ProjectTank/Properties/Resources.resx b/ProjectTank №3/ProjectTank/Properties/Resources.resx
new file mode 100644
index 0000000..fd4bdf3
--- /dev/null
+++ b/ProjectTank №3/ProjectTank/Properties/Resources.resx
@@ -0,0 +1,133 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+
+ ..\Resources\arrowRight.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\arrowDown.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\arrowLeft.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\arrowUp.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
\ No newline at end of file
diff --git a/ProjectTank №3/ProjectTank/Resources/arrowDown.jpg b/ProjectTank №3/ProjectTank/Resources/arrowDown.jpg
new file mode 100644
index 0000000..f21002e
Binary files /dev/null and b/ProjectTank №3/ProjectTank/Resources/arrowDown.jpg differ
diff --git a/ProjectTank №3/ProjectTank/Resources/arrowLeft.jpg b/ProjectTank №3/ProjectTank/Resources/arrowLeft.jpg
new file mode 100644
index 0000000..61b8dae
Binary files /dev/null and b/ProjectTank №3/ProjectTank/Resources/arrowLeft.jpg differ
diff --git a/ProjectTank №3/ProjectTank/Resources/arrowRight.jpg b/ProjectTank №3/ProjectTank/Resources/arrowRight.jpg
new file mode 100644
index 0000000..b440197
Binary files /dev/null and b/ProjectTank №3/ProjectTank/Resources/arrowRight.jpg differ
diff --git a/ProjectTank №3/ProjectTank/Resources/arrowUp.jpg b/ProjectTank №3/ProjectTank/Resources/arrowUp.jpg
new file mode 100644
index 0000000..e630cea
Binary files /dev/null and b/ProjectTank №3/ProjectTank/Resources/arrowUp.jpg differ
diff --git a/ProjectTank №4/ProjectTank.sln b/ProjectTank №4/ProjectTank.sln
new file mode 100644
index 0000000..a1561d4
--- /dev/null
+++ b/ProjectTank №4/ProjectTank.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.7.34024.191
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectTank", "ProjectTank\ProjectTank.csproj", "{E84822F4-E6D0-4691-A08D-4241A54BE837}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {E84822F4-E6D0-4691-A08D-4241A54BE837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E84822F4-E6D0-4691-A08D-4241A54BE837}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E84822F4-E6D0-4691-A08D-4241A54BE837}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E84822F4-E6D0-4691-A08D-4241A54BE837}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {90F6A650-635F-4AF8-BFD4-CC2A28015CD9}
+ EndGlobalSection
+EndGlobal
diff --git a/ProjectTank №4/ProjectTank/CollectionGenericObjects/AbsrtactCompany.cs b/ProjectTank №4/ProjectTank/CollectionGenericObjects/AbsrtactCompany.cs
new file mode 100644
index 0000000..0730e8f
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/CollectionGenericObjects/AbsrtactCompany.cs
@@ -0,0 +1,115 @@
+using ProjectTank.Drawnings;
+using ProjectTank.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 100;
+
+ ///
+ /// Ширина окна
+ ///
+ protected readonly int _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ protected readonly int _pictureHeight;
+
+ ///
+ /// Коллекция автомобилей
+ ///
+ protected ICollectionGenericObjects? _collection = null;
+
+ ///
+ /// Вычисление максимального количества элементов, который можно разместить в окне
+ ///
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+
+ ///
+ /// Конструктор
+ ///
+ /// Ширина окна
+ /// Высота окна
+ /// Коллекция автомобилей
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ {
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = collection;
+ _collection.SetMaxCount = GetMaxCount;
+ }
+
+ ///
+ /// Перегрузка оператора сложения для класса
+ ///
+ /// Компания
+ /// Добавляемый объект
+ ///
+ public static int operator +(AbstractCompany company, DrawningTank2 tank)
+ {
+ return company?._collection.Insert(tank) ?? -1;
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningTank2? operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position) ?? null;
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningTank2? GetRandomObject()
+ {
+ Random rnd = new();
+ return _collection?.Get(rnd.Next(GetMaxCount));
+ }
+
+ ///
+ /// Вывод всей коллекции
+ ///
+ ///
+ public Bitmap? Show()
+ {
+ Bitmap bitmap = new(_pictureWidth, _pictureHeight);
+ Graphics graphics = Graphics.FromImage(bitmap);
+ DrawBackgound(graphics);
+
+ SetObjectsPosition();
+ for (int i = 0; i < (_collection?.Count ?? 0); ++i)
+ {
+ DrawningTank2? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectTank №4/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..4f00b75
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,49 @@
+namespace ProjectTank.CollectionGenericObjects
+{
+ ///
+ /// Интерфейс описания действий для набора хранимых данных
+ ///
+ ///
+ public interface ICollectionGenericObjects
+ where T : class
+ {
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj);
+
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло удачно, false - удаление не удалось
+ T? Remove(int position);
+
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTank №4/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..4326cf4
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,113 @@
+using ProjectTank.CollectionGenericObjects;
+///
+/// Параметризованный набор объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public class MassiveGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private T?[] _collection;
+
+ public int Count => _collection.Length;
+
+ public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
+
+ ///
+ /// Конструктор
+ ///
+ public MassiveGenericObjects()
+ {
+ _collection = Array.Empty();
+ }
+
+ public T? Get(int position)
+ {
+ if (position >= 0 && position < Count)
+ {
+ return _collection[position];
+ }
+
+ return null;
+ }
+
+ public int Insert(T obj)
+ {
+ // вставка в свободное место набора
+ for (int i = 0; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ // проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
+
+ // проверка, что элемент массива по этой позиции пустой, если нет, то
+ // ищется свободное место после этой позиции и идет вставка туда
+ // если нет после, ищем до
+ if (_collection[position] != null)
+ {
+ bool pushed = false;
+ for (int index = position + 1; index < Count; index++)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+
+ if (!pushed)
+ {
+ for (int index = position - 1; index >= 0; index--)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+ }
+
+ if (!pushed)
+ {
+ return position;
+ }
+ }
+
+ // вставка
+ _collection[position] = obj;
+ return position;
+ }
+
+ public T? Remove(int position)
+ {
+ // проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+
+ if (_collection[position] == null) return null;
+
+ T? temp = _collection[position];
+ _collection[position] = null;
+ return temp;
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/CollectionGenericObjects/TankBase.cs b/ProjectTank №4/ProjectTank/CollectionGenericObjects/TankBase.cs
new file mode 100644
index 0000000..f1eac54
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/CollectionGenericObjects/TankBase.cs
@@ -0,0 +1,56 @@
+using ProjectTank.Drawnings;
+
+namespace ProjectTank.CollectionGenericObjects
+{
+ public class TankBase : AbstractCompany
+ {
+ public TankBase(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+
+ }
+ protected override void DrawBackgound(Graphics g)
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+ Pen pen = new(Color.Black, 2);
+ for (int i = 0; i < width + 1; i++)
+ {
+ for (int j = 0; j < height + 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5 + _placeSizeWidth - 45, j * _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5, j * _placeSizeHeight - _placeSizeHeight);
+ }
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ int TankWidth = 0;
+ int TankHeight = 0;
+
+ for (int i = 0; i < (_collection?.Count ?? 0); i++)
+ {
+ if (_collection?.Get(i) != null)
+ {
+ _collection.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i)?.SetPosition(_placeSizeWidth * TankWidth + 20, TankHeight * _placeSizeHeight + 5);
+ }
+
+ if (TankWidth < width)
+ TankWidth++;
+ else
+ {
+ TankWidth = 0;
+ TankHeight++;
+ }
+ if (TankHeight > height - 1)
+ {
+ return;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/Drawnings/DirectionType.cs b/ProjectTank №4/ProjectTank/Drawnings/DirectionType.cs
new file mode 100644
index 0000000..12d0cdf
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/Drawnings/DirectionType.cs
@@ -0,0 +1,30 @@
+namespace ProjectTank.Drawnings
+{
+ ///
+ /// направление перемещенния
+ ///
+ public enum DirectionType
+ {
+ ///
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+ ///
+ /// Влево
+ ///
+ Left = 3,
+ ///
+ /// Вправо
+ ///
+ Right = 4,
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/Drawnings/DrawningTank1.cs b/ProjectTank №4/ProjectTank/Drawnings/DrawningTank1.cs
new file mode 100644
index 0000000..0b5acd6
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/Drawnings/DrawningTank1.cs
@@ -0,0 +1,63 @@
+using ProjectTank.Entities;
+
+namespace ProjectTank.Drawnings;
+///
+/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+///
+public class DrawningTank1 : DrawningTank2
+{
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия пушки
+ /// признак наличия пулемета
+ ///
+ public DrawningTank1(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machinGun) : base(150, 87)
+ {
+ EntityTank2 = new EntityTank1(speed, weight, bodyColor, additionalColor, gun, machinGun);
+ }
+
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityTank2 == null || EntityTank2 is not EntityTank1 Tank1 || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+ Pen pen = new(Color.Black);
+ Brush additionalBrush = new SolidBrush(Tank1.AdditionalColor);
+
+ if (Tank1.Gun)
+ {
+ g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 30, 45, 5);
+
+ g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value + 30, 45, 5);
+ }
+
+ //пулемет
+ if (Tank1.MachinGun)
+ {
+ g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 15, 16, 5);
+ g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 10, 5, 5);
+ g.DrawRectangle(pen, _startPosX.Value + 71, _startPosY.Value + 3, 7, 7);
+ g.DrawRectangle(pen, _startPosX.Value + 55, _startPosY.Value + 5, 15, 3);
+
+ g.FillRectangle(additionalBrush, _startPosX.Value + 65, _startPosY.Value + 15, 16, 5);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 72, _startPosY.Value + 10, 5, 5);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 71, _startPosY.Value + 3, 7, 7);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 55, _startPosY.Value + 5, 15, 3);
+ }
+ _startPosY += 20;
+ base.DrawTransport(g);
+ _startPosY -= 20;
+
+ }
+
+}
diff --git a/ProjectTank №4/ProjectTank/Drawnings/DrawningTank2.cs b/ProjectTank №4/ProjectTank/Drawnings/DrawningTank2.cs
new file mode 100644
index 0000000..63d9c11
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/Drawnings/DrawningTank2.cs
@@ -0,0 +1,240 @@
+using ProjectTank.Entities;
+namespace ProjectTank.Drawnings
+{
+ public class DrawningTank2
+ {
+ ///
+ /// класс - сущность
+ ///
+ public EntityTank2? EntityTank2 { get; protected set; }
+
+ ///
+ /// ширина окна
+ ///
+ private int? _pictureWidth;
+
+ ///
+ /// высота окна
+ ///
+ private int? _pictureHeight;
+
+ ///
+ /// Левая координата прорисовки танка
+ ///
+ protected int? _startPosX;
+
+ ///
+ /// Верхняя координата прорисовки танка
+ ///
+ protected int? _startPosY;
+
+ ///
+ /// ширина прорисовки танка
+ /// ///
+ private readonly int _drawningTankWidth = 150;
+
+ ///
+ /// высота прорисовки танка
+ ///
+ private readonly int _drawningTankHeight = 67;
+
+ ///
+ /// Координата X объекта
+ ///
+ public int? GetPosX => _startPosX;
+
+ ///
+ /// Координата Y объекта
+ ///
+ public int? GetPosY => _startPosY;
+
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningTankWidth;
+
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningTankHeight;
+
+ ///
+ /// Пустой конструктор
+ ///
+ private DrawningTank2()
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+ }
+
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес танка
+ /// Основной цвет
+ public DrawningTank2(int speed, double weight, Color bodyColor) : this()
+ {
+ EntityTank2 = new EntityTank2(speed, weight, bodyColor);
+ }
+ ///
+ /// Конструктор
+ ///
+ /// Ширина прорисовки танка
+ /// Высота прорисовки танка
+ protected DrawningTank2(int drawningTankWidth, int drawningTankHeight) : this()
+ {
+ _drawningTankWidth = drawningTankWidth;
+ _drawningTankHeight = drawningTankHeight;
+ }
+
+ ///
+ /// Установка границ поля
+ ///
+ /// Ширина поля
+ /// Высота поля
+ /// true - границы заданы, false - проверка не пройдена , нельзя разместить объект в этих размерах
+ public bool SetPictureSize(int width, int height)
+ {
+
+ if (height < _drawningTankHeight || width < _drawningTankWidth)
+ {
+ return false;
+ }
+ _pictureHeight = height;
+ _pictureWidth = width;
+ if (_startPosX != null && _startPosY != null)
+ {
+ if (_startPosX < 0) _startPosX = 0;
+ if (_startPosY < 0) _startPosY = 0;
+ if (_pictureHeight.Value < _startPosY + _drawningTankHeight)
+ {
+ _startPosY = _pictureHeight - _drawningTankHeight;
+ }
+ if (_pictureWidth.Value < _startPosX + _drawningTankWidth)
+ {
+ _startPosX = _pictureWidth - _drawningTankWidth;
+ }
+ }
+
+ return true;
+ }
+ ///
+ /// Установка позиции
+ ///
+ /// Координата X
+ /// Координата Y
+ public void SetPosition(int x, int y)
+ {
+ if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
+ {
+ return;
+ }
+ _startPosX = x;
+ _startPosY = y;
+ if (_startPosX < 0) _startPosX = 0;
+ if (_startPosY < 0) _startPosY = 0;
+ if (_pictureHeight.Value < _startPosY + _drawningTankHeight)
+ {
+ _startPosY = _pictureHeight - _drawningTankHeight;
+ }
+ if (_pictureWidth.Value < _startPosX + _drawningTankWidth)
+ {
+ _startPosX = _pictureWidth - _drawningTankWidth;
+ }
+
+ }
+ ///
+ /// Изменение направления перемещения
+ ///
+ /// направление
+ ///
+ public bool MoveTransport(DirectionType dicretion)
+ {
+ if (EntityTank2 == null || _startPosX == null || _startPosY == null)
+ {
+ return false;
+ }
+ switch (dicretion)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX.Value - EntityTank2.Step > 0)
+ {
+ _startPosX -= (int)EntityTank2.Step;
+ }
+ return true;
+ //вправо
+ case DirectionType.Right:
+ if (_startPosX.Value + _drawningTankWidth + EntityTank2.Step < _pictureWidth)
+ {
+ _startPosX += (int)EntityTank2.Step;
+ }
+ return true;
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY.Value - EntityTank2.Step > 0)
+ {
+ _startPosY -= (int)EntityTank2.Step;
+ }
+ return true;
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY + EntityTank2.Step + _drawningTankHeight < _pictureHeight)
+ {
+ _startPosY += (int)EntityTank2.Step;
+ }
+ return true;
+ default:
+ return false;
+ }
+
+ }
+
+ ///
+ /// прорисовка танка
+ ///
+ ///
+ public virtual void DrawTransport(Graphics g)
+ {
+ if (EntityTank2 == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+ Pen pen = new(Color.Black);
+ Brush Br = new SolidBrush(EntityTank2.BodyColor);
+ //основная часть танка
+ g.DrawRectangle(pen, _startPosX.Value + 6, _startPosY.Value + 20, 135, 20);
+ g.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value, 55, 20);
+
+ g.FillRectangle(Br, _startPosX.Value + 6, _startPosY.Value + 20, 135, 20);
+ g.FillRectangle(Br, _startPosX.Value + 45, _startPosY.Value, 55, 20);
+
+ //гусеницы
+
+ g.DrawArc(pen, _startPosX.Value, _startPosY.Value + 40, 15, 30, 100, 170);
+ g.DrawArc(pen, _startPosX.Value + 135, _startPosY.Value + 40, 15, 30, -90, 170);
+ g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 40, _startPosX.Value + 145, _startPosY.Value + 40);
+ g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 70, _startPosX.Value + 145, _startPosY.Value + 70);
+ Pen WidePen = new(Color.Black);
+ WidePen.Width = 2;
+ g.DrawEllipse(WidePen, _startPosX.Value, _startPosY.Value + 40, 24, 24);
+ g.DrawEllipse(WidePen, _startPosX.Value + 125, _startPosY.Value + 40, 24, 24);
+
+ //катки
+ g.DrawEllipse(pen, _startPosX.Value + 26, _startPosY.Value + 50, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 52, _startPosY.Value + 50, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 50, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 104, _startPosY.Value + 50, 20, 20);
+
+
+ g.DrawEllipse(pen, _startPosX.Value + 49, _startPosY.Value + 40, 5, 5);
+ g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 40, 5, 5);
+ g.DrawEllipse(pen, _startPosX.Value + 101, _startPosY.Value + 40, 5, 5);
+
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/Entities/EntityTank1.cs b/ProjectTank №4/ProjectTank/Entities/EntityTank1.cs
new file mode 100644
index 0000000..9275607
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/Entities/EntityTank1.cs
@@ -0,0 +1,44 @@
+using ProjectTank.Entities;
+
+namespace ProjectTank
+{
+ ///
+ /// Класс-сущность танк
+ ///
+ public class EntityTank1 : EntityTank2
+
+ {
+ ///
+ /// Дополнительный цвет (для опциональных элементов)
+ ///
+ public Color AdditionalColor { get; private set; }
+
+ ///
+ /// Признак (опция) наличия пушки
+ ///
+ public bool Gun { get; private set; }
+
+
+ ///
+ /// Признак (опция) наличия Пулемета на башне
+ /// ///
+ public bool MachinGun { get; private set; }
+
+ ///
+ /// Конструктор объекта-класса Танка
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Пушка танка
+ /// Пулемет на башне
+ public EntityTank1(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machinGun) : base(speed, weight, bodyColor)
+ {
+ AdditionalColor = additionalColor;
+ MachinGun = machinGun;
+ Gun = gun;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/Entities/EntityTank2.cs b/ProjectTank №4/ProjectTank/Entities/EntityTank2.cs
new file mode 100644
index 0000000..56fc366
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/Entities/EntityTank2.cs
@@ -0,0 +1,37 @@
+namespace ProjectTank.Entities
+{
+ public class EntityTank2
+ {
+ ///
+ /// скорость
+ ///
+ public int Speed { get; private set; }
+
+ ///
+ /// вес
+ ///
+ public double Weight { get; private set; }
+
+ ///
+ /// основный цвет
+ ///
+ public Color BodyColor { get; private set; }
+ ///
+ /// шаг
+ ///
+ public double Step => Speed * 100 / Weight;
+ ///
+ /// Конструктор сущности
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+
+ public EntityTank2(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+ }
+}
diff --git a/ProjectTank №4/ProjectTank/FormTank.Designer.cs b/ProjectTank №4/ProjectTank/FormTank.Designer.cs
new file mode 100644
index 0000000..9890852
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/FormTank.Designer.cs
@@ -0,0 +1,159 @@
+using static System.Net.Mime.MediaTypeNames;
+using System.Windows.Forms;
+using System.Xml.Linq;
+
+namespace ProjectTank
+{
+ partial class FormTank
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ pictureBoxTanks = new PictureBox();
+ buttonLeft = new Button();
+ buttonUp = new Button();
+ buttonRight = new Button();
+ buttonDown = new Button();
+ СomboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxTanks).BeginInit();
+ SuspendLayout();
+ //
+ // pictureBoxTanks
+ //
+ pictureBoxTanks.Dock = DockStyle.Fill;
+ pictureBoxTanks.Location = new Point(0, 0);
+ pictureBoxTanks.Margin = new Padding(3, 4, 3, 4);
+ pictureBoxTanks.Name = "pictureBoxTanks";
+ pictureBoxTanks.Size = new Size(950, 637);
+ pictureBoxTanks.TabIndex = 0;
+ pictureBoxTanks.TabStop = false;
+ pictureBoxTanks.Click += ButtonMove_Click;
+ //
+ // buttonLeft
+ //
+ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
+ buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonLeft.Location = new Point(768, 568);
+ buttonLeft.Margin = new Padding(3, 4, 3, 4);
+ buttonLeft.Name = "buttonLeft";
+ buttonLeft.Size = new Size(46, 53);
+ buttonLeft.TabIndex = 2;
+ buttonLeft.UseVisualStyleBackColor = true;
+ buttonLeft.Click += ButtonMove_Click;
+ //
+ // buttonUp
+ //
+ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonUp.BackgroundImage = Properties.Resources.arrowUp;
+ buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUp.Location = new Point(821, 507);
+ buttonUp.Margin = new Padding(3, 4, 3, 4);
+ buttonUp.Name = "buttonUp";
+ buttonUp.Size = new Size(46, 53);
+ buttonUp.TabIndex = 3;
+ buttonUp.UseVisualStyleBackColor = true;
+ buttonUp.Click += ButtonMove_Click;
+ //
+ // buttonRight
+ //
+ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonRight.BackgroundImage = Properties.Resources.arrowRight;
+ buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
+ buttonRight.Location = new Point(873, 568);
+ buttonRight.Margin = new Padding(3, 4, 3, 4);
+ buttonRight.Name = "buttonRight";
+ buttonRight.Size = new Size(46, 53);
+ buttonRight.TabIndex = 4;
+ buttonRight.UseVisualStyleBackColor = true;
+ buttonRight.Click += ButtonMove_Click;
+ //
+ // buttonDown
+ //
+ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonDown.BackgroundImage = Properties.Resources.arrowDown;
+ buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDown.Location = new Point(821, 568);
+ buttonDown.Margin = new Padding(3, 4, 3, 4);
+ buttonDown.Name = "buttonDown";
+ buttonDown.Size = new Size(46, 53);
+ buttonDown.TabIndex = 5;
+ buttonDown.UseVisualStyleBackColor = true;
+ buttonDown.Click += ButtonMove_Click;
+ //
+ // СomboBoxStrategy
+ //
+ СomboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ СomboBoxStrategy.FormattingEnabled = true;
+ СomboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
+ СomboBoxStrategy.Location = new Point(798, 16);
+ СomboBoxStrategy.Margin = new Padding(3, 4, 3, 4);
+ СomboBoxStrategy.Name = "СomboBoxStrategy";
+ СomboBoxStrategy.Size = new Size(138, 28);
+ СomboBoxStrategy.TabIndex = 7;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(850, 67);
+ buttonStrategyStep.Margin = new Padding(3, 4, 3, 4);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(86, 31);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += ButtonStrategyStep_Ckick;
+ //
+ // FormTank
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(950, 637);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(СomboBoxStrategy);
+ Controls.Add(buttonDown);
+ Controls.Add(buttonRight);
+ Controls.Add(buttonUp);
+ Controls.Add(buttonLeft);
+ Controls.Add(pictureBoxTanks);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormTank";
+ Text = "FormTank";
+ ((System.ComponentModel.ISupportInitialize)pictureBoxTanks).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxTanks;
+ private Button buttonLeft;
+ private Button buttonUp;
+ private Button buttonRight;
+ private Button buttonDown;
+ private ComboBox СomboBoxStrategy;
+ private Button buttonStrategyStep;
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/FormTank.cs b/ProjectTank №4/ProjectTank/FormTank.cs
new file mode 100644
index 0000000..9a4dfa7
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/FormTank.cs
@@ -0,0 +1,122 @@
+using ProjectTank.Drawnings;
+using ProjectTank.Entities;
+using ProjectTank.MovementStrategy;
+
+namespace ProjectTank
+{
+ ///
+ /// Форма работы с объектом "Танк"
+ ///
+ public partial class FormTank : Form
+ {
+ ///
+ /// Поле-объект для прорисовки объекта
+ ///
+ private DrawningTank2? _drawningTank;
+
+ ///
+ /// Стратегия перемещения
+ ///
+ private AbstractStrategy? _strategy;
+ public DrawningTank2 SetTank
+ {
+ set
+ {
+ _drawningTank = value;
+ _drawningTank.SetPictureSize(pictureBoxTanks.Width, pictureBoxTanks.Height);
+ СomboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+ ///
+ /// Конструктор формы
+ ///
+ public FormTank()
+ {
+ InitializeComponent();
+ _strategy = null;
+ }
+ ///
+ /// Метод прорисовки танка
+ ///
+ private void Draw()
+ {
+ if (_drawningTank == null)
+ {
+ return;
+ }
+ Bitmap bmp = new(pictureBoxTanks.Width, pictureBoxTanks.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningTank.DrawTransport(gr);
+ pictureBoxTanks.Image = bmp;
+ }
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_drawningTank == null)
+ {
+ return;
+ }
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ bool result = false;
+ switch (name)
+ {
+ case "buttonUp":
+ result = _drawningTank.MoveTransport(DirectionType.Up);
+ break;
+ case "buttonLeft":
+ result = _drawningTank.MoveTransport(DirectionType.Left);
+ break;
+ case "buttonRight":
+ result = _drawningTank.MoveTransport(DirectionType.Right);
+ break;
+ case "buttonDown":
+ result = _drawningTank.MoveTransport(DirectionType.Down);
+ break;
+ }
+ if (result)
+ {
+ Draw();
+ }
+ }
+ ///
+ /// Обработка нажатия кнопки "Шаг"
+ ///
+ ///
+ ///
+ private void ButtonStrategyStep_Ckick(object sender, EventArgs e)
+ {
+ if (_drawningTank == null)
+ {
+ return;
+ }
+ if (СomboBoxStrategy.Enabled)
+ {
+ _strategy = СomboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(new MoveableTank(_drawningTank),
+ pictureBoxTanks.Width, pictureBoxTanks.Height);
+ }
+ if (_strategy == null)
+ {
+ return;
+ }
+ СomboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ СomboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/FormTank.resx b/ProjectTank №4/ProjectTank/FormTank.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/FormTank.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/FormTankCollection.Designer.cs b/ProjectTank №4/ProjectTank/FormTankCollection.Designer.cs
new file mode 100644
index 0000000..5c77734
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/FormTankCollection.Designer.cs
@@ -0,0 +1,188 @@
+using static System.Net.Mime.MediaTypeNames;
+using System.Windows.Forms;
+using System.Xml.Linq;
+
+namespace ProjectTank
+{
+ partial class FormTankCollection
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ groupBoxTools = new GroupBox();
+ buttonRefresh = new Button();
+ buttonGoToCheck = new Button();
+ buttonRemoveTank = new Button();
+ maskedTextBox = new MaskedTextBox();
+ buttonAddTank1 = new Button();
+ buttonAddTank2 = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGoToCheck);
+ groupBoxTools.Controls.Add(buttonRemoveTank);
+ groupBoxTools.Controls.Add(maskedTextBox);
+ groupBoxTools.Controls.Add(buttonAddTank1);
+ groupBoxTools.Controls.Add(buttonAddTank2);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(700, 0);
+ groupBoxTools.Margin = new Padding(3, 4, 3, 4);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Padding = new Padding(3, 4, 3, 4);
+ groupBoxTools.Size = new Size(214, 600);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(7, 505);
+ buttonRefresh.Margin = new Padding(3, 4, 3, 4);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(200, 47);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonGoToCheck.Location = new Point(7, 403);
+ buttonGoToCheck.Margin = new Padding(3, 4, 3, 4);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(200, 47);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveTank
+ //
+ buttonRemoveTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveTank.Location = new Point(7, 321);
+ buttonRemoveTank.Margin = new Padding(3, 4, 3, 4);
+ buttonRemoveTank.Name = "buttonRemoveTank";
+ buttonRemoveTank.Size = new Size(200, 47);
+ buttonRemoveTank.TabIndex = 4;
+ buttonRemoveTank.Text = "Удаление танка";
+ buttonRemoveTank.UseVisualStyleBackColor = true;
+ buttonRemoveTank.Click += buttonRemoveTank_Click;
+ //
+ // maskedTextBox
+ //
+ maskedTextBox.Location = new Point(7, 283);
+ maskedTextBox.Margin = new Padding(3, 4, 3, 4);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(193, 27);
+ maskedTextBox.TabIndex = 3;
+ maskedTextBox.ValidatingType = typeof(int);
+ //
+ // buttonAddTank1
+ //
+ buttonAddTank1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTank1.Location = new Point(7, 177);
+ buttonAddTank1.Margin = new Padding(3, 4, 3, 4);
+ buttonAddTank1.Name = "buttonAddTank1";
+ buttonAddTank1.Size = new Size(200, 47);
+ buttonAddTank1.TabIndex = 2;
+ buttonAddTank1.Text = "Добавление Tank1";
+ buttonAddTank1.UseVisualStyleBackColor = true;
+ buttonAddTank1.Click += ButtonAddBattleTank_Click;
+ //
+ // buttonAddTank2
+ //
+ buttonAddTank2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTank2.Location = new Point(7, 123);
+ buttonAddTank2.Margin = new Padding(3, 4, 3, 4);
+ buttonAddTank2.Name = "buttonAddTank2";
+ buttonAddTank2.Size = new Size(200, 47);
+ buttonAddTank2.TabIndex = 1;
+ buttonAddTank2.Text = "Добавление Tank2";
+ buttonAddTank2.UseVisualStyleBackColor = true;
+ buttonAddTank2.Click += ButtonAddTank_Click;
+ //
+ // comboBoxSelectorCompany
+ //
+ comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectorCompany.FormattingEnabled = true;
+ comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
+ comboBoxSelectorCompany.Location = new Point(7, 33);
+ comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(199, 28);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // pictureBox
+ //
+ pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Location = new Point(0, 0);
+ pictureBox.Margin = new Padding(3, 4, 3, 4);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(700, 600);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormTankCollection
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(914, 600);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormTankCollection";
+ Text = "Коллекция танков";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddTank1;
+ private Button buttonAddTank2;
+ private MaskedTextBox maskedTextBox;
+ private PictureBox pictureBox;
+ private Button buttonRemoveTank;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/FormTankCollection.cs b/ProjectTank №4/ProjectTank/FormTankCollection.cs
new file mode 100644
index 0000000..04909f8
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/FormTankCollection.cs
@@ -0,0 +1,151 @@
+using ProjectTank.CollectionGenericObjects;
+using ProjectTank.Drawnings;
+using System.Windows.Forms;
+
+namespace ProjectTank
+{
+ ///
+ ///
+ ///
+ public partial class FormTankCollection : Form
+ {
+ ///
+ ///
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormTankCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new TankBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создоваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null) return;
+
+ Random random = new();
+ DrawningTank2 drawningTank;
+ switch (type)
+ {
+ case nameof(DrawningTank2):
+ drawningTank = new DrawningTank2(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random));
+ break;
+ case nameof(DrawningTank1):
+ bool randomTrack = Convert.ToBoolean(random.Next(0, 2));
+ drawningTank = new DrawningTank1(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), randomTrack, (randomTrack ? Convert.ToBoolean(random.Next(0, 2)) : true));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawningTank != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ ///
+ /// Получение цвета
+ ///
+ /// Генератор случайных чесел
+ ///
+ private static Color GetColor(Random random)
+ {
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new ColorDialog();
+
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
+ return color;
+ }
+
+ private void ButtonAddTank_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningTank2));
+ }
+
+ private void ButtonAddBattleTank_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningTank1));
+ }
+
+ private void buttonRemoveTank_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return;
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
+
+ int position = Convert.ToInt32(maskedTextBox.Text);
+
+ if (_company - position != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null) return;
+
+ DrawningTank2? tank = null;
+ int coutner = 100;
+
+ while (tank == null)
+ {
+ tank = _company.GetRandomObject();
+ coutner--;
+ if (coutner <= 0) break;
+ }
+
+ if (tank == null) return;
+
+ FormTank form = new()
+ {
+ SetTank = tank
+ };
+ form.ShowDialog();
+ }
+
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null) return;
+ pictureBox.Image = _company.Show();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/FormTankCollection.resx b/ProjectTank №4/ProjectTank/FormTankCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/FormTankCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/MovementStrategy/AbstractStrategy.cs b/ProjectTank №4/ProjectTank/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..b012cf0
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,118 @@
+namespace ProjectTank.MovementStrategy
+{
+ public abstract class AbstractStrategy
+ {
+ ///
+ /// Перемещаемый объект
+ ///
+ private IMoveableObject? _moveableObject;
+ ///
+ /// Статус перемещения
+ ///
+ private StrategyStatus _state = StrategyStatus.NotInit;
+ ///
+ /// Ширина поля
+ ///
+ protected int FieldWidth { get; private set; }
+ ///
+ /// Высота поля
+ ///
+ protected int FieldHeight { get; private set; }
+ ///
+ /// Статус перемещения
+ ///
+ public StrategyStatus GetStatus() { return _state; }
+ ///
+ /// Установка данных
+ ///
+ /// Перемещаемый объект
+ /// Ширина поля
+ /// Высота поля
+ public void SetData(IMoveableObject moveableObject, int width, int height)
+ {
+ if (moveableObject == null)
+ {
+ _state = StrategyStatus.NotInit;
+ return;
+ }
+ _state = StrategyStatus.InProgress;
+ _moveableObject = moveableObject;
+ FieldWidth = width;
+ FieldHeight = height;
+ }
+ ///
+ /// Шаг перемещения
+ ///
+ public void MakeStep()
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return;
+ }
+ if (IsTargetDestinaion())
+ {
+ _state = StrategyStatus.Finish;
+ return;
+ }
+ MoveToTarget();
+ }
+ ///
+ /// Перемещение влево
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveLeft() => MoveTo(MovementDirection.Left);
+ ///
+ /// Перемещение вправо
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveRight() => MoveTo(MovementDirection.Right);
+ ///
+ /// Перемещение вверх
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveUp() => MoveTo(MovementDirection.Up);
+ ///
+ /// Перемещение вниз
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveDown() => MoveTo(MovementDirection.Down);
+ ///
+ /// Параметры объекта
+ ///
+ protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
+ ///
+ /// Шаг объекта
+ ///
+ ///
+ protected int? GetStep()
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return null;
+ }
+ return _moveableObject?.GetStep;
+ }
+ ///
+ /// Перемещение к цели
+ ///
+ protected abstract void MoveToTarget();
+ ///
+ /// Достигнута ли цель
+ ///
+ ///
+ protected abstract bool IsTargetDestinaion();
+ ///
+ /// Попытка перемещения в требуемом направлении
+ ///
+ /// Направление
+ /// Результат попытки (true - удалось переместиться, false - неудача)
+ private bool MoveTo(MovementDirection movementDirection)
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return false;
+ }
+ return _moveableObject?.TryMoveObject(movementDirection) ?? false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/MovementStrategy/IMoveableObject.cs b/ProjectTank №4/ProjectTank/MovementStrategy/IMoveableObject.cs
new file mode 100644
index 0000000..1a1422f
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/MovementStrategy/IMoveableObject.cs
@@ -0,0 +1,23 @@
+namespace ProjectTank.MovementStrategy
+{
+ public interface IMoveableObject
+ {
+ ///
+ /// Получение координаты объекта
+ ///
+
+ ObjectParameters? GetObjectPosition { get; }
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ /// Направление
+ /// true - объект перемещен, false - перемещение невозможно
+ bool TryMoveObject(MovementDirection direction);
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/MovementStrategy/MoveToBorder.cs b/ProjectTank №4/ProjectTank/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..366e6a3
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,38 @@
+namespace ProjectTank.MovementStrategy;
+
+internal class MoveToBorder : AbstractStrategy
+{
+ ///
+ /// Стратегия перемещения объекта к Краю экрана
+ ///
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.RightBorder + GetStep() >= FieldWidth &&
+ objParams.DownBorder + GetStep() >= FieldHeight;
+ }
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+
+ int diffX = objParams.RightBorder - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ MoveRight();
+ }
+
+ int diffY = objParams.DownBorder - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ MoveDown();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/MovementStrategy/MoveToCenter.cs b/ProjectTank №4/ProjectTank/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..df46ff5
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,53 @@
+namespace ProjectTank.MovementStrategy
+{
+ ///
+ /// Стратегия перемещения объекта в центр экрана
+ ///
+ public class MoveToCenter : AbstractStrategy
+ {
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2
+ && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
+ objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
+ && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
+ }
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/MovementStrategy/MoveableTank.cs b/ProjectTank №4/ProjectTank/MovementStrategy/MoveableTank.cs
new file mode 100644
index 0000000..4f4b947
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/MovementStrategy/MoveableTank.cs
@@ -0,0 +1,59 @@
+using ProjectTank.Drawnings;
+
+namespace ProjectTank.MovementStrategy
+{
+ public class MoveableTank : IMoveableObject
+ {
+ ///
+ /// Поле-объект класса или его DrawningTank наследника
+ ///
+ private readonly DrawningTank2? _tank = null;
+ ///
+ /// Конструктор
+ ///
+ /// Объект класса DrawningBoat
+ public MoveableTank(DrawningTank2 tank)
+ {
+ _tank = tank;
+ }
+
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_tank == null || _tank.EntityTank2 == null ||
+ !_tank.GetPosX.HasValue || !_tank.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(_tank.GetPosX.Value,
+ _tank.GetPosY.Value, _tank.GetWidth, _tank.GetHeight);
+ }
+ }
+ public int GetStep => (int)(_tank?.EntityTank2?.Step ?? 0);
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (_tank == null || _tank.EntityTank2 == null)
+ {
+ return false;
+ }
+ return _tank.MoveTransport(GetDirectionType(direction));
+ }
+ ///
+ /// Конвертация из MovementDirection в DirectionType
+ ///
+ /// MovementDirection
+ /// DirectionType
+ private static DirectionType GetDirectionType(MovementDirection direction)
+ {
+ return direction switch
+ {
+ MovementDirection.Left => DirectionType.Left,
+ MovementDirection.Right => DirectionType.Right,
+ MovementDirection.Up => DirectionType.Up,
+ MovementDirection.Down => DirectionType.Down,
+ _ => DirectionType.Unknow,
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/MovementStrategy/MovementDirection.cs b/ProjectTank №4/ProjectTank/MovementStrategy/MovementDirection.cs
new file mode 100644
index 0000000..10ffa6b
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/MovementStrategy/MovementDirection.cs
@@ -0,0 +1,22 @@
+namespace ProjectTank.MovementStrategy
+{
+ public enum MovementDirection
+ {
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+ ///
+ /// Влево
+ ///
+ Left = 3,
+ ///
+ /// Вправо
+ ///
+ Right = 4,
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/MovementStrategy/ObjectParameters.cs b/ProjectTank №4/ProjectTank/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..656c9c2
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,60 @@
+namespace ProjectTank.MovementStrategy
+{
+ public class ObjectParameters
+ {
+ ///
+ /// Координата X
+ ///
+ private readonly int _x;
+ ///
+ /// Координата Y
+ ///
+ private readonly int _y;
+ ///
+ /// Ширина объекта
+ ///
+ private readonly int _width;
+ ///
+ /// Высота объекта
+ ///
+ private readonly int _height;
+ ///
+ /// Левая граница
+ ///
+ public int LeftBorder => _x;
+ ///
+ /// Верхняя граница
+ ///
+ public int TopBorder => _y;
+ ///
+ /// Правая граница
+ ///
+ public int RightBorder => _x + _width;
+ ///
+ /// Нижняя граница
+ ///
+ public int DownBorder => _y + _height;
+ ///
+ /// Середина объекта
+ ///
+ public int ObjectMiddleHorizontal => _x + _width / 2;
+ ///
+ /// Середина объекта
+ ///
+ public int ObjectMiddleVertical => _y + _height / 2;
+ ///
+ /// Конструктор
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина объекта
+ /// Высота объекта
+ public ObjectParameters(int x, int y, int width, int height)
+ {
+ _x = x;
+ _y = y;
+ _width = width;
+ _height = height;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/MovementStrategy/StrategyStatus.cs b/ProjectTank №4/ProjectTank/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..c10e61d
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,18 @@
+namespace ProjectTank.MovementStrategy
+{
+ public enum StrategyStatus
+ {
+ ///
+ /// Все готово к началу
+ ///
+ NotInit,
+ ///
+ /// Выполняется
+ ///
+ InProgress,
+ ///
+ /// Завершино
+ ///
+ Finish
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/Program.cs b/ProjectTank №4/ProjectTank/Program.cs
new file mode 100644
index 0000000..94ae4d7
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/Program.cs
@@ -0,0 +1,17 @@
+namespace ProjectTank
+{
+ internal static class Program
+ {
+ ///
+ /// The main entry point for the application.
+ ///
+ [STAThread]
+ static void Main()
+ {
+ // To customize application configuration such as set high DPI settings or default font,
+ // see https://aka.ms/applicationconfiguration.
+ ApplicationConfiguration.Initialize();
+ Application.Run(new FormTankCollection());
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/ProjectTank.csproj b/ProjectTank №4/ProjectTank/ProjectTank.csproj
new file mode 100644
index 0000000..244387d
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/ProjectTank.csproj
@@ -0,0 +1,26 @@
+
+
+
+ WinExe
+ net7.0-windows
+ enable
+ true
+ enable
+
+
+
+
+ True
+ True
+ Resources.resx
+
+
+
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+
+
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/Properties/Resources.Designer.cs b/ProjectTank №4/ProjectTank/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..e20507b
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/Properties/Resources.Designer.cs
@@ -0,0 +1,103 @@
+//------------------------------------------------------------------------------
+//
+// Этот код создан программой.
+// Исполняемая версия:4.0.30319.42000
+//
+// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
+// повторной генерации кода.
+//
+//------------------------------------------------------------------------------
+
+namespace ProjectTank.Properties {
+ using System;
+
+
+ ///
+ /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
+ ///
+ // Этот класс создан автоматически классом StronglyTypedResourceBuilder
+ // с помощью такого средства, как ResGen или Visual Studio.
+ // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
+ // с параметром /str или перестройте свой проект VS.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectTank.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Перезаписывает свойство CurrentUICulture текущего потока для всех
+ /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowDown {
+ get {
+ object obj = ResourceManager.GetObject("arrowDown", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowLeft {
+ get {
+ object obj = ResourceManager.GetObject("arrowLeft", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowRight {
+ get {
+ object obj = ResourceManager.GetObject("arrowRight", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowUp {
+ get {
+ object obj = ResourceManager.GetObject("arrowUp", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+ }
+}
diff --git a/ProjectTank №4/ProjectTank/Properties/Resources.resx b/ProjectTank №4/ProjectTank/Properties/Resources.resx
new file mode 100644
index 0000000..fd4bdf3
--- /dev/null
+++ b/ProjectTank №4/ProjectTank/Properties/Resources.resx
@@ -0,0 +1,133 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+
+ ..\Resources\arrowRight.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\arrowDown.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\arrowLeft.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\arrowUp.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
\ No newline at end of file
diff --git a/ProjectTank №4/ProjectTank/Resources/arrowDown.jpg b/ProjectTank №4/ProjectTank/Resources/arrowDown.jpg
new file mode 100644
index 0000000..f21002e
Binary files /dev/null and b/ProjectTank №4/ProjectTank/Resources/arrowDown.jpg differ
diff --git a/ProjectTank №4/ProjectTank/Resources/arrowLeft.jpg b/ProjectTank №4/ProjectTank/Resources/arrowLeft.jpg
new file mode 100644
index 0000000..61b8dae
Binary files /dev/null and b/ProjectTank №4/ProjectTank/Resources/arrowLeft.jpg differ
diff --git a/ProjectTank №4/ProjectTank/Resources/arrowRight.jpg b/ProjectTank №4/ProjectTank/Resources/arrowRight.jpg
new file mode 100644
index 0000000..b440197
Binary files /dev/null and b/ProjectTank №4/ProjectTank/Resources/arrowRight.jpg differ
diff --git a/ProjectTank №4/ProjectTank/Resources/arrowUp.jpg b/ProjectTank №4/ProjectTank/Resources/arrowUp.jpg
new file mode 100644
index 0000000..e630cea
Binary files /dev/null and b/ProjectTank №4/ProjectTank/Resources/arrowUp.jpg differ