diff --git a/Excavator/Excavator/CollectionGenericObjects/AbsractCompany.cs b/Excavator/Excavator/CollectionGenericObjects/AbsractCompany.cs
new file mode 100644
index 0000000..712c9b6
--- /dev/null
+++ b/Excavator/Excavator/CollectionGenericObjects/AbsractCompany.cs
@@ -0,0 +1,116 @@
+using Excavator.Drawnings;
+
+namespace Excavator.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 110;
+
+ ///
+ /// Ширина окна
+ ///
+ 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, DrawningSimpleExcavator car)
+ {
+ return company._collection.Insert(car);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningSimpleExcavator operator -(AbstractCompany company, int position)
+ {
+ return company._collection.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningSimpleExcavator? 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)
+ {
+ DrawningSimpleExcavator? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
diff --git a/Excavator/Excavator/CollectionGenericObjects/Garage.cs b/Excavator/Excavator/CollectionGenericObjects/Garage.cs
new file mode 100644
index 0000000..6b35061
--- /dev/null
+++ b/Excavator/Excavator/CollectionGenericObjects/Garage.cs
@@ -0,0 +1,65 @@
+using Excavator.Drawnings;
+
+namespace Excavator.CollectionGenericObjects;
+
+///
+/// Реализация абстрактной компании - экскаваторшеринг
+///
+public class Garage : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+
+ public Garage(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+
+ }
+ protected override void DrawBackgound(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 - 20, j * _placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+
+
+ protected override void SetObjectsPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth - 1;
+ int height = _pictureHeight / _placeSizeHeight - 1;
+
+ int curWidth = width;
+ 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 + 5);
+ }
+
+ if (curWidth > 0)
+ curWidth--;
+ else
+ {
+ curHeight++;
+ curWidth = width;
+ }
+ if (curHeight > height)
+ {
+ return;
+
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Excavator/Excavator/CollectionGenericObjects/ICollectionGenericObjects.cs b/Excavator/Excavator/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..3f8be1e
--- /dev/null
+++ b/Excavator/Excavator/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,48 @@
+namespace Excavator.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/Excavator/Excavator/CollectionGenericObjects/MassiveGenericObjects.cs b/Excavator/Excavator/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..31946a2
--- /dev/null
+++ b/Excavator/Excavator/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,118 @@
+namespace Excavator.CollectionGenericObjects;
+
+///
+/// Параметризованный набор объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public class MassiveGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private T?[] _collection;
+
+ public int Count => _collection.Length;
+
+ public int SetMaxCount
+ {
+ set
+ {
+ if (value > 0)
+ {
+ if (_collection.Length > 0)
+ {
+ Array.Resize(ref _collection, value);
+ }
+ else
+ {
+ _collection = new T?[value];
+ }
+ }
+ }
+ }
+
+ ///
+ /// Конструктор
+ ///
+ public MassiveGenericObjects()
+ {
+ _collection = Array.Empty();
+ }
+
+ public T? Get(int position)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+
+ return _collection[position];
+ }
+
+ 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)
+ {
+ // TODO проверка позиции
+ // TODO проверка, что элемент массима по этой позиции пустой,
+ // если элемент массима по этой позиции не пустой,
+ // найти свободное место после этой позиции, если не найдено,
+ // то искать до
+ // TODO вставка
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
+
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+ else
+ {
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+
+ for (int i = 0; i < position; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+
+ public T Remove(int position)
+ {
+ if (position >= Count || position < 0) return null;
+ T obj = _collection[position];
+ _collection[position] = null;
+ return obj;
+ }
+}
\ No newline at end of file
diff --git a/Excavator/Excavator/Excavator.csproj b/Excavator/Excavator/Excavator.csproj
index 244387d..e1a0735 100644
--- a/Excavator/Excavator/Excavator.csproj
+++ b/Excavator/Excavator/Excavator.csproj
@@ -8,19 +8,4 @@
enable
-
-
- True
- True
- Resources.resx
-
-
-
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
-
-
-
\ No newline at end of file
diff --git a/Excavator/Excavator/FormExcavator.Designer.cs b/Excavator/Excavator/FormExcavator.Designer.cs
index a652b92..bba3c49 100644
--- a/Excavator/Excavator/FormExcavator.Designer.cs
+++ b/Excavator/Excavator/FormExcavator.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxExcavator = new PictureBox();
- buttonCreateExcavator = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
- buttonCreateSimpleExcavator = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxExcavator).BeginInit();
@@ -49,17 +47,6 @@
pictureBoxExcavator.TabIndex = 0;
pictureBoxExcavator.TabStop = false;
//
- // buttonCreateExcavator
- //
- buttonCreateExcavator.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateExcavator.Location = new Point(12, 562);
- buttonCreateExcavator.Name = "buttonCreateExcavator";
- buttonCreateExcavator.Size = new Size(217, 23);
- buttonCreateExcavator.TabIndex = 1;
- buttonCreateExcavator.Text = "Создать экскаватор с обвесами";
- buttonCreateExcavator.UseVisualStyleBackColor = true;
- buttonCreateExcavator.Click += ButtonCreateExcavator_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -108,17 +95,6 @@
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
- // buttonCreateSimpleExcavator
- //
- buttonCreateSimpleExcavator.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateSimpleExcavator.Location = new Point(235, 562);
- buttonCreateSimpleExcavator.Name = "buttonCreateSimpleExcavator";
- buttonCreateSimpleExcavator.Size = new Size(217, 23);
- buttonCreateSimpleExcavator.TabIndex = 6;
- buttonCreateSimpleExcavator.Text = "Создать экскаватор ";
- buttonCreateSimpleExcavator.UseVisualStyleBackColor = true;
- buttonCreateSimpleExcavator.Click += ButtonCreateSimpleExcavator_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
@@ -147,12 +123,10 @@
ClientSize = new Size(923, 597);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateSimpleExcavator);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateExcavator);
Controls.Add(pictureBoxExcavator);
Name = "FormExcavator";
Text = "Экскаватор";
@@ -163,12 +137,10 @@
#endregion
private PictureBox pictureBoxExcavator;
- private Button buttonCreateExcavator;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
- private Button buttonCreateSimpleExcavator;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/Excavator/Excavator/FormExcavator.cs b/Excavator/Excavator/FormExcavator.cs
index 27aa00b..023dc1d 100644
--- a/Excavator/Excavator/FormExcavator.cs
+++ b/Excavator/Excavator/FormExcavator.cs
@@ -24,7 +24,17 @@ public partial class FormExcavator : Form
InitializeComponent();
_strategy = null;
}
-
+ public DrawningSimpleExcavator SetExcavator
+ {
+ set
+ {
+ _drawningSimpleExcavator = value;
+ _drawningSimpleExcavator.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
///
/// Метод прорисовки экскаватора
///
@@ -41,57 +51,6 @@ public partial class FormExcavator : Form
pictureBoxExcavator.Image = bmp;
}
- ///
- /// Создание объекта
- ///
- ///
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningSimpleExcavator):
- _drawningSimpleExcavator = new DrawningSimpleExcavator(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(DrawningExcavator):
- _drawningSimpleExcavator = new DrawningExcavator(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(1, 2)), Convert.ToBoolean(random.Next(1, 2)));
- break;
- default:
- return;
- }
-
- _drawningSimpleExcavator.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
- _drawningSimpleExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- //comboBoxStrategy.Enabled = true;
- Draw();
-
- }
-
- ///
- /// Обработка нажатия кнопки "Создать экскаватор с обвесами"
- ///
- ///
- ///
- private void ButtonCreateExcavator_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawningExcavator));
- }
-
- ///
- /// Обработка нажатия кнопки "Создать экскаватор"
- ///
- ///
- ///
- private void ButtonCreateSimpleExcavator_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawningSimpleExcavator));
- }
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
diff --git a/Excavator/Excavator/FormExcavatorCollection.Designer.cs b/Excavator/Excavator/FormExcavatorCollection.Designer.cs
new file mode 100644
index 0000000..2314178
--- /dev/null
+++ b/Excavator/Excavator/FormExcavatorCollection.Designer.cs
@@ -0,0 +1,172 @@
+namespace Excavator
+{
+ partial class FormExcavatorCollection
+ {
+ ///
+ /// 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();
+ buttonRemoveExcavator = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddExcavator = new Button();
+ buttonAddSimpleExcavator = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Anchor = AnchorStyles.Right;
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGoToCheck);
+ groupBoxTools.Controls.Add(buttonRemoveExcavator);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddExcavator);
+ groupBoxTools.Controls.Add(buttonAddSimpleExcavator);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point);
+ groupBoxTools.Location = new Point(855, 1);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(212, 634);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(6, 473);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(200, 49);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Location = new Point(6, 379);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(200, 49);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveExcavator
+ //
+ buttonRemoveExcavator.Location = new Point(6, 273);
+ buttonRemoveExcavator.Name = "buttonRemoveExcavator";
+ buttonRemoveExcavator.Size = new Size(200, 49);
+ buttonRemoveExcavator.TabIndex = 4;
+ buttonRemoveExcavator.Text = "Удалить экскаватор";
+ buttonRemoveExcavator.UseVisualStyleBackColor = true;
+ buttonRemoveExcavator.Click += ButtonRemoveExcavator_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(12, 244);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(194, 20);
+ maskedTextBoxPosition.TabIndex = 3;
+ //
+ // buttonAddExcavator
+ //
+ buttonAddExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddExcavator.Location = new Point(6, 145);
+ buttonAddExcavator.Name = "buttonAddExcavator";
+ buttonAddExcavator.Size = new Size(200, 52);
+ buttonAddExcavator.TabIndex = 2;
+ buttonAddExcavator.Text = "Добавить экскаватор с обвесами";
+ buttonAddExcavator.UseVisualStyleBackColor = true;
+ buttonAddExcavator.Click += ButtonAddExcavator_Click;
+ //
+ // buttonAddSimpleExcavator
+ //
+ buttonAddSimpleExcavator.Location = new Point(6, 87);
+ buttonAddSimpleExcavator.Name = "buttonAddSimpleExcavator";
+ buttonAddSimpleExcavator.Size = new Size(200, 52);
+ buttonAddSimpleExcavator.TabIndex = 1;
+ buttonAddSimpleExcavator.Text = "Добавить экскаватор";
+ buttonAddSimpleExcavator.UseVisualStyleBackColor = true;
+ buttonAddSimpleExcavator.Click += ButtonAddSimleExcavator_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(12, 22);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(194, 21);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // pictureBox
+ //
+ pictureBox.AccessibleRole = AccessibleRole.None;
+ pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ pictureBox.BackgroundImageLayout = ImageLayout.None;
+ pictureBox.Location = new Point(0, 1);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(855, 634);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ pictureBox.Click += pictureBox_Click;
+ //
+ // FormExcavatorCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1067, 635);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormExcavatorCollection";
+ Text = "Коллекция экскаваторов";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private Button buttonAddExcavator;
+ private Button buttonAddSimpleExcavator;
+ private ComboBox comboBoxSelectorCompany;
+ private PictureBox pictureBox;
+ private Button buttonGoToCheck;
+ private Button buttonRemoveExcavator;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonRefresh;
+ }
+}
\ No newline at end of file
diff --git a/Excavator/Excavator/FormExcavatorCollection.cs b/Excavator/Excavator/FormExcavatorCollection.cs
new file mode 100644
index 0000000..4aaf62b
--- /dev/null
+++ b/Excavator/Excavator/FormExcavatorCollection.cs
@@ -0,0 +1,158 @@
+using Excavator.CollectionGenericObjects;
+using Excavator.Drawnings;
+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 Excavator;
+
+public partial class FormExcavatorCollection : Form
+{
+
+ private AbstractCompany? _company = null;
+
+ public FormExcavatorCollection()
+ {
+ InitializeComponent();
+ }
+
+ private void pictureBox_Click(object sender, EventArgs e)
+ {
+
+ }
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ DrawningSimpleExcavator drawningSimpleExcavator;
+ Random random = new();
+ switch (type)
+ {
+ case nameof(DrawningSimpleExcavator):
+ drawningSimpleExcavator = new DrawningSimpleExcavator(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random));
+ break;
+ case nameof(DrawningExcavator):
+ drawningSimpleExcavator = new DrawningExcavator(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawningSimpleExcavator != -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();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
+ return color;
+ }
+ private void ButtonAddSimleExcavator_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleExcavator));
+ private void ButtonAddExcavator_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningExcavator));
+ private void ButtonRemoveExcavator_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_company - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawningSimpleExcavator? excavator = null;
+ int counter = 100;
+ while (excavator == null)
+ {
+ excavator = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (excavator == null)
+ {
+ return;
+ }
+
+ FormExcavator form = new()
+ {
+ SetExcavator = excavator
+ };
+ 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/Excavator/Excavator/FormExcavatorCollection.resx b/Excavator/Excavator/FormExcavatorCollection.resx
new file mode 100644
index 0000000..a395bff
--- /dev/null
+++ b/Excavator/Excavator/FormExcavatorCollection.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/Excavator/Excavator/MovementSrtategy/MoveToBorder.cs b/Excavator/Excavator/MovementSrtategy/MoveToBorder.cs
index 51ab69f..83fec93 100644
--- a/Excavator/Excavator/MovementSrtategy/MoveToBorder.cs
+++ b/Excavator/Excavator/MovementSrtategy/MoveToBorder.cs
@@ -16,7 +16,7 @@ public class MoveToBorder : AbstractStrategy
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
- {
+ {
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
diff --git a/Excavator/Excavator/Program.cs b/Excavator/Excavator/Program.cs
index 4f04208..032fe7f 100644
--- a/Excavator/Excavator/Program.cs
+++ b/Excavator/Excavator/Program.cs
@@ -11,7 +11,7 @@ namespace Excavator
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormExcavator());
+ Application.Run(new FormExcavatorCollection());
}
}
}
\ No newline at end of file