diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..1eb7aa1
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,118 @@
+using ProjectLiner.CollectionGenericObjects;
+using ProjectLiner.Drawnings;
+
+namespace ProjectLiner.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 bool operator +(AbstractCompany company, DrawningCommonLiner Liner)
+ {
+ return company._collection?.Insert(Liner) ?? false;
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static bool operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position) ?? false;
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningCommonLiner? 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)
+ {
+ DrawningCommonLiner? 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/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..9e2ed2f
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,49 @@
+namespace ProjectLiner.CollectionGenericObjects
+{
+ ///
+ /// Интерфейс описания действий для набора хранимых объектов
+ ///
+ /// Параметр: ограничение - ссылочный тип
+ public interface ICollectionGenericObjects
+ where T : class
+ {
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+ bool Insert(T obj);
+
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла удачно, false - вставка не удалась
+ bool Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло удачно, false - удаление не удалось
+ bool Remove(int position);
+
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs
new file mode 100644
index 0000000..0501fa8
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs
@@ -0,0 +1,74 @@
+
+using ProjectLiner.Drawnings;
+using ProjectLiner.CollectionGenericObjects;
+
+namespace ProjectLiner.CollectionGenericObjects;
+
+///
+/// Реализация абстрактной компании - лайнер
+///
+public class LinerSharingService : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ /// Ширина
+ /// Высота
+ /// Коллекция
+ public LinerSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackgound(Graphics g)
+ {
+
+ int count_width = _pictureWidth / _placeSizeWidth; // кол-во мест в ширину
+ int count_height = _pictureHeight / _placeSizeHeight;
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < count_width; i++)
+ {
+ for (int j = 0; j < count_height + 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 50, j * _placeSizeHeight); // вертикаль
+ g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + 10, j * _placeSizeHeight + _placeSizeHeight);
+ }
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+ int positionWidth = 0;
+ int positionHeight = height - 1;
+
+ if (_collection?.Count != null)
+ {
+ for (int i = 0; i < (_collection.Count); i++)
+ {
+ if (_collection.Get(i) != null)
+ {
+ _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i).SetPosition(_placeSizeWidth * positionWidth + 25, positionHeight * _placeSizeHeight + 10);
+ }
+
+ if (positionWidth < width - 1)
+ {
+ positionWidth++;
+ }
+
+ else
+ {
+ positionWidth = 0;
+ positionHeight--;
+ }
+ if (positionHeight < 0)
+ {
+ return;
+ }
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..9865dd0
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,111 @@
+using ProjectLiner.CollectionGenericObjects;
+
+namespace ProjectLiner.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)
+ {
+ if (position < 0 || position >= Count)
+ return null;
+ return _collection[position];
+ }
+
+ public bool Insert(T obj)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public bool Insert(T obj, int position)
+ {
+ if (position < 0 || position >= Count)
+ return false;
+
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return true;
+ }
+
+ int temp = position + 1;
+ while (temp < Count)
+ {
+ if (_collection[temp] == null)
+ {
+ _collection[temp] = obj;
+ return true;
+ }
+ temp++;
+ }
+
+ temp = position - 1;
+ while (temp > 0)
+ {
+ if (_collection[temp] == null)
+ {
+ _collection[temp] = obj;
+ return true;
+ }
+ temp--;
+ }
+
+ return false;
+ }
+
+ public bool Remove(int position)
+ {
+ if (position < 0 || position >= Count)
+ return false;
+
+ _collection[position] = null;
+
+ return true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
index c21ee63..7dc1072 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxLiner = new PictureBox();
- buttonCreate = new Button();
buttonDown = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonRight = new Button();
- buttonCreateCommonLiner = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
@@ -45,30 +43,21 @@
pictureBoxLiner.BackColor = SystemColors.Control;
pictureBoxLiner.Dock = DockStyle.Fill;
pictureBoxLiner.Location = new Point(0, 0);
+ pictureBoxLiner.Margin = new Padding(5, 5, 5, 5);
pictureBoxLiner.Name = "pictureBoxLiner";
- pictureBoxLiner.Size = new Size(948, 614);
+ pictureBoxLiner.Size = new Size(1465, 1007);
pictureBoxLiner.TabIndex = 0;
pictureBoxLiner.TabStop = false;
//
- // buttonCreate
- //
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 544);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(203, 58);
- buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать Лайнер";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += buttonCreate_Click;
- //
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.bottom;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
- buttonDown.Location = new Point(830, 552);
+ buttonDown.Location = new Point(1283, 905);
+ buttonDown.Margin = new Padding(5, 5, 5, 5);
buttonDown.Name = "buttonDown";
- buttonDown.Size = new Size(50, 50);
+ buttonDown.Size = new Size(77, 82);
buttonDown.TabIndex = 2;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
@@ -78,9 +67,10 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.top;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
- buttonUp.Location = new Point(830, 496);
+ buttonUp.Location = new Point(1283, 813);
+ buttonUp.Margin = new Padding(5, 5, 5, 5);
buttonUp.Name = "buttonUp";
- buttonUp.Size = new Size(50, 50);
+ buttonUp.Size = new Size(77, 82);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
@@ -90,9 +80,10 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- buttonLeft.Location = new Point(774, 552);
+ buttonLeft.Location = new Point(1196, 905);
+ buttonLeft.Margin = new Padding(5, 5, 5, 5);
buttonLeft.Name = "buttonLeft";
- buttonLeft.Size = new Size(50, 50);
+ buttonLeft.Size = new Size(77, 82);
buttonLeft.TabIndex = 4;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
@@ -102,39 +93,31 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
- buttonRight.Location = new Point(886, 552);
+ buttonRight.Location = new Point(1369, 905);
+ buttonRight.Margin = new Padding(5, 5, 5, 5);
buttonRight.Name = "buttonRight";
- buttonRight.Size = new Size(50, 50);
+ buttonRight.Size = new Size(77, 82);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
- // buttonCreateCommonLiner
- //
- buttonCreateCommonLiner.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateCommonLiner.Location = new Point(221, 544);
- buttonCreateCommonLiner.Name = "buttonCreateCommonLiner";
- buttonCreateCommonLiner.Size = new Size(240, 58);
- buttonCreateCommonLiner.TabIndex = 6;
- buttonCreateCommonLiner.Text = "Создать Обычный Лайнер";
- buttonCreateCommonLiner.UseVisualStyleBackColor = true;
- buttonCreateCommonLiner.Click += buttonCreateCommonLiner_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
- comboBoxStrategy.Location = new Point(742, 12);
+ comboBoxStrategy.Location = new Point(1147, 20);
+ comboBoxStrategy.Margin = new Padding(5, 5, 5, 5);
comboBoxStrategy.Name = "comboBoxStrategy";
- comboBoxStrategy.Size = new Size(194, 33);
+ comboBoxStrategy.Size = new Size(298, 49);
comboBoxStrategy.TabIndex = 11;
//
// buttonStrategyStep
//
- buttonStrategyStep.Location = new Point(816, 51);
+ buttonStrategyStep.Location = new Point(1261, 84);
+ buttonStrategyStep.Margin = new Padding(5, 5, 5, 5);
buttonStrategyStep.Name = "buttonStrategyStep";
- buttonStrategyStep.Size = new Size(120, 37);
+ buttonStrategyStep.Size = new Size(185, 61);
buttonStrategyStep.TabIndex = 12;
buttonStrategyStep.Text = "Шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
@@ -142,18 +125,17 @@
//
// FormLiner
//
- AutoScaleDimensions = new SizeF(11F, 25F);
+ AutoScaleDimensions = new SizeF(17F, 41F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(948, 614);
+ ClientSize = new Size(1465, 1007);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateCommonLiner);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(buttonDown);
- Controls.Add(buttonCreate);
Controls.Add(pictureBoxLiner);
+ Margin = new Padding(5, 5, 5, 5);
Name = "FormLiner";
Text = "Лайнер";
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).EndInit();
@@ -163,12 +145,10 @@
#endregion
private PictureBox pictureBoxLiner;
- private Button buttonCreate;
private Button buttonDown;
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;
- private Button buttonCreateCommonLiner;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectLiner/ProjectLiner/FormLiner.cs b/ProjectLiner/ProjectLiner/FormLiner.cs
index aa13498..683457a 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.cs
@@ -23,6 +23,23 @@ namespace ProjectLiner
_strategy = null;
}
+
+ ///
+ /// Стратегия перемещения
+ ///
+
+ public DrawningLiner SetLiner
+ {
+ set
+ {
+ _drawningCommonLiner = value;
+ _drawningCommonLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
///
/// Метод прорисовки лайнера
///
@@ -39,57 +56,6 @@ namespace ProjectLiner
pictureBoxLiner.Image = bmp;
}
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningCommonLiner):
- _drawningCommonLiner = new DrawningCommonLiner(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(DrawningLiner):
- _drawningCommonLiner = new DrawningLiner(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;
-
- }
-
- _drawningCommonLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
- _drawningCommonLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
- ///
- /// Обработка нажатия кнопки "Создать Лайнер"
- ///
- ///
- ///
- private void buttonCreate_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawningLiner));
- }
-
- ///
- /// Обработка нажатия кнопки "Создать Обычный Лайнер"
- ///
- ///
- ///
-
- private void buttonCreateCommonLiner_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawningCommonLiner));
- }
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs
new file mode 100644
index 0000000..1aeb63b
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs
@@ -0,0 +1,173 @@
+namespace ProjectLiner
+{
+ partial class FormLinerCollection
+ {
+ ///
+ /// 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();
+ buttonRemoveLiner = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddCommonLiner = new Button();
+ buttonAddLiner = 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(buttonRemoveLiner);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddCommonLiner);
+ groupBoxTools.Controls.Add(buttonAddLiner);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(1053, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(272, 845);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(33, 683);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(217, 76);
+ 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(33, 562);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(217, 76);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveLiner
+ //
+ buttonRemoveLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveLiner.Location = new Point(33, 416);
+ buttonRemoveLiner.Name = "buttonRemoveLiner";
+ buttonRemoveLiner.Size = new Size(217, 76);
+ buttonRemoveLiner.TabIndex = 4;
+ buttonRemoveLiner.Text = "Удаление Лайнера";
+ buttonRemoveLiner.UseVisualStyleBackColor = true;
+ buttonRemoveLiner.Click += ButtonRemoveLiner_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(33, 363);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(217, 47);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddCommonLiner
+ //
+ buttonAddCommonLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddCommonLiner.Location = new Point(33, 236);
+ buttonAddCommonLiner.Name = "buttonAddCommonLiner";
+ buttonAddCommonLiner.Size = new Size(217, 76);
+ buttonAddCommonLiner.TabIndex = 2;
+ buttonAddCommonLiner.Text = "Добавление Обычного Лайнера";
+ buttonAddCommonLiner.UseVisualStyleBackColor = true;
+ buttonAddCommonLiner.Click += ButtonAddCommonLiner_Click;
+ //
+ // buttonAddLiner
+ //
+ buttonAddLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddLiner.Location = new Point(33, 126);
+ buttonAddLiner.Name = "buttonAddLiner";
+ buttonAddLiner.Size = new Size(217, 76);
+ buttonAddLiner.TabIndex = 1;
+ buttonAddLiner.Text = "Добавление Лайнера";
+ buttonAddLiner.UseVisualStyleBackColor = true;
+ buttonAddLiner.Click += ButtonAddLiner_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(18, 46);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(242, 49);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // pictureBox
+ //
+ pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Location = new Point(0, 0);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(1053, 845);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormLinerCollection
+ //
+ AutoScaleDimensions = new SizeF(17F, 41F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1325, 845);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormLinerCollection";
+ Text = "Коллекция автомобилей";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private Button buttonAddLiner;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddCommonLiner;
+ private PictureBox pictureBox;
+ private Button buttonGoToCheck;
+ private Button buttonRemoveLiner;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonRefresh;
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
new file mode 100644
index 0000000..38bb839
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
@@ -0,0 +1,188 @@
+using ProjectLiner.CollectionGenericObjects;
+using ProjectLiner.Drawnings;
+using System.Windows.Forms;
+
+namespace ProjectLiner
+{
+ ///
+ /// Форма работы с компанией и ее коллекцией
+ ///
+ public partial class FormLinerCollection : Form
+ {
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormLinerCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new LinerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ Random random = new();
+ DrawningCommonLiner drawingLiner;
+ switch (type)
+ {
+ case nameof(DrawningCommonLiner):
+ drawingLiner = new DrawningCommonLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningLiner):
+ drawingLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawingLiner)
+ {
+ 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 ButtonAddCommonLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCommonLiner));
+
+ ///
+ /// Добавление лайнера
+ ///
+ ///
+ ///
+ private void ButtonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner));
+
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveLiner_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)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawningCommonLiner? liner = null;
+ int counter = 100;
+ while (liner == null)
+ {
+ liner = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (liner == null)
+ {
+ return;
+ }
+
+ FormLiner form = new()
+ {
+ SetLiner = (DrawningLiner)liner
+ };
+ form.ShowDialog();
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+ }
+ }
+}
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.resx b/ProjectLiner/ProjectLiner/FormLinerCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.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/ProjectLiner/ProjectLiner/Program.cs b/ProjectLiner/ProjectLiner/Program.cs
index b3dc92e..e3f64ca 100644
--- a/ProjectLiner/ProjectLiner/Program.cs
+++ b/ProjectLiner/ProjectLiner/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectLiner
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormLiner());
+ Application.Run(new FormLinerCollection());
}
}
}
\ No newline at end of file