diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..36f5c38
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,116 @@
+using ProjectElectricLocomotive.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.CollectionGenericObjects;
+
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 147;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 64;
+
+ ///
+ /// Ширина окна
+ ///
+ 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, DrawningLocomotive truck)
+ {
+ return company._collection.Insert(truck);
+ }
+
+ //
+ // Перегрузка оператора удаления для класса
+ //
+ // Компания param >
+ // < param name="position">Номер удаляемого объекта
+ //
+ public static DrawningLocomotive operator -(AbstractCompany company, int position)
+ {
+ return company._collection.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningLocomotive? 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)
+ {
+ DrawningLocomotive? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..c5a8798
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.CollectionGenericObjects;
+
+///
+/// Интерфейс описания действий для набора хранимых объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public interface ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj);
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ /// /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj, int position);
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло удачно, false - удаление не удалось
+ T? Remove(int position);
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+
+}
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepot.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepot.cs
new file mode 100644
index 0000000..9f477be
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepot.cs
@@ -0,0 +1,74 @@
+using ProjectElectricLocomotive.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.CollectionGenericObjects;
+
+public class LocomotiveDepot : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ /// Ширина
+ /// Высота
+ /// Коллекция
+ public LocomotiveDepot(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;
+ }
+ }
+ }
+
+ }
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..c1c6c32
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.CollectionGenericObjects;
+
+///
+/// Параметризованный набор объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public class MassiveGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private T?[] _collection;
+
+ public int Count => _collection.Length;
+
+ public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
+
+ ///
+ /// Конструктор
+ ///
+ public MassiveGenericObjects()
+ {
+ _collection = Array.Empty();
+ }
+
+
+ public T? Get(int position)
+ {
+ // проверка позиции
+ if (position >= Count || position < 0)
+ {
+ 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)
+ {
+ // проверка позиции
+ // проверка, что элемент массива по этой позиции пустой, если нет, то
+ // ищется свободное место после этой позиции и идет вставка туда, если нет после, ищем до
+ // вставка
+
+ if (position >= Count || position < 0)
+ {
+ return -1;
+ }
+
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+ else
+ {
+ for (int i = 1; i < Count; ++i)
+ {
+ if (_collection[position + i] == null)
+ {
+ _collection[position + i] = obj;
+ return position + i;
+ }
+ for (i = position - 1; i >= 0; i--)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+ }
+ }
+ return -1;
+
+ }
+ public T? Remove(int position)
+ {
+ //// проверка позиции
+ //// удаление объекта из массива, присвоив элементу массива значение null
+
+ if (position >= Count || position < 0 || _collection[position] == null) return null;
+ T removedObject = _collection[position];
+ _collection[position] = null;
+ return removedObject;
+ }
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs
index b758749..3dda2d5 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxElectricLocomotive = new PictureBox();
- buttonCreate = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
- buttonCreateLocomotive = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
@@ -49,17 +47,6 @@
pictureBoxElectricLocomotive.TabIndex = 0;
pictureBoxElectricLocomotive.TabStop = false;
//
- // buttonCreate
- //
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 436);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(150, 31);
- buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать электровоз";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += ButtonCreate_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -112,17 +99,6 @@
buttonUp.UseVisualStyleBackColor = false;
buttonUp.Click += ButtonMove_Click;
//
- // buttonCreateLocomotive
- //
- buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateLocomotive.Location = new Point(187, 436);
- buttonCreateLocomotive.Name = "buttonCreateLocomotive";
- buttonCreateLocomotive.Size = new Size(150, 31);
- buttonCreateLocomotive.TabIndex = 6;
- buttonCreateLocomotive.Text = "Создать локомотив";
- buttonCreateLocomotive.UseVisualStyleBackColor = true;
- buttonCreateLocomotive.Click += buttonCreateLocomotive_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -150,12 +126,10 @@
ClientSize = new Size(866, 479);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateLocomotive);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreate);
Controls.Add(pictureBoxElectricLocomotive);
Name = "FormElectricLocomotive";
Text = "Электровоз";
@@ -166,12 +140,10 @@
#endregion
private PictureBox pictureBoxElectricLocomotive;
- private Button buttonCreate;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
- private Button buttonCreateLocomotive;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs
index 305f806..9c18238 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormElectricLocomotive.cs
@@ -21,6 +21,22 @@ public partial class FormElectricLocomotive : Form
private AbstractStrategy? _strategy;
+
+ ///
+ /// Получение объекта
+ ///
+ public DrawningLocomotive SetLocomotive
+ {
+ set
+ {
+ _drawningLocomotive = value;
+ _drawningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
///
/// Конструктор формы
///
@@ -46,50 +62,6 @@ public partial class FormElectricLocomotive : Form
pictureBoxElectricLocomotive.Image = bmp;
}
- ///
- /// Создание объекта класса-перемещения
- ///
- ///
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningLocomotive):
- _drawningLocomotive = new DrawningLocomotive(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(DrawningElectricLocomotive):
- _drawningLocomotive = new DrawningElectricLocomotive(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)));
- break;
- default:
- return;
- }
- _drawningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
- _drawningLocomotive.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(DrawningElectricLocomotive));
-
- ///
- /// Обработка нажатия кнопки "Создать локомотив"
- ///
- ///
- ///
- private void buttonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
-
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs
new file mode 100644
index 0000000..b85a000
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs
@@ -0,0 +1,171 @@
+namespace ProjectElectricLocomotive
+{
+ partial class FormLocomotiveCollection
+ {
+ ///
+ /// 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();
+ buttonRemoveLocomotive = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddElectricLocomotiv = new Button();
+ buttonAddLocomotive = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ colorDialog1 = new ColorDialog();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGoToCheck);
+ groupBoxTools.Controls.Add(buttonRemoveLocomotive);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddElectricLocomotiv);
+ groupBoxTools.Controls.Add(buttonAddLocomotive);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(600, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(200, 450);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(6, 336);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(188, 32);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Location = new Point(6, 265);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(188, 32);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Поставить на пути";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveLocomotive
+ //
+ buttonRemoveLocomotive.Location = new Point(6, 193);
+ buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
+ buttonRemoveLocomotive.Size = new Size(188, 32);
+ buttonRemoveLocomotive.TabIndex = 4;
+ buttonRemoveLocomotive.Text = "Удалить локомотив";
+ buttonRemoveLocomotive.UseVisualStyleBackColor = true;
+ buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(6, 164);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(188, 23);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddElectricLocomotiv
+ //
+ buttonAddElectricLocomotiv.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddElectricLocomotiv.Location = new Point(6, 104);
+ buttonAddElectricLocomotiv.Name = "buttonAddElectricLocomotiv";
+ buttonAddElectricLocomotiv.Size = new Size(188, 32);
+ buttonAddElectricLocomotiv.TabIndex = 2;
+ buttonAddElectricLocomotiv.Text = "Добавить электровоз";
+ buttonAddElectricLocomotiv.UseVisualStyleBackColor = true;
+ buttonAddElectricLocomotiv.Click += ButtonAddElectricLocomotive_Click;
+ //
+ // buttonAddLocomotive
+ //
+ buttonAddLocomotive.Location = new Point(6, 66);
+ buttonAddLocomotive.Name = "buttonAddLocomotive";
+ buttonAddLocomotive.Size = new Size(188, 32);
+ buttonAddLocomotive.TabIndex = 1;
+ buttonAddLocomotive.Text = "Добавить локомотив";
+ buttonAddLocomotive.UseVisualStyleBackColor = true;
+ buttonAddLocomotive.Click += ButtonAddLocomotive_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(6, 22);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(188, 23);
+ 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(600, 450);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormLocomotiveCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormLocomotiveCollection";
+ Text = "FormLocomotiveCollection";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddLocomotive;
+ private Button buttonRemoveLocomotive;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonAddElectricLocomotiv;
+ private PictureBox pictureBox;
+ private Button buttonGoToCheck;
+ private Button buttonRefresh;
+ private ColorDialog colorDialog1;
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.cs
new file mode 100644
index 0000000..5ee6f91
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.cs
@@ -0,0 +1,184 @@
+using ProjectElectricLocomotive.CollectionGenericObjects;
+using ProjectElectricLocomotive.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 ProjectElectricLocomotive;
+
+public partial class FormLocomotiveCollection : Form
+{
+
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormLocomotiveCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new LocomotiveDepot(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+ ///
+ /// Добавление грузовика
+ ///
+ ///
+ ///
+ private void ButtonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
+ ///
+ /// Добавление бензовоза
+ ///
+ ///
+ ///
+ private void ButtonAddElectricLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningElectricLocomotive));
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ Random random = new();
+ DrawningLocomotive DrawningLocomotive;
+ switch (type)
+ {
+ case nameof(DrawningLocomotive):
+ DrawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningElectricLocomotive):
+ DrawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 5000), GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+ if (_company + DrawningLocomotive != -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 ButtonRemoveLocomotive_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 ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ pictureBox.Image = _company.Show();
+ }
+
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ DrawningLocomotive? locomotive = null;
+ int counter = 100;
+ while (locomotive == null)
+ {
+ locomotive = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+ if (locomotive == null)
+ {
+ return;
+ }
+ FormElectricLocomotive form = new()
+ {
+ SetLocomotive = locomotive
+ };
+ form.ShowDialog();
+ }
+
+
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.resx b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.resx
new file mode 100644
index 0000000..818dfae
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs
index ddb490c..5def1ba 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectElectricLocomotive
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormElectricLocomotive());
+ Application.Run(new FormLocomotiveCollection());
}
}
}
\ No newline at end of file