diff --git a/Tank/Tank.sln b/Tank/Tank.sln
index a226ebb..736023a 100644
--- a/Tank/Tank.sln
+++ b/Tank/Tank.sln
@@ -1,9 +1,9 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
-VisualStudioVersion = 17.6.33801.468
+VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tank", "Tank\Tank.csproj", "{19BA0FA1-372B-490A-AA7F-757B0B8F322B}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tank", "Tank\Tank.csproj", "{5C602C58-ECEC-4FAB-BA10-FB671582D227}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -11,15 +11,15 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {19BA0FA1-372B-490A-AA7F-757B0B8F322B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {19BA0FA1-372B-490A-AA7F-757B0B8F322B}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {19BA0FA1-372B-490A-AA7F-757B0B8F322B}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {19BA0FA1-372B-490A-AA7F-757B0B8F322B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5C602C58-ECEC-4FAB-BA10-FB671582D227}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5C602C58-ECEC-4FAB-BA10-FB671582D227}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5C602C58-ECEC-4FAB-BA10-FB671582D227}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5C602C58-ECEC-4FAB-BA10-FB671582D227}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {5332F2FC-D1C2-4B42-B32E-53ECC094BBB7}
+ SolutionGuid = {73BF3262-E499-401F-BDBD-BD2BC7D3C324}
EndGlobalSection
EndGlobal
diff --git a/Tank/Tank/DrawArmoVehicle.cs b/Tank/Tank/DrawArmoVehicle.cs
index aa389df..2446515 100644
--- a/Tank/Tank/DrawArmoVehicle.cs
+++ b/Tank/Tank/DrawArmoVehicle.cs
@@ -5,12 +5,13 @@ using System.Security.Cryptography.Pkcs;
using System.Text;
using System.Threading.Tasks;
using Tank.Entities;
+using Tank.MovementStrategy;
namespace Tank
{
public class DrawArmoVehicle
{
- public EntityBase? Tank { get; protected set; }
+ public EntityArmoVehicle? Tank { get; protected set; }
protected int _pictureWidth;
protected int _pictureHeight;
protected int _startPosX;
@@ -29,7 +30,7 @@ namespace Tank
_pictureWidth = width;
if (_pictureHeight < _Height || _pictureWidth < _Width)
return;
- Tank = new EntityBase(speed, weight, bodyColor);
+ Tank = new EntityArmoVehicle(speed, weight, bodyColor);
}
protected DrawArmoVehicle(int speed, double weight, Color bodyColor, int width, int height, int tankWidth, int tankHeight)
@@ -40,7 +41,7 @@ namespace Tank
_Width = tankWidth;
if (_pictureHeight < _Height || _pictureWidth < _Width)
return;
- Tank = new EntityBase(speed, weight, bodyColor);
+ Tank = new EntityArmoVehicle(speed, weight, bodyColor);
}
public bool CanMove(Direction direction)
@@ -124,5 +125,7 @@ namespace Tank
g.FillEllipse(ColorBlack, 85 + _startPosX, 42 + _startPosY, 20, 20);
g.FillEllipse(ColorBlack, 110 + _startPosX, 42 + _startPosY, 20, 20);
}
+
+ public IMoveableObject GetMoveableObject => new DrawingObjectTank(this);
}
-}
+}
\ No newline at end of file
diff --git a/Tank/Tank/DrawTank.cs b/Tank/Tank/DrawTank.cs
index f473bf4..e270a72 100644
--- a/Tank/Tank/DrawTank.cs
+++ b/Tank/Tank/DrawTank.cs
@@ -14,13 +14,13 @@ namespace Tank.DrawningObjects
{
if (Tank != null)
{
- Tank = new EntityAddBase(speed, weight, bodyColor, additionalColor, bodyKit, caterpillar, tower);
+ Tank = new EntityTank(speed, weight, bodyColor, additionalColor, bodyKit, caterpillar, tower);
}
}
public override void DrawTransport(Graphics g)
{
- if (Tank is not EntityAddBase ArmoVehicle)
+ if (Tank is not EntityTank ArmoVehicle)
return;
base.DrawTransport(g);
if (ArmoVehicle.BodyKit)
@@ -49,7 +49,7 @@ namespace Tank.DrawningObjects
{
// Орудие
Brush bodyBrush = new SolidBrush(ArmoVehicle.AdditionalColor);
- g.FillRectangle(bodyBrush, _startPosX + 111, _startPosY + 17, 70, 5);
+ g.FillRectangle(bodyBrush, _startPosX + 111, _startPosY + 17, 60, 5);
// Зенитное орудие
Point[] pointgun = { new Point(_startPosX + 44, _startPosY + 13), new Point(_startPosX + 45, _startPosY + 12), new Point(_startPosX + 41, _startPosY + 8), new Point(_startPosX + 41, _startPosY + 7),
diff --git a/Tank/Tank/EntityBase.cs b/Tank/Tank/EntityArmoVehicle.cs
similarity index 81%
rename from Tank/Tank/EntityBase.cs
rename to Tank/Tank/EntityArmoVehicle.cs
index 2c23395..8263ed4 100644
--- a/Tank/Tank/EntityBase.cs
+++ b/Tank/Tank/EntityArmoVehicle.cs
@@ -6,13 +6,13 @@ using System.Threading.Tasks;
namespace Tank.Entities
{
- public class EntityBase
+ public class EntityArmoVehicle
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight;
- public EntityBase(int speed, double weight, Color bodyColor)
+ public EntityArmoVehicle(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
diff --git a/Tank/Tank/EntityAddBase.cs b/Tank/Tank/EntityTank.cs
similarity index 71%
rename from Tank/Tank/EntityAddBase.cs
rename to Tank/Tank/EntityTank.cs
index 1527343..04d5f7f 100644
--- a/Tank/Tank/EntityAddBase.cs
+++ b/Tank/Tank/EntityTank.cs
@@ -6,13 +6,13 @@ using System.Threading.Tasks;
namespace Tank.Entities
{
- public class EntityAddBase : EntityBase
+ public class EntityTank : EntityArmoVehicle
{
public Color AdditionalColor { get; private set; }
public bool BodyKit { get; private set; }
public bool Caterpillar { get; private set; }
public bool Tower { get; private set; }
- public EntityAddBase(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool caterpillar, bool tower) : base(speed, weight, bodyColor)
+ public EntityTank(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool caterpillar, bool tower) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
BodyKit = bodyKit;
diff --git a/Tank/Tank/FormTank.Designer.cs b/Tank/Tank/FormTank.Designer.cs
index 70578cb..4a148c0 100644
--- a/Tank/Tank/FormTank.Designer.cs
+++ b/Tank/Tank/FormTank.Designer.cs
@@ -37,6 +37,7 @@
buttonArmVechicle = new Button();
buttonStep = new Button();
comboBoxStrategy = new ComboBox();
+ ChooseCar = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
SuspendLayout();
//
@@ -45,7 +46,7 @@
pictureBoxTank.Location = new Point(1, 0);
pictureBoxTank.Margin = new Padding(3, 4, 3, 4);
pictureBoxTank.Name = "pictureBoxTank";
- pictureBoxTank.Size = new Size(913, 599);
+ pictureBoxTank.Size = new Size(913, 571);
pictureBoxTank.TabIndex = 0;
pictureBoxTank.TabStop = false;
//
@@ -117,7 +118,7 @@
buttonArmVechicle.Location = new Point(176, 501);
buttonArmVechicle.Margin = new Padding(3, 4, 3, 4);
buttonArmVechicle.Name = "buttonArmVechicle";
- buttonArmVechicle.Size = new Size(145, 53);
+ buttonArmVechicle.Size = new Size(150, 53);
buttonArmVechicle.TabIndex = 15;
buttonArmVechicle.Text = "Создание бронеавтомобиля";
buttonArmVechicle.UseVisualStyleBackColor = true;
@@ -143,12 +144,23 @@
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 19;
//
+ // ChooseCar
+ //
+ ChooseCar.Location = new Point(807, 120);
+ ChooseCar.Name = "ChooseCar";
+ ChooseCar.Size = new Size(94, 52);
+ ChooseCar.TabIndex = 20;
+ ChooseCar.Text = "Выбрать технику";
+ ChooseCar.UseVisualStyleBackColor = true;
+ ChooseCar.Click += ButtonSelectTank_Click;
+ //
// FormTank
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = SystemColors.ButtonHighlight;
ClientSize = new Size(914, 568);
+ Controls.Add(ChooseCar);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonStep);
Controls.Add(buttonArmVechicle);
@@ -176,5 +188,6 @@
private Button buttonArmVechicle;
private Button buttonStep;
private ComboBox comboBoxStrategy;
+ private Button ChooseCar;
}
}
\ No newline at end of file
diff --git a/Tank/Tank/FormTank.cs b/Tank/Tank/FormTank.cs
index d43d757..aae6222 100644
--- a/Tank/Tank/FormTank.cs
+++ b/Tank/Tank/FormTank.cs
@@ -7,10 +7,13 @@ namespace Tank
{
private DrawArmoVehicle? _Tank;
private AbstractStrategy? _abstractStrategy;
+ public DrawArmoVehicle? SelectedTank { get; private set; }
public FormTank()
{
InitializeComponent();
+ _abstractStrategy = null;
+ SelectedTank = null;
}
private void Draw()
@@ -18,19 +21,30 @@ namespace Tank
if (_Tank == null)
return;
- Bitmap bmp = new(pictureBoxTank.Width, pictureBoxTank.Height);
- Graphics gr = Graphics.FromImage(bmp);
+ Bitmap bitmap = new(pictureBoxTank.Width, pictureBoxTank.Height);
+ Graphics gr = Graphics.FromImage(bitmap);
_Tank?.DrawTransport(gr);
- pictureBoxTank.Image = bmp;
+ pictureBoxTank.Image = bitmap;
}
private void ButtonCreateTank_Click(object sender, EventArgs e)
{
Random rnd = new();
+ Color mainColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ mainColor = dialog.Color;
+ }
+ Color addColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ addColor = dialog.Color;
+ }
+
_Tank = new DrawTank(rnd.Next(100, 200), rnd.Next(2000, 4000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ mainColor, addColor,
Convert.ToBoolean(rnd.Next(1, 2)), Convert.ToBoolean(rnd.Next(1, 2)), Convert.ToBoolean(rnd.Next(1, 2)),
pictureBoxTank.Width, pictureBoxTank.Height);
_Tank.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
@@ -66,9 +80,15 @@ namespace Tank
private void CreateButtonArmoVehicle_Click(object sender, EventArgs e)
{
Random rnd = new();
+ Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
_Tank = new DrawArmoVehicle(rnd.Next(100, 200), rnd.Next(2000, 4000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- pictureBoxTank.Width, pictureBoxTank.Height);
+ color, pictureBoxTank.Width, pictureBoxTank.Height);
_Tank.SetPosition(rnd.Next(10, 50), rnd.Next(30, 70));
Draw();
@@ -102,5 +122,11 @@ namespace Tank
_abstractStrategy = null;
}
}
+
+ private void ButtonSelectTank_Click(object sender, EventArgs e)
+ {
+ SelectedTank = _Tank;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/Tank/Tank/FormTank.resx b/Tank/Tank/FormTank.resx
index a395bff..af32865 100644
--- a/Tank/Tank/FormTank.resx
+++ b/Tank/Tank/FormTank.resx
@@ -18,7 +18,7 @@
System.Resources.ResXResourceReader, System.Windows.Forms, ...
System.Resources.ResXResourceWriter, System.Windows.Forms, ...
this is my long stringthis is a comment
- Blue
+ Blue
[base64 mime encoded serialized .NET Framework object]
diff --git a/Tank/Tank/FormTanksCollections.Designer.cs b/Tank/Tank/FormTanksCollections.Designer.cs
new file mode 100644
index 0000000..d93389d
--- /dev/null
+++ b/Tank/Tank/FormTanksCollections.Designer.cs
@@ -0,0 +1,135 @@
+namespace Tank
+{
+ partial class FormTanksCollections
+ {
+ ///
+ /// 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()
+ {
+ panel1 = new Panel();
+ UpdateButton = new Button();
+ DeleteButton = new Button();
+ AddButton = new Button();
+ InputNum = new TextBox();
+ label1 = new Label();
+ DrawTank = new PictureBox();
+ panel1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)DrawTank).BeginInit();
+ SuspendLayout();
+ //
+ // panel1
+ //
+ panel1.Controls.Add(UpdateButton);
+ panel1.Controls.Add(DeleteButton);
+ panel1.Controls.Add(AddButton);
+ panel1.Controls.Add(InputNum);
+ panel1.Controls.Add(label1);
+ panel1.Dock = DockStyle.Right;
+ panel1.Location = new Point(550, 0);
+ panel1.Name = "panel1";
+ panel1.Size = new Size(250, 451);
+ panel1.TabIndex = 0;
+ //
+ // UpdateButton
+ //
+ UpdateButton.Location = new Point(10, 241);
+ UpdateButton.Name = "UpdateButton";
+ UpdateButton.Size = new Size(229, 37);
+ UpdateButton.TabIndex = 4;
+ UpdateButton.Text = "Обновить коллекцию";
+ UpdateButton.UseVisualStyleBackColor = true;
+ UpdateButton.Click += ButtonRefreshCollection_Click;
+ //
+ // DeleteButton
+ //
+ DeleteButton.Location = new Point(10, 176);
+ DeleteButton.Name = "DeleteButton";
+ DeleteButton.Size = new Size(229, 37);
+ DeleteButton.TabIndex = 3;
+ DeleteButton.Text = "Удалить технику";
+ DeleteButton.UseVisualStyleBackColor = true;
+ DeleteButton.Click += ButtonRemoveTank_Click;
+ //
+ // AddButton
+ //
+ AddButton.Location = new Point(10, 53);
+ AddButton.Name = "AddButton";
+ AddButton.Size = new Size(229, 37);
+ AddButton.TabIndex = 2;
+ AddButton.Text = "Добавить технику";
+ AddButton.UseVisualStyleBackColor = true;
+ AddButton.Click += ButtonAddTank_Click;
+ //
+ // InputNum
+ //
+ InputNum.Location = new Point(10, 133);
+ InputNum.Name = "InputNum";
+ InputNum.Size = new Size(228, 27);
+ InputNum.TabIndex = 1;
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(2, 3);
+ label1.Name = "label1";
+ label1.Size = new Size(103, 20);
+ label1.TabIndex = 0;
+ label1.Text = "Инструменты";
+ //
+ // DrawTank
+ //
+ DrawTank.Dock = DockStyle.Fill;
+ DrawTank.Location = new Point(0, 0);
+ DrawTank.Name = "DrawTank";
+ DrawTank.Size = new Size(550, 451);
+ DrawTank.TabIndex = 1;
+ DrawTank.TabStop = false;
+ //
+ // CollectionsFrame
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 451);
+ Controls.Add(DrawTank);
+ Controls.Add(panel1);
+ Name = "CollectionsFrame";
+ Text = "CollectionsFrame";
+ panel1.ResumeLayout(false);
+ panel1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)DrawTank).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Panel panel1;
+ private Button UpdateButton;
+ private Button DeleteButton;
+ private Button AddButton;
+ private TextBox InputNum;
+ private Label label1;
+ private PictureBox DrawTank;
+ }
+}
\ No newline at end of file
diff --git a/Tank/Tank/FormTanksCollections.cs b/Tank/Tank/FormTanksCollections.cs
new file mode 100644
index 0000000..4aef8b2
--- /dev/null
+++ b/Tank/Tank/FormTanksCollections.cs
@@ -0,0 +1,71 @@
+using Tank.DrawningObjects;
+using Tank.Generics;
+using Tank.MovementStrategy;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Tank
+{
+ public partial class FormTanksCollections : Form
+ {
+ private readonly TanksGenericCollection _tanks;
+
+ public FormTanksCollections()
+ {
+ InitializeComponent();
+ _tanks = new TanksGenericCollection(DrawTank.Width, DrawTank.Height);
+ }
+
+ private void ButtonAddTank_Click(object sender, EventArgs e)
+ {
+ FormTank form = new FormTank();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_tanks + form.SelectedTank != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ DrawTank.Image = _tanks.ShowTanks();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ private void ButtonRemoveTank_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = -1;
+ try
+ {
+ pos = Convert.ToInt32(InputNum.Text);
+ }
+ catch (Exception ex) { }
+ if (_tanks - pos)
+ {
+ MessageBox.Show("Объект удален");
+ DrawTank.Image = _tanks.ShowTanks();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ private void ButtonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ DrawTank.Image = _tanks.ShowTanks();
+ }
+ }
+}
diff --git a/Tank/Tank/FormTanksCollections.resx b/Tank/Tank/FormTanksCollections.resx
new file mode 100644
index 0000000..a395bff
--- /dev/null
+++ b/Tank/Tank/FormTanksCollections.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/Tank/Tank/MoveToBorder.cs b/Tank/Tank/MoveToBorder.cs
index 4d98eb6..1e8627f 100644
--- a/Tank/Tank/MoveToBorder.cs
+++ b/Tank/Tank/MoveToBorder.cs
@@ -44,4 +44,4 @@ namespace Tank.MovementStrategy
}
}
}
-}
+}
\ No newline at end of file
diff --git a/Tank/Tank/Program.cs b/Tank/Tank/Program.cs
index 3fbc0e1..afa7dde 100644
--- a/Tank/Tank/Program.cs
+++ b/Tank/Tank/Program.cs
@@ -11,7 +11,7 @@ namespace Tank
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormTank());
+ Application.Run(new FormTanksCollections());
}
}
}
\ No newline at end of file
diff --git a/Tank/Tank/SetGeneric.cs b/Tank/Tank/SetGeneric.cs
new file mode 100644
index 0000000..cf12286
--- /dev/null
+++ b/Tank/Tank/SetGeneric.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tank
+{
+ internal class SetGeneric where T : class
+ {
+ // Массив объектов, которые храним
+ private readonly T?[] _places;
+
+ // Количество объектов в массиве
+ public int Count => _places.Length;
+
+ // Конструктор
+ public SetGeneric(int count)
+ {
+ _places = new T?[count];
+ }
+
+ //Добавление объекта в набор
+ public int Insert(T tank)
+ {
+ int index = -1;
+ for(int i = 0; i < _places.Length; i++)
+ {
+ if (_places[i] == null)
+ {
+ index = i; break;
+ }
+ }
+ if (index < 0)
+ {
+ return -1;
+ }
+ for(int i = index; i > 0; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[0] = tank;
+ return 0;
+ }
+
+ // Добавление объекта в набор на конкретную позицию
+ public bool Insert(T tank, int position)
+ {
+ if (position < 0 || position >= Count)
+ return false;
+ if (_places[position] == null)
+ {
+ _places[position] = tank;
+ return true;
+ }
+ int index = -1;
+ for(int i = position; i < Count; i++)
+ {
+ if (_places[i] == null)
+ {
+ index = i; break;
+ }
+ }
+ if (index < 0)
+ return false;
+ for(int i = index; index > position; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[position] = tank;
+ return true;
+ }
+
+ // Удаление объекта из набора с конкретной позиции
+ public bool Remove(int position)
+ {
+ if (position < 0 || position >= Count)
+ return false;
+ _places[position] = null;
+ return true;
+ }
+
+ // Получение объекта из набора по позиции
+ public T? Get(int position)
+ {
+ if (position < 0 || position >= Count)
+ return null;
+ return _places[position];
+ }
+ }
+}
\ No newline at end of file
diff --git a/Tank/Tank/TanksGenericCollection.cs b/Tank/Tank/TanksGenericCollection.cs
new file mode 100644
index 0000000..1eddea4
--- /dev/null
+++ b/Tank/Tank/TanksGenericCollection.cs
@@ -0,0 +1,108 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms.VisualStyles;
+using Tank.DrawningObjects;
+using Tank.MovementStrategy;
+
+namespace Tank.Generics
+{
+ internal class TanksGenericCollection
+ where T : DrawArmoVehicle
+ where U : IMoveableObject
+ {
+ // Ширина и высота окна прорисовки
+ private readonly int _pictureWidth;
+ private readonly int _pictureHeight;
+
+ // Размеры занимаемого объектом места
+ private readonly int _placeSizeWidth = 180;
+ private readonly int _placeSizeHeight = 90;
+
+ // Набор объектов
+ private readonly SetGeneric _collection;
+
+ // Конструктор
+ public TanksGenericCollection(int pictureWidth, int pictureHeight)
+ {
+ int width = pictureWidth / _placeSizeWidth;
+ int height = pictureHeight / _placeSizeHeight;
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ _collection = new SetGeneric(width * height);
+ }
+
+ // Перегрузка оператора сложения
+ public static int? operator +(TanksGenericCollection collect, T? obj)
+ {
+ if (obj == null)
+ {
+ return -1;
+ }
+ return collect?._collection.Insert(obj);
+ }
+
+ // Перегрузка оператора вычитания
+ public static bool operator -(TanksGenericCollection collect, int pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if (obj == null)
+ {
+ return false;
+ }
+ return collect._collection.Remove(pos);
+ }
+
+ // Получение объекта IMoveableObject
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+
+ // Вывод всего набора объектов
+ public Bitmap ShowTanks()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+
+ // Метод отрисовки фона
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
+ {
+ //Линия разметки места
+ g.DrawLine(pen, i * _placeSizeWidth, j *
+ _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
+ _placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i *
+ _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+
+ // Метод прорисовки объектов
+ private void DrawObjects(Graphics g)
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ DrawArmoVehicle? tank = _collection.Get(i);
+ if (tank == null)
+ continue;
+ tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
+ tank.DrawTransport(g);
+ }
+ }
+ }
+}
+