diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..68b1260
--- /dev/null
+++ b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,115 @@
+using ProjectTank.Drawnings;
+
+namespace ProjectTank.CollectionGenericObjects
+{
+ ///
+ /// Абстракция компании, хранящий коллекцию автомобилей
+ ///
+ public abstract class AbstractCompany
+ {
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 180;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 70;
+
+ ///
+ /// Ширина окна
+ ///
+ 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, DrawningTank сruiser)
+ {
+ return company._collection.Insert(сruiser);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningTank operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningTank? 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)
+ {
+ DrawningTank? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+ }
+}
diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..8ff883f
--- /dev/null
+++ b/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,45 @@
+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);
+ }
+
+}
diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..0da45f0
--- /dev/null
+++ b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,97 @@
+using ProjectTank.Drawnings;
+
+namespace 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)
+ {
+ // TODO проверка позиции
+ if (position >= _collection.Length || position < 0)
+ {
+ return null;
+ }
+ return _collection[position];
+ }
+ public int Insert(T obj)
+ {
+ // TODO вставка в свободное место набора
+ int index = 0;
+ while (index < _collection.Length)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[index] = obj;
+ return index;
+ }
+ index++;
+ }
+ return -1;
+ }
+ public int Insert(T obj, int position)
+ {
+ // TODO проверка позиции
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ // ищется свободное место после этой позиции и идет вставка туда
+ // если нет после, ищем до
+ // TODO вставка
+ if (position >= _collection.Length || position < 0)
+ { return -1; }
+
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+ int index;
+
+ for (index = position + 1; index < _collection.Length; ++index)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+ }
+
+ for (index = position - 1; index >= 0; --index)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+ }
+ return -1;
+ }
+ public T Remove(int position)
+ {
+ // TODO проверка позиции
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ if (position >= _collection.Length || position < 0)
+ { return null; }
+ T drawningTank = _collection[position];
+ _collection[position] = null;
+ return drawningTank;
+ }
+ }
+}
diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/TankDockingService.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/TankDockingService.cs
new file mode 100644
index 0000000..02580c5
--- /dev/null
+++ b/ProjectTank/ProjectTank/CollectionGenericObjects/TankDockingService.cs
@@ -0,0 +1,65 @@
+using ProjectTank.Drawnings;
+
+namespace ProjectTank.CollectionGenericObjects
+{
+ ///
+ /// Реализация абстрактной компании - каршеринг
+ ///
+ public class TankDockingService : AbstractCompany
+ {
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public TankDockingService(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; i++)
+ {
+ for (int j = 0; j < height + 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight + _placeSizeHeight);
+ }
+ }
+ }
+ protected override void SetObjectsPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ int curWidth = 0;
+ int curHeight = 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 * curWidth + 10, curHeight * _placeSizeHeight + 10);
+ }
+
+ if (curWidth < width - 1)
+ curWidth++;
+ else
+ {
+ curWidth = 0;
+ curHeight ++;
+ }
+
+ if (curHeight >= height)
+ {
+ return;
+ }
+ }
+ }
+ }
+}
diff --git a/ProjectTank/ProjectTank/FormTank.Designer.cs b/ProjectTank/ProjectTank/FormTank.Designer.cs
index eca5964..96b8fbd 100644
--- a/ProjectTank/ProjectTank/FormTank.Designer.cs
+++ b/ProjectTank/ProjectTank/FormTank.Designer.cs
@@ -30,13 +30,11 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormTank));
pictureBoxTank = new PictureBox();
- button1 = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonLeft = new Button();
comboBoxStrategy = new ComboBox();
- buttonCretaeTank = new Button();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
SuspendLayout();
@@ -45,34 +43,20 @@
//
pictureBoxTank.Dock = DockStyle.Fill;
pictureBoxTank.Location = new Point(0, 0);
- pictureBoxTank.Margin = new Padding(3, 2, 3, 2);
pictureBoxTank.Name = "pictureBoxTank";
- pictureBoxTank.Size = new Size(700, 338);
+ pictureBoxTank.Size = new Size(800, 450);
pictureBoxTank.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxTank.TabIndex = 0;
pictureBoxTank.TabStop = false;
//
- // button1
- //
- button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- button1.Location = new Point(10, 307);
- button1.Margin = new Padding(3, 2, 3, 2);
- button1.Name = "button1";
- button1.Size = new Size(186, 22);
- button1.TabIndex = 1;
- button1.Text = "создать военный танк";
- button1.UseVisualStyleBackColor = true;
- button1.Click += ButtonCreateTank_Click;
- //
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
- buttonUp.Location = new Point(632, 280);
- buttonUp.Margin = new Padding(3, 2, 3, 2);
+ buttonUp.Location = new Point(722, 373);
buttonUp.Name = "buttonUp";
- buttonUp.Size = new Size(26, 22);
+ buttonUp.Size = new Size(30, 30);
buttonUp.TabIndex = 2;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
@@ -82,10 +66,9 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
- buttonDown.Location = new Point(632, 307);
- buttonDown.Margin = new Padding(3, 2, 3, 2);
+ buttonDown.Location = new Point(722, 409);
buttonDown.Name = "buttonDown";
- buttonDown.Size = new Size(26, 22);
+ buttonDown.Size = new Size(30, 30);
buttonDown.TabIndex = 3;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
@@ -95,10 +78,9 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
- buttonRight.Location = new Point(663, 307);
- buttonRight.Margin = new Padding(3, 2, 3, 2);
+ buttonRight.Location = new Point(758, 409);
buttonRight.Name = "buttonRight";
- buttonRight.Size = new Size(26, 22);
+ buttonRight.Size = new Size(30, 30);
buttonRight.TabIndex = 4;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
@@ -108,10 +90,9 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
- buttonLeft.Location = new Point(600, 307);
- buttonLeft.Margin = new Padding(3, 2, 3, 2);
+ buttonLeft.Location = new Point(686, 409);
buttonLeft.Name = "buttonLeft";
- buttonLeft.Size = new Size(26, 22);
+ buttonLeft.Size = new Size(30, 30);
buttonLeft.TabIndex = 5;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
@@ -122,30 +103,16 @@
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к краю" });
- comboBoxStrategy.Location = new Point(557, 9);
- comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
+ comboBoxStrategy.Location = new Point(637, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
- comboBoxStrategy.Size = new Size(133, 23);
+ comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 6;
//
- // buttonCretaeTank
- //
- buttonCretaeTank.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCretaeTank.Location = new Point(210, 308);
- buttonCretaeTank.Margin = new Padding(3, 2, 3, 2);
- buttonCretaeTank.Name = "buttonCretaeTank";
- buttonCretaeTank.Size = new Size(186, 22);
- buttonCretaeTank.TabIndex = 7;
- buttonCretaeTank.Text = "создать танк";
- buttonCretaeTank.UseVisualStyleBackColor = true;
- buttonCretaeTank.Click += buttonCretaeTank_Click;
- //
// buttonStrategyStep
//
- buttonStrategyStep.Location = new Point(607, 34);
- buttonStrategyStep.Margin = new Padding(3, 2, 3, 2);
+ buttonStrategyStep.Location = new Point(694, 46);
buttonStrategyStep.Name = "buttonStrategyStep";
- buttonStrategyStep.Size = new Size(82, 22);
+ buttonStrategyStep.Size = new Size(94, 29);
buttonStrategyStep.TabIndex = 8;
buttonStrategyStep.Text = "шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
@@ -153,19 +120,16 @@
//
// FormTank
//
- AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(700, 338);
+ ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
- Controls.Add(buttonCretaeTank);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonLeft);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
- Controls.Add(button1);
Controls.Add(pictureBoxTank);
- Margin = new Padding(3, 2, 3, 2);
Name = "FormTank";
Text = "FormTank";
Click += ButtonMove_Click;
@@ -177,13 +141,11 @@
#endregion
private PictureBox pictureBoxTank;
- private Button button1;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private ComboBox comboBoxStrategy;
- private Button buttonCretaeTank;
private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/ProjectTank/ProjectTank/FormTank.cs b/ProjectTank/ProjectTank/FormTank.cs
index f960ab9..a88325b 100644
--- a/ProjectTank/ProjectTank/FormTank.cs
+++ b/ProjectTank/ProjectTank/FormTank.cs
@@ -15,6 +15,25 @@ namespace ProjectTank
///
private AbstractStrategy? _strategy;
+ ///
+ /// Получение объекта
+ ///
+ public DrawningTank SetTank
+ {
+ set
+ {
+ _drawningTank = value;
+ _drawningTank.SetPictureSize(pictureBoxTank.Width,
+ pictureBoxTank.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
+ ///
+ /// Конструктор формы
+ ///
public FormTank()
{
InitializeComponent();
@@ -37,57 +56,6 @@ namespace ProjectTank
pictureBoxTank.Image = bmp;
}
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningTank):
- _drawningTank = new DrawningTank(random.Next(100, 300),
- random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256),
- random.Next(0, 256), random.Next(0, 256)));
- break;
- case nameof(DrawningMilitaryTank):
- _drawningTank = new DrawningMilitaryTank(random.Next(100,
- 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256),
- random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256),
- random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
- break;
- default:
- return;
- }
- _drawningTank.SetPictureSize(pictureBoxTank.Width,
- pictureBoxTank.Height);
- _drawningTank.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
- ///
- /// Обработка нажатия кнопки "Создать военный танк"
- ///
- ///
- ///
- private void ButtonCreateTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryTank));
-
- ///
- /// Обработка нажатия кнопки "Создать танк"
- ///
- ///
- ///
- private void buttonCretaeTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTank));
-
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
@@ -104,16 +72,13 @@ namespace ProjectTank
switch (name)
{
case "buttonUp":
- result =
- _drawningTank.MoveTransport(DirectionType.Up);
+ result = _drawningTank.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- result =
- _drawningTank.MoveTransport(DirectionType.Down);
+ result = _drawningTank.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- result =
- _drawningTank.MoveTransport(DirectionType.Left);
+ result = _drawningTank.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result =
diff --git a/ProjectTank/ProjectTank/FormTanksCollection.Designer.cs b/ProjectTank/ProjectTank/FormTanksCollection.Designer.cs
new file mode 100644
index 0000000..8d4f6a7
--- /dev/null
+++ b/ProjectTank/ProjectTank/FormTanksCollection.Designer.cs
@@ -0,0 +1,184 @@
+namespace ProjectTank
+{
+ partial class FormTanksCollection
+ {
+ ///
+ /// 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();
+ maskedTextBoxPosision = new MaskedTextBox();
+ buttonRefresh = new Button();
+ buttonGetToTest = new Button();
+ ButtonRemoveTank = new Button();
+ ButtonAddMilitaryTank = new Button();
+ ButtonAddTank = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBoxTank = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(maskedTextBoxPosision);
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGetToTest);
+ groupBoxTools.Controls.Add(ButtonRemoveTank);
+ groupBoxTools.Controls.Add(ButtonAddMilitaryTank);
+ groupBoxTools.Controls.Add(ButtonAddTank);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(522, 0);
+ groupBoxTools.Margin = new Padding(3, 2, 3, 2);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Padding = new Padding(3, 2, 3, 2);
+ groupBoxTools.Size = new Size(194, 430);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "инструменты";
+ //
+ // maskedTextBoxPosision
+ //
+ maskedTextBoxPosision.Location = new Point(18, 172);
+ maskedTextBoxPosision.Margin = new Padding(3, 2, 3, 2);
+ maskedTextBoxPosision.Mask = "00";
+ maskedTextBoxPosision.Name = "maskedTextBoxPosision";
+ maskedTextBoxPosision.Size = new Size(163, 23);
+ maskedTextBoxPosision.TabIndex = 2;
+ maskedTextBoxPosision.ValidatingType = typeof(int);
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(18, 359);
+ buttonRefresh.Margin = new Padding(3, 2, 3, 2);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(163, 30);
+ buttonRefresh.TabIndex = 5;
+ buttonRefresh.Text = "обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGetToTest
+ //
+ buttonGetToTest.Anchor = AnchorStyles.Right;
+ buttonGetToTest.Location = new Point(18, 274);
+ buttonGetToTest.Margin = new Padding(3, 2, 3, 2);
+ buttonGetToTest.Name = "buttonGetToTest";
+ buttonGetToTest.Size = new Size(163, 30);
+ buttonGetToTest.TabIndex = 4;
+ buttonGetToTest.Text = "передать на тесты";
+ buttonGetToTest.UseVisualStyleBackColor = true;
+ buttonGetToTest.Click += ButtonGetToTest_Click;
+ //
+ // ButtonRemoveTank
+ //
+ ButtonRemoveTank.Anchor = AnchorStyles.Right;
+ ButtonRemoveTank.Location = new Point(18, 203);
+ ButtonRemoveTank.Margin = new Padding(3, 2, 3, 2);
+ ButtonRemoveTank.Name = "ButtonRemoveTank";
+ ButtonRemoveTank.Size = new Size(163, 30);
+ ButtonRemoveTank.TabIndex = 3;
+ ButtonRemoveTank.Text = "удалить танк";
+ ButtonRemoveTank.UseVisualStyleBackColor = true;
+ ButtonRemoveTank.Click += ButtonRemoveTank_Click;
+ //
+ // ButtonAddMilitaryTank
+ //
+ ButtonAddMilitaryTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ ButtonAddMilitaryTank.Location = new Point(18, 114);
+ ButtonAddMilitaryTank.Margin = new Padding(3, 2, 3, 2);
+ ButtonAddMilitaryTank.Name = "ButtonAddMilitaryTank";
+ ButtonAddMilitaryTank.Size = new Size(163, 38);
+ ButtonAddMilitaryTank.TabIndex = 2;
+ ButtonAddMilitaryTank.Text = "добавлене военного танка";
+ ButtonAddMilitaryTank.UseVisualStyleBackColor = true;
+ ButtonAddMilitaryTank.Click += ButtonAddMilitaryTank_Click;
+ //
+ // ButtonAddTank
+ //
+ ButtonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ ButtonAddTank.BackgroundImageLayout = ImageLayout.Center;
+ ButtonAddTank.Location = new Point(18, 80);
+ ButtonAddTank.Margin = new Padding(3, 2, 3, 2);
+ ButtonAddTank.Name = "ButtonAddTank";
+ ButtonAddTank.Size = new Size(163, 30);
+ ButtonAddTank.TabIndex = 1;
+ ButtonAddTank.Text = "добваление танк";
+ ButtonAddTank.UseVisualStyleBackColor = true;
+ ButtonAddTank.Click += ButtonAddTank_Click;
+ //
+ // comboBoxSelectorCompany
+ //
+ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectorCompany.FormattingEnabled = true;
+ comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" });
+ comboBoxSelectorCompany.Location = new Point(18, 20);
+ comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(163, 23);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1;
+ //
+ // pictureBoxTank
+ //
+ pictureBoxTank.Dock = DockStyle.Fill;
+ pictureBoxTank.Location = new Point(0, 0);
+ pictureBoxTank.Margin = new Padding(3, 2, 3, 2);
+ pictureBoxTank.Name = "pictureBoxTank";
+ pictureBoxTank.Size = new Size(522, 430);
+ pictureBoxTank.TabIndex = 1;
+ pictureBoxTank.TabStop = false;
+ //
+ // FormTanksCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(716, 430);
+ Controls.Add(pictureBoxTank);
+ Controls.Add(groupBoxTools);
+ Margin = new Padding(3, 2, 3, 2);
+ Name = "FormTanksCollection";
+ Text = "FormTanksCollection";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button ButtonAddMilitaryTank;
+ private Button ButtonAddTank;
+ private Button ButtonRemoveTank;
+ private Button buttonRefresh;
+ private Button buttonGetToTest;
+ private PictureBox pictureBoxTank;
+ private MaskedTextBox maskedTextBoxPosision;
+ }
+}
\ No newline at end of file
diff --git a/ProjectTank/ProjectTank/FormTanksCollection.cs b/ProjectTank/ProjectTank/FormTanksCollection.cs
new file mode 100644
index 0000000..52a91f2
--- /dev/null
+++ b/ProjectTank/ProjectTank/FormTanksCollection.cs
@@ -0,0 +1,169 @@
+using ProjectTank.CollectionGenericObjects;
+using ProjectTank.Drawnings;
+
+namespace ProjectTank
+{
+ public partial class FormTanksCollection : Form
+ {
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+ ///
+ /// Конструктор
+ ///
+ public FormTanksCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "хранилище":
+ _company = new TankDockingService(pictureBoxTank.Width,
+ pictureBoxTank.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ Random random = new();
+ DrawningTank drawningTank;
+ switch (type)
+ {
+ case nameof(DrawningTank):
+ drawningTank = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningMilitaryTank):
+ drawningTank = new DrawningMilitaryTank(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random),
+ GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+ if (_company + drawningTank != -1)
+ {
+ MessageBox.Show("объект добавлен");
+ pictureBoxTank.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();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ return color;
+ }
+
+ //private void ButtonAddTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTank));
+
+ //private void ButtonAddMilitaryTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryTank));
+ private void ButtonAddTank_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningTank));
+ }
+
+ private void ButtonAddMilitaryTank_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningMilitaryTank));
+ }
+
+ private void ButtonRemoveTank_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosision.Text) || _company == null)
+ {
+ return;
+ }
+ if (MessageBox.Show("удалить объект?", "удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosision.Text);
+ if (_company - pos != null)
+ {
+ MessageBox.Show("объект удален");
+ pictureBoxTank.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("не удалось удалить объект");
+ }
+ }
+
+ private void ButtonGetToTest_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawningTank? tank = null;
+ int counter = 100;
+ while (tank == null)
+ {
+ tank = _company.GetRandomObject();
+ counter--;
+ if (counter <= 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;
+ }
+
+ pictureBoxTank.Image = _company.Show();
+ }
+
+
+ }
+}
diff --git a/ProjectTank/ProjectTank/FormTanksCollection.resx b/ProjectTank/ProjectTank/FormTanksCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectTank/ProjectTank/FormTanksCollection.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/ProjectTank/MovementStrategy/MoveableTank.cs b/ProjectTank/ProjectTank/MovementStrategy/MoveableTank.cs
index a87b19d..23291a0 100644
--- a/ProjectTank/ProjectTank/MovementStrategy/MoveableTank.cs
+++ b/ProjectTank/ProjectTank/MovementStrategy/MoveableTank.cs
@@ -10,36 +10,36 @@ namespace ProjectTank.MovementStrategy
///
/// Поле-объект класса DrawningTank или его наследника
///
- private readonly DrawningTank? _cruiser = null;
+ private readonly DrawningTank? _tank = null;
///
/// Конструктор
///
- /// Объект класса DrawningTank
- public MoveableTank(DrawningTank cruiser)
+ /// Объект класса DrawningTank
+ public MoveableTank(DrawningTank tank)
{
- _cruiser = cruiser;
+ _tank = tank;
}
public ObjectParameters? GetObjectPosition
{
get
{
- if (_cruiser == null || _cruiser.EntityTank == null ||
- !_cruiser.GetPosX.HasValue || !_cruiser.GetPosY.HasValue)
+ if (_tank == null || _tank.EntityTank == null ||
+ !_tank.GetPosX.HasValue || !_tank.GetPosY.HasValue)
{
return null;
}
- return new ObjectParameters(_cruiser.GetPosX.Value,
- _cruiser.GetPosY.Value, _cruiser.GetWidth, _cruiser.GetHeight);
+ return new ObjectParameters(_tank.GetPosX.Value,
+ _tank.GetPosY.Value, _tank.GetWidth, _tank.GetHeight);
}
}
- public int GetStep => (int)(_cruiser?.EntityTank?.Step ?? 0);
+ public int GetStep => (int)(_tank?.EntityTank?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
- if (_cruiser == null || _cruiser.EntityTank == null)
+ if (_tank == null || _tank.EntityTank == null)
{
return false;
}
- return _cruiser.MoveTransport(GetDirectionType(direction));
+ return _tank.MoveTransport(GetDirectionType(direction));
}
///
/// Конвертация из MovementDirection в DirectionType
diff --git a/ProjectTank/ProjectTank/Program.cs b/ProjectTank/ProjectTank/Program.cs
index 61d6fe8..ea4a79c 100644
--- a/ProjectTank/ProjectTank/Program.cs
+++ b/ProjectTank/ProjectTank/Program.cs
@@ -3,15 +3,14 @@ namespace ProjectTank
internal static class Program
{
///
- /// The main entry point for the application.
+ /// 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.
+ // 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 FormTanksCollection());
}
}
}
\ No newline at end of file