diff --git a/.idea/.idea.BoykoSolution/.idea/.gitignore b/.idea/.idea.BoykoSolution/.idea/.gitignore
new file mode 100644
index 0000000..e5028a2
--- /dev/null
+++ b/.idea/.idea.BoykoSolution/.idea/.gitignore
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/projectSettingsUpdater.xml
+/.idea.BoykoSolution.iml
+/modules.xml
+/contentModel.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/.idea.BoykoSolution/.idea/.name b/.idea/.idea.BoykoSolution/.idea/.name
new file mode 100644
index 0000000..4264369
--- /dev/null
+++ b/.idea/.idea.BoykoSolution/.idea/.name
@@ -0,0 +1 @@
+BoykoSolution
\ No newline at end of file
diff --git a/.idea/.idea.BoykoSolution/.idea/encodings.xml b/.idea/.idea.BoykoSolution/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/.idea.BoykoSolution/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.BoykoSolution/.idea/indexLayout.xml b/.idea/.idea.BoykoSolution/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/.idea/.idea.BoykoSolution/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.BoykoSolution/.idea/vcs.xml b/.idea/.idea.BoykoSolution/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/.idea.BoykoSolution/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ProjectElectroTrans/CollectionGenericObjects/AbstractCompany.cs b/ProjectElectroTrans/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..68b0455
--- /dev/null
+++ b/ProjectElectroTrans/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,116 @@
+using ProjectElectroTrans.Drawnings;
+
+namespace ProjectElectroTrans.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 80;
+
+ ///
+ /// Ширина окна
+ ///
+ 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, DrawingTrans trans)
+ {
+ return company._collection.Insert(trans);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawingTrans? operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawingTrans? 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)
+ {
+ DrawingTrans? 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/ProjectElectroTrans/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectElectroTrans/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..f22a93e
--- /dev/null
+++ b/ProjectElectroTrans/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,50 @@
+using ProjectElectroTrans.Drawnings;
+
+namespace ProjectElectroTrans.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/ProjectElectroTrans/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectElectroTrans/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..2beb914
--- /dev/null
+++ b/ProjectElectroTrans/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,133 @@
+using System.Runtime.Remoting;
+using ProjectElectroTrans.Drawnings;
+
+namespace ProjectElectroTrans.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 _collection[position];
+ }
+
+ return null;
+ }
+
+ 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 < 0 || position >= Count)
+ {
+ return -1;
+ }
+
+ // проверка, что элемент массива по этой позиции пустой, если нет, то
+ // ищется свободное место после этой позиции и идет вставка туда
+ // если нет после, ищем до
+ if (_collection[position] != null)
+ {
+ bool pushed = false;
+ for (int index = position + 1; index < Count; index++)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+
+ if (!pushed)
+ {
+ for (int index = position - 1; index >= 0; index--)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+ }
+
+ if (!pushed)
+ {
+ return position;
+ }
+ }
+
+ // вставка
+ _collection[position] = obj;
+ return position;
+ }
+
+ public T? Remove(int position)
+ {
+ // проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+
+ if (_collection[position] == null) return null;
+
+ T? temp = _collection[position];
+ _collection[position] = null;
+ return temp;
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/CollectionGenericObjects/TransDepoService.cs b/ProjectElectroTrans/CollectionGenericObjects/TransDepoService.cs
new file mode 100644
index 0000000..48d165d
--- /dev/null
+++ b/ProjectElectroTrans/CollectionGenericObjects/TransDepoService.cs
@@ -0,0 +1,55 @@
+using ProjectElectroTrans.Drawnings;
+using ProjectElectroTrans.Entities;
+using System;
+
+namespace ProjectElectroTrans.CollectionGenericObjects;
+
+///
+/// Реализация абстрактной компании - аренда поезда
+///
+public class TransDepoService : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public TransDepoService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackgound(Graphics g)
+ {
+ Pen pen = new(Color.Black);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for(int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
+ {
+ g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j));
+ g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1)));
+ }
+ g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight)));
+ }
+
+
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ int n = 0;
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
+ {
+ DrawingTrans? drawingTrans = _collection?.Get(n);
+ n++;
+ if (drawingTrans != null)
+ {
+ drawingTrans.SetPictureSize(_pictureWidth, _pictureHeight);
+ drawingTrans.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/Drawnings/DirectionType.cs b/ProjectElectroTrans/Drawnings/DirectionType.cs
index 6e6c370..b360a90 100644
--- a/ProjectElectroTrans/Drawnings/DirectionType.cs
+++ b/ProjectElectroTrans/Drawnings/DirectionType.cs
@@ -1,4 +1,4 @@
-namespace ProjectSportCar.Drawnings;
+namespace ProjectElectroTrans.Drawnings;
///
/// Направление перемещения
diff --git a/ProjectElectroTrans/Drawnings/DrawingTrans.cs b/ProjectElectroTrans/Drawnings/DrawingTrans.cs
index 59270e8..dcbf01f 100644
--- a/ProjectElectroTrans/Drawnings/DrawingTrans.cs
+++ b/ProjectElectroTrans/Drawnings/DrawingTrans.cs
@@ -1,5 +1,4 @@
using ProjectElectroTrans.Entities;
-using ProjectSportCar.Drawnings;
namespace ProjectElectroTrans.Drawnings;
diff --git a/ProjectElectroTrans/FormElectroTrans.Designer.cs b/ProjectElectroTrans/FormElectroTrans.Designer.cs
index c605eaa..baf4722 100644
--- a/ProjectElectroTrans/FormElectroTrans.Designer.cs
+++ b/ProjectElectroTrans/FormElectroTrans.Designer.cs
@@ -7,9 +7,9 @@ namespace ProjectElectroTrans
partial class FormElectroTrans
{
///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
@@ -33,12 +33,10 @@ namespace ProjectElectroTrans
private void InitializeComponent()
{
pictureBoxElectroTrans = new PictureBox();
- buttonCreateElectroTrans = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
- buttonCreateCar = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxElectroTrans).BeginInit();
@@ -53,17 +51,6 @@ namespace ProjectElectroTrans
pictureBoxElectroTrans.TabIndex = 0;
pictureBoxElectroTrans.TabStop = false;
//
- // buttonCreateElectroTrans
- //
- buttonCreateElectroTrans.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateElectroTrans.Location = new Point(12, 562);
- buttonCreateElectroTrans.Name = "buttonCreateElectroTrans";
- buttonCreateElectroTrans.Size = new Size(223, 23);
- buttonCreateElectroTrans.TabIndex = 1;
- buttonCreateElectroTrans.Text = "Создать электропоезд";
- buttonCreateElectroTrans.UseVisualStyleBackColor = true;
- buttonCreateElectroTrans.Click += ButtonCreateElectroTrans_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -112,17 +99,6 @@ namespace ProjectElectroTrans
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
- // buttonCreateCar
- //
- buttonCreateCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateCar.Location = new Point(250, 562);
- buttonCreateCar.Name = "buttonCreateTrans";
- buttonCreateCar.Size = new Size(223, 23);
- buttonCreateCar.TabIndex = 6;
- buttonCreateCar.Text = "Создать поезд";
- buttonCreateCar.UseVisualStyleBackColor = true;
- buttonCreateCar.Click += ButtonCreateTrans_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -143,22 +119,20 @@ namespace ProjectElectroTrans
buttonStrategyStep.UseVisualStyleBackColor = true;
buttonStrategyStep.Click += ButtonStrategyStep_Click;
//
- // FormElectroTrans
+ // FormSportCar
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(923, 597);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateCar);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateElectroTrans);
Controls.Add(pictureBoxElectroTrans);
Name = "FormElectroTrans";
- Text = "Электропоезд";
+ Text = "Электровоз";
((System.ComponentModel.ISupportInitialize)pictureBoxElectroTrans).EndInit();
ResumeLayout(false);
}
@@ -166,13 +140,11 @@ namespace ProjectElectroTrans
#endregion
private PictureBox pictureBoxElectroTrans;
- private Button buttonCreateElectroTrans;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
- private Button buttonCreateCar;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
-}
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/FormElectroTrans.cs b/ProjectElectroTrans/FormElectroTrans.cs
index 0b486b8..9d321ce 100644
--- a/ProjectElectroTrans/FormElectroTrans.cs
+++ b/ProjectElectroTrans/FormElectroTrans.cs
@@ -1,22 +1,41 @@
-using ProjectElectroTrans.Drawnings;
using ProjectElectroTrans.MovementStrategy;
-using ProjectSportCar.Drawnings;
-using ProjectSportCar.MovementStrategy;
+using ProjectElectroTrans.Drawnings;
namespace ProjectElectroTrans;
+///
+/// ""
+///
public partial class FormElectroTrans : Form
{
///
/// -
///
- private DrawingTrans? _drawingTrans;
+ private DrawingTrans? _drawningTrans;
///
///
///
private AbstractStrategy? _strategy;
+ ///
+ ///
+ ///
+ public DrawingTrans SetCar
+ {
+ set
+ {
+ _drawningTrans = value;
+ _drawningTrans.SetPictureSize(pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
+ ///
+ ///
+ ///
public FormElectroTrans()
{
InitializeComponent();
@@ -28,62 +47,25 @@ public partial class FormElectroTrans : Form
///
private void Draw()
{
- if (_drawingTrans == null)
+ if (_drawningTrans == null)
{
return;
}
Bitmap bmp = new(pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawingTrans.DrawTransport(gr);
+ _drawningTrans.DrawTransport(gr);
pictureBoxElectroTrans.Image = bmp;
}
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawingTrans):
- _drawingTrans = new DrawingTrans(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(DrawingElectroTrans):
- _drawingTrans = new DrawingElectroTrans(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;
- }
- _drawingTrans.SetPictureSize(pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
- _drawingTrans.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
///
- /// " "
+ /// ( )
///
///
///
- private void ButtonCreateElectroTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingElectroTrans));
-
- ///
- /// " "
- ///
- ///
- ///
- private void ButtonCreateTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingTrans));
- ///
- /// ( )
- ///
- ///
- ///
- private void ButtonMove_Click(object sender, EventArgs e)
+ private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_drawingTrans == null)
+ if (_drawningTrans == null)
{
return;
}
@@ -93,16 +75,16 @@ public partial class FormElectroTrans : Form
switch (name)
{
case "buttonUp":
- result = _drawingTrans.MoveTransport(DirectionType.Up);
+ result = _drawningTrans.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- result = _drawingTrans.MoveTransport(DirectionType.Down);
+ result = _drawningTrans.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- result = _drawingTrans.MoveTransport(DirectionType.Left);
+ result = _drawningTrans.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
- result = _drawingTrans.MoveTransport(DirectionType.Right);
+ result = _drawningTrans.MoveTransport(DirectionType.Right);
break;
}
@@ -111,14 +93,15 @@ public partial class FormElectroTrans : Form
Draw();
}
}
+
///
- /// ""
- ///
- ///
- ///
- private void ButtonStrategyStep_Click(object sender, EventArgs e)
+ /// ""
+ ///
+ ///
+ ///
+ private void ButtonStrategyStep_Click(object sender, EventArgs e)
{
- if (_drawingTrans == null)
+ if (_drawningTrans == null)
{
return;
}
@@ -135,7 +118,7 @@ public partial class FormElectroTrans : Form
{
return;
}
- _strategy.SetData(new MoveableTrans(_drawingTrans), pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
+ _strategy.SetData(new MoveableTrans(_drawningTrans), pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
}
if (_strategy == null)
@@ -153,4 +136,4 @@ public partial class FormElectroTrans : Form
_strategy = null;
}
}
-}
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/FormTransCollection.Designer.cs b/ProjectElectroTrans/FormTransCollection.Designer.cs
new file mode 100644
index 0000000..d1adee7
--- /dev/null
+++ b/ProjectElectroTrans/FormTransCollection.Designer.cs
@@ -0,0 +1,177 @@
+using static System.Net.Mime.MediaTypeNames;
+using System.Windows.Forms;
+using System.Xml.Linq;
+
+namespace ProjectElectroTrans
+{
+ partial class FormTransCollection
+ {
+ ///
+ /// 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();
+ buttonRemoveCar = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddSportCar = new Button();
+ buttonAddCar = 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(buttonRemoveCar);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddSportCar);
+ groupBoxTools.Controls.Add(buttonAddCar);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(783, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(179, 616);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(6, 499);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(167, 40);
+ 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(6, 361);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(167, 40);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveCar
+ //
+ buttonRemoveCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveCar.Location = new Point(6, 251);
+ buttonRemoveCar.Name = "buttonRemoveTrans";
+ buttonRemoveCar.Size = new Size(167, 40);
+ buttonRemoveCar.TabIndex = 4;
+ buttonRemoveCar.Text = "Удалить поезд";
+ buttonRemoveCar.UseVisualStyleBackColor = true;
+ buttonRemoveCar.Click += ButtonRemoveTrans_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(6, 222);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(167, 23);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddSportCar
+ //
+ buttonAddSportCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddSportCar.Location = new Point(6, 137);
+ buttonAddSportCar.Name = "buttonAddSportCar";
+ buttonAddSportCar.Size = new Size(167, 40);
+ buttonAddSportCar.TabIndex = 2;
+ buttonAddSportCar.Text = "Добавление электропоезда";
+ buttonAddSportCar.UseVisualStyleBackColor = true;
+ buttonAddSportCar.Click += ButtonAddElectroTrans_Click;
+ //
+ // buttonAddCar
+ //
+ buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddCar.Location = new Point(6, 91);
+ buttonAddCar.Name = "buttonAddCar";
+ buttonAddCar.Size = new Size(167, 40);
+ buttonAddCar.TabIndex = 1;
+ buttonAddCar.Text = "Добавление поезда";
+ buttonAddCar.UseVisualStyleBackColor = true;
+ buttonAddCar.Click += ButtonAddTrans_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(167, 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(783, 616);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormCarCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(962, 616);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormCarCollection";
+ Text = "Коллекция автомобилей";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddSportCar;
+ private Button buttonAddCar;
+ private Button buttonRemoveCar;
+ private MaskedTextBox maskedTextBoxPosition;
+ private PictureBox pictureBox;
+ private Button buttonGoToCheck;
+ private Button buttonRefresh;
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/FormTransCollection.cs b/ProjectElectroTrans/FormTransCollection.cs
new file mode 100644
index 0000000..e700e38
--- /dev/null
+++ b/ProjectElectroTrans/FormTransCollection.cs
@@ -0,0 +1,190 @@
+using ProjectElectroTrans.CollectionGenericObjects;
+using ProjectElectroTrans.Drawnings;
+using System.Windows.Forms;
+
+namespace ProjectElectroTrans;
+
+///
+/// Форма работы с компанией и ее коллекцией
+///
+public partial class FormTransCollection : Form
+{
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormTransCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new TransDepoService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Добавление обычного автомобиля
+ ///
+ ///
+ ///
+ private void ButtonAddTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingTrans));
+
+ ///
+ /// Добавление спортивного автомобиля
+ ///
+ ///
+ ///
+ private void ButtonAddElectroTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingElectroTrans));
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ Random random = new();
+ DrawingTrans drawingTrans;
+ switch (type)
+ {
+ case nameof(DrawingTrans):
+ drawingTrans = new DrawingTrans(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawingElectroTrans):
+ // вызов диалогового окна для выбора цвета
+ drawingTrans = new DrawingElectroTrans(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 + drawingTrans != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ _ = MessageBox.Show(drawingTrans.ToString());
+ }
+ }
+
+ ///
+ /// Получение цвета
+ ///
+ /// Генератор случайных чисел
+ ///
+ 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 ButtonRemoveTrans_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;
+ }
+
+ DrawingTrans? car = null;
+ int counter = 100;
+ while (car == null)
+ {
+ car = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (car == null)
+ {
+ return;
+ }
+
+ FormElectroTrans form = new()
+ {
+ SetCar = car
+ };
+ 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/ProjectElectroTrans/FormTransCollection.resx b/ProjectElectroTrans/FormTransCollection.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/ProjectElectroTrans/FormTransCollection.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/ProjectElectroTrans/MovementStrategy/MoveToBorder.cs b/ProjectElectroTrans/MovementStrategy/MoveToBorder.cs
index f4581b7..a1389e1 100644
--- a/ProjectElectroTrans/MovementStrategy/MoveToBorder.cs
+++ b/ProjectElectroTrans/MovementStrategy/MoveToBorder.cs
@@ -1,6 +1,4 @@
-using ProjectElectroTrans.MovementStrategy;
-
-namespace ProjectSportCar.MovementStrategy;
+namespace ProjectElectroTrans.MovementStrategy;
public class MoveToBorder : AbstractStrategy
{
diff --git a/ProjectElectroTrans/MovementStrategy/MoveableTrans.cs b/ProjectElectroTrans/MovementStrategy/MoveableTrans.cs
index 965fda9..788b454 100644
--- a/ProjectElectroTrans/MovementStrategy/MoveableTrans.cs
+++ b/ProjectElectroTrans/MovementStrategy/MoveableTrans.cs
@@ -1,5 +1,4 @@
using ProjectElectroTrans.Drawnings;
-using ProjectSportCar.Drawnings;
namespace ProjectElectroTrans.MovementStrategy;
diff --git a/ProjectElectroTrans/Program.cs b/ProjectElectroTrans/Program.cs
index d25ed3f..c78bbd9 100644
--- a/ProjectElectroTrans/Program.cs
+++ b/ProjectElectroTrans/Program.cs
@@ -1,9 +1,11 @@
+using System.Drawing;
+
namespace ProjectElectroTrans
{
internal static class Program
{
///
- /// The main entry point for the application.
+ /// The main entry point for the application.
///
[STAThread]
static void Main()
@@ -11,7 +13,8 @@ namespace ProjectElectroTrans
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormElectroTrans());
+ Application.Run(new FormTransCollection());
}
}
+
}
\ No newline at end of file