diff --git a/ProjertTrain/ProjertTrain/CollectionGenericObjects/AbstractCompany.cs b/ProjertTrain/ProjertTrain/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..542b7ec
--- /dev/null
+++ b/ProjertTrain/ProjertTrain/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,115 @@
+using ProjectTrain.Drawnings;
+
+namespace ProjectTrain.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, DrawningTrain сruiser)
+ {
+ return company._collection.Insert(сruiser);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningTrain operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningTrain? 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)
+ {
+ DrawningTrain? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+ }
+}
diff --git a/ProjertTrain/ProjertTrain/CollectionGenericObjects/CruiserDockingService.cs b/ProjertTrain/ProjertTrain/CollectionGenericObjects/CruiserDockingService.cs
new file mode 100644
index 0000000..2d91819
--- /dev/null
+++ b/ProjertTrain/ProjertTrain/CollectionGenericObjects/CruiserDockingService.cs
@@ -0,0 +1,65 @@
+using ProjectTrain.Drawnings;
+
+namespace ProjectTrain.CollectionGenericObjects
+{
+ ///
+ /// Реализация абстрактной компании - каршеринг
+ ///
+ public class TrainDockingService : AbstractCompany
+ {
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public TrainDockingService(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/ProjertTrain/ProjertTrain/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjertTrain/ProjertTrain/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..e0e56fe
--- /dev/null
+++ b/ProjertTrain/ProjertTrain/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,45 @@
+namespace ProjectTrain.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/ProjertTrain/ProjertTrain/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjertTrain/ProjertTrain/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..6a86fea
--- /dev/null
+++ b/ProjertTrain/ProjertTrain/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,97 @@
+using ProjectTrain.Drawnings;
+
+namespace ProjectTrain.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 drawningTrain = _collection[position];
+ _collection[position] = null;
+ return drawningTrain;
+ }
+ }
+}
diff --git a/ProjertTrain/ProjertTrain/FormTrain.Designer.cs b/ProjertTrain/ProjertTrain/FormTrain.Designer.cs
index b21316a..5d8b67d 100644
--- a/ProjertTrain/ProjertTrain/FormTrain.Designer.cs
+++ b/ProjertTrain/ProjertTrain/FormTrain.Designer.cs
@@ -30,13 +30,11 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormTrain));
pictureBoxTrain = new PictureBox();
- button1 = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonLeft = new Button();
comboBoxStrategy = new ComboBox();
- buttonCretaeTrain = new Button();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxTrain).BeginInit();
SuspendLayout();
@@ -45,34 +43,20 @@
//
pictureBoxTrain.Dock = DockStyle.Fill;
pictureBoxTrain.Location = new Point(0, 0);
- pictureBoxTrain.Margin = new Padding(3, 2, 3, 2);
pictureBoxTrain.Name = "pictureBoxTrain";
- pictureBoxTrain.Size = new Size(700, 338);
+ pictureBoxTrain.Size = new Size(800, 450);
pictureBoxTrain.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxTrain.TabIndex = 0;
pictureBoxTrain.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 += ButtonCreateTrain_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;
//
- // buttonCretaeTrain
- //
- buttonCretaeTrain.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCretaeTrain.Location = new Point(210, 308);
- buttonCretaeTrain.Margin = new Padding(3, 2, 3, 2);
- buttonCretaeTrain.Name = "buttonCretaeTrain";
- buttonCretaeTrain.Size = new Size(186, 22);
- buttonCretaeTrain.TabIndex = 7;
- buttonCretaeTrain.Text = "создать поезда";
- buttonCretaeTrain.UseVisualStyleBackColor = true;
- buttonCretaeTrain.Click += buttonCretaeTrain_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 @@
//
// FormTrain
//
- 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(buttonCretaeTrain);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonLeft);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
- Controls.Add(button1);
Controls.Add(pictureBoxTrain);
- Margin = new Padding(3, 2, 3, 2);
Name = "FormTrain";
Text = "FormTrain";
Click += ButtonMove_Click;
@@ -177,13 +141,11 @@
#endregion
private PictureBox pictureBoxTrain;
- private Button button1;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private ComboBox comboBoxStrategy;
- private Button buttonCretaeTrain;
private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/ProjertTrain/ProjertTrain/FormTrain.cs b/ProjertTrain/ProjertTrain/FormTrain.cs
index 6d3c703..746d7f7 100644
--- a/ProjertTrain/ProjertTrain/FormTrain.cs
+++ b/ProjertTrain/ProjertTrain/FormTrain.cs
@@ -15,6 +15,25 @@ namespace ProjectTrain
///
private AbstractStrategy? _strategy;
+ ///
+ /// Получение объекта
+ ///
+ public DrawningTrain SetTrain
+ {
+ set
+ {
+ _drawningTrain = value;
+ _drawningTrain.SetPictureSize(pictureBoxTrain.Width,
+ pictureBoxTrain.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
+ ///
+ /// Конструктор формы
+ ///
public FormTrain()
{
InitializeComponent();
@@ -37,57 +56,6 @@ namespace ProjectTrain
pictureBoxTrain.Image = bmp;
}
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningTrain):
- _drawningTrain = new DrawningTrain(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(DrawningElectroTrain):
- _drawningTrain = new DrawningElectroTrain(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;
- }
- _drawningTrain.SetPictureSize(pictureBoxTrain.Width,
- pictureBoxTrain.Height);
- _drawningTrain.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
- ///
- /// Обработка нажатия кнопки "Создать военный крейсер"
- ///
- ///
- ///
- private void ButtonCreateTrain_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningElectroTrain));
-
- ///
- /// Обработка нажатия кнопки "Создать крейсер"
- ///
- ///
- ///
- private void buttonCretaeTrain_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrain));
-
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
@@ -104,16 +72,13 @@ namespace ProjectTrain
switch (name)
{
case "buttonUp":
- result =
- _drawningTrain.MoveTransport(DirectionType.Up);
+ result = _drawningTrain.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- result =
- _drawningTrain.MoveTransport(DirectionType.Down);
+ result = _drawningTrain.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- result =
- _drawningTrain.MoveTransport(DirectionType.Left);
+ result = _drawningTrain.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result =
diff --git a/ProjertTrain/ProjertTrain/FormTrainsCollection.Designer.cs b/ProjertTrain/ProjertTrain/FormTrainsCollection.Designer.cs
new file mode 100644
index 0000000..d1d3194
--- /dev/null
+++ b/ProjertTrain/ProjertTrain/FormTrainsCollection.Designer.cs
@@ -0,0 +1,173 @@
+namespace ProjectTrain
+{
+ partial class FormTrainsCollection
+ {
+ ///
+ /// 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();
+ ButtonRemoveTrain = new Button();
+ ButtonAddElectroTrain = new Button();
+ ButtonAddTrain = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBoxTrain = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxTrain).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(maskedTextBoxPosision);
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGetToTest);
+ groupBoxTools.Controls.Add(ButtonRemoveTrain);
+ groupBoxTools.Controls.Add(ButtonAddElectroTrain);
+ groupBoxTools.Controls.Add(ButtonAddTrain);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(596, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(222, 574);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "инструменты";
+ //
+ // maskedTextBoxPosision
+ //
+ maskedTextBoxPosision.Location = new Point(20, 229);
+ maskedTextBoxPosision.Mask = "00";
+ maskedTextBoxPosision.Name = "maskedTextBoxPosision";
+ maskedTextBoxPosision.Size = new Size(186, 27);
+ maskedTextBoxPosision.TabIndex = 2;
+ maskedTextBoxPosision.ValidatingType = typeof(int);
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(20, 479);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(186, 40);
+ buttonRefresh.TabIndex = 5;
+ buttonRefresh.Text = "обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGetToTest
+ //
+ buttonGetToTest.Anchor = AnchorStyles.Right;
+ buttonGetToTest.Location = new Point(20, 366);
+ buttonGetToTest.Name = "buttonGetToTest";
+ buttonGetToTest.Size = new Size(186, 40);
+ buttonGetToTest.TabIndex = 4;
+ buttonGetToTest.Text = "передать на тесты";
+ buttonGetToTest.UseVisualStyleBackColor = true;
+ buttonGetToTest.Click += ButtonGetToTest_Click;
+ //
+ // ButtonRemoveTrain
+ //
+ ButtonRemoveTrain.Anchor = AnchorStyles.Right;
+ ButtonRemoveTrain.Location = new Point(20, 271);
+ ButtonRemoveTrain.Name = "ButtonRemoveTrain";
+ ButtonRemoveTrain.Size = new Size(186, 40);
+ ButtonRemoveTrain.TabIndex = 3;
+ ButtonRemoveTrain.Text = "удалить крейсер";
+ ButtonRemoveTrain.UseVisualStyleBackColor = true;
+ ButtonRemoveTrain.Click += ButtonRemoveTrain_Click;
+ //
+ // ButtonAddElectroTrain
+ //
+ ButtonAddElectroTrain.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ ButtonAddElectroTrain.Location = new Point(20, 152);
+ ButtonAddElectroTrain.Name = "ButtonAddElectroTrain";
+ ButtonAddElectroTrain.Size = new Size(186, 50);
+ ButtonAddElectroTrain.TabIndex = 2;
+ ButtonAddElectroTrain.Text = "добваление военного крейсера";
+ ButtonAddElectroTrain.UseVisualStyleBackColor = true;
+ ButtonAddElectroTrain.Click += ButtonAddElectroTrain_Click;
+ //
+ // ButtonAddTrain
+ //
+ ButtonAddTrain.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ ButtonAddTrain.BackgroundImageLayout = ImageLayout.Center;
+ ButtonAddTrain.Location = new Point(20, 106);
+ ButtonAddTrain.Name = "ButtonAddTrain";
+ ButtonAddTrain.Size = new Size(186, 40);
+ ButtonAddTrain.TabIndex = 1;
+ ButtonAddTrain.Text = "добваление крейсера";
+ ButtonAddTrain.UseVisualStyleBackColor = true;
+ ButtonAddTrain.Click += ButtonAddTrain_Click;
+ //
+ // comboBoxSelectorCompany
+ //
+ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectorCompany.FormattingEnabled = true;
+ comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" });
+ comboBoxSelectorCompany.Location = new Point(20, 26);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(186, 28);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1;
+ //
+ // pictureBoxTrain
+ //
+ pictureBoxTrain.Dock = DockStyle.Fill;
+ pictureBoxTrain.Location = new Point(0, 0);
+ pictureBoxTrain.Name = "pictureBoxTrain";
+ pictureBoxTrain.Size = new Size(596, 574);
+ pictureBoxTrain.TabIndex = 1;
+ pictureBoxTrain.TabStop = false;
+ //
+ // FormTrainsCollection
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(818, 574);
+ Controls.Add(pictureBoxTrain);
+ Controls.Add(groupBoxTools);
+ Name = "FormTrainsCollection";
+ Text = "FormTrainsCollection";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxTrain).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button ButtonAddElectroTrain;
+ private Button ButtonAddTrain;
+ private Button ButtonRemoveTrain;
+ private Button buttonRefresh;
+ private Button buttonGetToTest;
+ private PictureBox pictureBoxTrain;
+ private MaskedTextBox maskedTextBoxPosision;
+ }
+}
\ No newline at end of file
diff --git a/ProjertTrain/ProjertTrain/FormTrainsCollection.cs b/ProjertTrain/ProjertTrain/FormTrainsCollection.cs
new file mode 100644
index 0000000..a7c9c1d
--- /dev/null
+++ b/ProjertTrain/ProjertTrain/FormTrainsCollection.cs
@@ -0,0 +1,169 @@
+using ProjectTrain.CollectionGenericObjects;
+using ProjectTrain.Drawnings;
+
+namespace ProjectTrain
+{
+ public partial class FormTrainsCollection : Form
+ {
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+ ///
+ /// Конструктор
+ ///
+ public FormTrainsCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "хранилище":
+ _company = new TrainDockingService(pictureBoxTrain.Width,
+ pictureBoxTrain.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ Random random = new();
+ DrawningTrain drawningTrain;
+ switch (type)
+ {
+ case nameof(DrawningTrain):
+ drawningTrain = new DrawningTrain(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningElectroTrain):
+ drawningTrain = new DrawningElectroTrain(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 + drawningTrain != -1)
+ {
+ MessageBox.Show("объект добавлен");
+ pictureBoxTrain.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 ButtonAddTrain_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrain));
+
+ //private void ButtonAddElectroTrain_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningElectroTrain));
+ private void ButtonAddTrain_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningTrain));
+ }
+
+ private void ButtonAddElectroTrain_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningElectroTrain));
+ }
+
+ private void ButtonRemoveTrain_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("объект удален");
+ pictureBoxTrain.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("не удалось удалить объект");
+ }
+ }
+
+ private void ButtonGetToTest_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawningTrain? cruiser = null;
+ int counter = 100;
+ while (cruiser == null)
+ {
+ cruiser = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+ if (cruiser == null)
+ {
+ return;
+ }
+ FormTrain form = new()
+ {
+ SetTrain = cruiser
+ };
+ form.ShowDialog();
+
+ }
+
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBoxTrain.Image = _company.Show();
+ }
+
+
+ }
+}
diff --git a/ProjertTrain/ProjertTrain/FormTrainsCollection.resx b/ProjertTrain/ProjertTrain/FormTrainsCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjertTrain/ProjertTrain/FormTrainsCollection.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/ProjertTrain/ProjertTrain/Program.cs b/ProjertTrain/ProjertTrain/Program.cs
index fe3637a..1a8dd72 100644
--- a/ProjertTrain/ProjertTrain/Program.cs
+++ b/ProjertTrain/ProjertTrain/Program.cs
@@ -3,15 +3,14 @@ namespace ProjectTrain
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 FormTrain());
+ Application.Run(new FormTrainsCollection());
}
}
}
\ No newline at end of file