diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..0549301
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,119 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectGasolineTanker.Drawings;
+
+
+namespace ProjectGasolineTanker.CollectionGenericObjects;
+
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 110;
+
+ ///
+ /// Ширина окна
+ ///
+ protected readonly int _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ protected readonly int _pictureHeight;
+
+ ///
+ /// Коллекция грузовиков
+ ///
+ protected ICollectionGenericObjects? _collection = null;
+
+ ///
+ /// Вычисление максимального количества элементов, который можно разместить в окне
+ ///
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+
+ ///
+ /// Конструктор
+ ///
+ /// Ширина окна
+ /// Высота окна
+ /// Коллекция грузовиков
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ {
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = collection;
+ _collection.SetMaxCount = GetMaxCount;
+ }
+
+ ///
+ /// Перегрузка оператора сложения для класса
+ ///
+ /// Компания
+ /// Добавляемый объект
+ ///
+ public static int operator +(AbstractCompany company, DrawingTanker tanker)
+ {
+ return company._collection.Insert(tanker);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawingTanker operator -(AbstractCompany company, int position)
+ {
+ return company._collection.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawingTanker? 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)
+ {
+ DrawingTanker? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..1c71a8c
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectGasolineTanker.CollectionGenericObjects;
+
+///
+/// Интерфейс описания действий для набора хранимых объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public interface ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj);
+
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// 1 - вставка прошла удачно, -1 - вставка не удалась
+ int Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ ///
+ T? Remove(int position);
+
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..bf37cd7
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,115 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectGasolineTanker.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 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)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+
+ int temp = position + 1;
+ while (temp < Count)
+ {
+ if (_collection[temp] == null)
+ {
+ _collection[temp] = obj;
+ return temp;
+ }
+ temp++;
+ }
+
+ temp = position - 1;
+ while (temp > 0)
+ {
+ if (_collection[temp] == null)
+ {
+ _collection[temp] = obj;
+ return temp;
+ }
+ temp--;
+ }
+
+ return -1;
+ }
+
+ 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;
+ }
+}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerSharingService.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerSharingService.cs
new file mode 100644
index 0000000..c387201
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerSharingService.cs
@@ -0,0 +1,60 @@
+using ProjectGasolineTanker.Drawings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectGasolineTanker.CollectionGenericObjects;
+
+public class TankerSharingService : AbstractCompany
+{
+ public TankerSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackgound(Graphics g)
+ {
+ Pen pen = new(Color.Black, 4);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight,
+ i * _placeSizeWidth + _placeSizeWidth - 40, j * _placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ int curWidth = 0;
+ int curHeight = height - 1;
+
+ for (int i = 0; i < (_collection?.Count ?? 0); i++)
+ {
+ if (_collection.Get(i) != null)
+ {
+ _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 5);
+ }
+
+ if (curWidth < width - 1)
+ curWidth++;
+ else
+ {
+ curWidth = 0;
+ curHeight--;
+ }
+ if (curHeight < 0)
+ {
+ return;
+ }
+ }
+ }
+}
+
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs
index 2e74d11..fedcea3 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxGasolineTanker = new PictureBox();
- buttonCreateGasolineTanker = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
- buttonCreateTanker = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxGasolineTanker).BeginInit();
@@ -49,17 +47,6 @@
pictureBoxGasolineTanker.TabIndex = 0;
pictureBoxGasolineTanker.TabStop = false;
//
- // buttonCreateGasolineTanker
- //
- buttonCreateGasolineTanker.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateGasolineTanker.Location = new Point(12, 682);
- buttonCreateGasolineTanker.Name = "buttonCreateGasolineTanker";
- buttonCreateGasolineTanker.Size = new Size(230, 34);
- buttonCreateGasolineTanker.TabIndex = 1;
- buttonCreateGasolineTanker.Text = "Создать Бензовоз";
- buttonCreateGasolineTanker.UseVisualStyleBackColor = true;
- buttonCreateGasolineTanker.Click += buttonCreateGasolineTanker_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -108,17 +95,6 @@
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
- // buttonCreateTanker
- //
- buttonCreateTanker.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateTanker.Location = new Point(248, 682);
- buttonCreateTanker.Name = "buttonCreateTanker";
- buttonCreateTanker.Size = new Size(230, 34);
- buttonCreateTanker.TabIndex = 6;
- buttonCreateTanker.Text = "Создать Грузовик";
- buttonCreateTanker.UseVisualStyleBackColor = true;
- buttonCreateTanker.Click += buttonCreateTanker_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -146,12 +122,10 @@
ClientSize = new Size(1312, 749);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateTanker);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateGasolineTanker);
Controls.Add(pictureBoxGasolineTanker);
Name = "FormGasolineTanker";
Text = "Бензовоз";
@@ -162,12 +136,10 @@
#endregion
private PictureBox pictureBoxGasolineTanker;
- private Button buttonCreateGasolineTanker;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
- private Button buttonCreateTanker;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs
index ba4eed7..c48ea75 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs
@@ -24,6 +24,18 @@ namespace ProjectGasolineTanker
///
private AbstractStrategy? _strategy;
+ public DrawingTanker SetTanker
+ {
+ set
+ {
+ _drawingTanker = value;
+ _drawingTanker.SetPictureSize(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
///
/// Конструктор формы
///
@@ -46,49 +58,6 @@ namespace ProjectGasolineTanker
pictureBoxGasolineTanker.Image = bmp;
}
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawingTanker):
- _drawingTanker = new DrawingTanker(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(DrawingGasolineTanker):
- _drawingTanker = new DrawingGasolineTanker(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;
- }
- _drawingTanker.SetPictureSize(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
- _drawingTanker.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
-
-
-
- ///
- /// Обработка нажатия кнопки создать
- ///
- ///
- ///
- private void buttonCreateGasolineTanker_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawingGasolineTanker));
- }
-
- private void buttonCreateTanker_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawingTanker));
- }
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs
new file mode 100644
index 0000000..f67f5a7
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs
@@ -0,0 +1,173 @@
+namespace ProjectGasolineTanker
+{
+ partial class FormTankerCollection
+ {
+ ///
+ /// 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();
+ buttonDelTanker = new Button();
+ maskedTextBox1 = new MaskedTextBox();
+ buttonAddGasolineTanker = new Button();
+ buttonAddTanker = 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(buttonDelTanker);
+ groupBoxTools.Controls.Add(maskedTextBox1);
+ groupBoxTools.Controls.Add(buttonAddGasolineTanker);
+ groupBoxTools.Controls.Add(buttonAddTanker);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(1095, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(254, 681);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(16, 522);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(226, 55);
+ 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(16, 426);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(226, 55);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += buttonGoToCheck_Click;
+ //
+ // buttonDelTanker
+ //
+ buttonDelTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonDelTanker.Location = new Point(16, 325);
+ buttonDelTanker.Name = "buttonDelTanker";
+ buttonDelTanker.Size = new Size(226, 55);
+ buttonDelTanker.TabIndex = 4;
+ buttonDelTanker.Text = "Удаление грузовика";
+ buttonDelTanker.UseVisualStyleBackColor = true;
+ buttonDelTanker.Click += buttonDelTanker_Click_1;
+ //
+ // maskedTextBox1
+ //
+ maskedTextBox1.Location = new Point(16, 262);
+ maskedTextBox1.Mask = "00";
+ maskedTextBox1.Name = "maskedTextBox1";
+ maskedTextBox1.Size = new Size(150, 31);
+ maskedTextBox1.TabIndex = 3;
+ maskedTextBox1.ValidatingType = typeof(int);
+ //
+ // buttonAddGasolineTanker
+ //
+ buttonAddGasolineTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddGasolineTanker.Location = new Point(16, 179);
+ buttonAddGasolineTanker.Name = "buttonAddGasolineTanker";
+ buttonAddGasolineTanker.Size = new Size(226, 55);
+ buttonAddGasolineTanker.TabIndex = 2;
+ buttonAddGasolineTanker.Text = "Добавление Бензовоза";
+ buttonAddGasolineTanker.UseVisualStyleBackColor = true;
+ buttonAddGasolineTanker.Click += buttonAddGasolineTanker_Click_1;
+ //
+ // buttonAddTanker
+ //
+ buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTanker.Location = new Point(16, 118);
+ buttonAddTanker.Name = "buttonAddTanker";
+ buttonAddTanker.Size = new Size(226, 55);
+ buttonAddTanker.TabIndex = 1;
+ buttonAddTanker.Text = "Добавление грузовика";
+ buttonAddTanker.UseVisualStyleBackColor = true;
+ buttonAddTanker.Click += buttonAddTanker_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(16, 30);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(226, 33);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1;
+ //
+ // pictureBox
+ //
+ pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Location = new Point(0, 0);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(1095, 681);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormTankerCollection
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1349, 681);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormTankerCollection";
+ Text = "Коллекция Грузовиков";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddGasolineTanker;
+ private Button buttonAddTanker;
+ private MaskedTextBox maskedTextBox1;
+ private PictureBox pictureBox;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ private Button buttonDelTanker;
+ }
+}
\ No newline at end of file
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs
new file mode 100644
index 0000000..710059a
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs
@@ -0,0 +1,194 @@
+using ProjectGasolineTanker.CollectionGenericObjects;
+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;
+using ProjectGasolineTanker.Drawings;
+
+namespace ProjectGasolineTanker;
+
+public partial class FormTankerCollection : Form
+{
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormTankerCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new TankerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ Random random = new();
+ DrawingTanker drawingTanker;
+ switch (type)
+ {
+ case nameof(DrawingTanker):
+ drawingTanker = new DrawingTanker(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawingGasolineTanker):
+ drawingTanker = new DrawingGasolineTanker(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random),
+ GetColor(random),
+ Convert.ToBoolean(random.Next(1, 1)), Convert.ToBoolean(random.Next(1, 1)));
+
+ break;
+ default:
+ return;
+
+ }
+ if (_company + drawingTanker != -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 buttonAddTanker_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingTanker));
+
+ ///
+ /// Добавление самолета с радаром
+ ///
+ ///
+ ///
+ private void buttonAddGasolineTanker_Click_1(object sender, EventArgs e) => CreateObject(nameof(DrawingGasolineTanker));
+
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void buttonDelTanker_Click_1(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+
+ int pos = Convert.ToInt32(maskedTextBox1.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;
+ }
+
+ DrawingTanker? tanker = null;
+ int counter = 100;
+ while (tanker == null)
+ {
+ tanker = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (tanker == null)
+ {
+ return;
+ }
+
+ FormGasolineTanker form = new()
+ {
+ SetTanker = tanker
+ };
+ form.ShowDialog();
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void buttonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+ }
+}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.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/ProjectGasolineTanker/ProjectGasolineTanker/Program.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Program.cs
index 12d41fa..913060e 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/Program.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectGasolineTanker
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormGasolineTanker());
+ Application.Run(new FormTankerCollection());
}
}
}
\ No newline at end of file