diff --git a/ProjectDumpTruck/ProjectDumpTruck.sln b/ProjectDumpTruck/ProjectDumpTruck.sln
index c4a0661..a6f6c18 100644
--- a/ProjectDumpTruck/ProjectDumpTruck.sln
+++ b/ProjectDumpTruck/ProjectDumpTruck.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectDumpTruck", "ProjectDumpTruck\ProjectDumpTruck.csproj", "{0045C558-05F7-4B43-8DE8-C584B0F61ED9}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectDumpTruck", "ProjectDumpTruck\ProjectDumpTruck.csproj", "{0045C558-05F7-4B43-8DE8-C584B0F61ED9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..1035242
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,112 @@
+using ProjectDumpTruck.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectDumpTruck.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 120;
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 120;
+ ///
+ /// Ширина окна
+ ///
+ 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, DrawningTruck truck)
+ {
+ return company._collection.Insert(truck);
+
+ }
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningTruck operator -(AbstractCompany company, int position)
+ {
+ return company._collection.Remove(position);
+
+ }
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningTruck? 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)
+ {
+ DrawningTruck? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..3538adf
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectDumpTruck.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/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..ae7f672
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,104 @@
+using ProjectDumpTruck.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectDumpTruck.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 && _collection[position] != null)
+ return _collection[position];
+ return null;
+ }
+ public int Insert(T obj)
+ {
+ for (int i = 0; i < _collection.Length; ++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;
+ }
+ for (int i = position + 1; i < _collection.Length; ++i)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return position;
+ }
+ }
+ for (int i = 0; i < position; ++i)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return position;
+ }
+ }
+ return -1;
+ }
+ public T Remove(int position)
+ {
+ if (position >= 0 && position < Count)
+ {
+ T remove = _collection[position];
+ _collection[position]= null;
+ return remove;
+ }
+ return null;
+ }
+}
+
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/TruckSharingService.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/TruckSharingService.cs
new file mode 100644
index 0000000..1bec61c
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/TruckSharingService.cs
@@ -0,0 +1,85 @@
+using ProjectDumpTruck.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectDumpTruck.CollectionGenericObjects;
+
+///
+/// Реализация абстрактной компании - тракшеринг
+///
+public class TruckSharingService : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public TruckSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ private int start_width = 10, start_height = 20;
+ private int width_between = 60;
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected override void DrawBackgound(Graphics g)
+ {
+ Pen pen = new(Color.Black, 5);
+ int height = 5, width = 5;
+
+ int maxWidth = _pictureWidth / (_placeSizeWidth + width_between);
+ int maxHeight = _pictureHeight / _placeSizeHeight;
+
+ for (int i = 0; i < maxWidth; i++)
+ {
+ height = 10;
+ for (int j = 0; j < maxHeight; j++)
+ {
+ g.DrawLine(pen, width, height, width + _placeSizeWidth, height);
+ g.DrawLine(pen, width, height, width, height + _placeSizeHeight);
+ height += _placeSizeHeight;
+ }
+ g.DrawLine(pen, width, height, width + _placeSizeWidth, height);
+ width = width + _placeSizeWidth + width_between;
+ }
+ }
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected override void SetObjectsPosition()
+ {
+ int maxWidth = _pictureWidth / (_placeSizeWidth + width_between);
+ int maxHeight = _pictureHeight / _placeSizeHeight;
+ int i_collection = 0;
+ int x_pos = start_width, y_pos = start_height;
+
+
+ if (_collection != null) {
+ for (int j = 0; j < maxHeight; j++)
+ {
+ x_pos = start_width;
+ for (int i = 0; i < maxWidth; i++)
+ {
+ if (_collection.Get(i_collection) != null)
+ {
+ _collection.Get(i_collection).SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i_collection).SetPosition(x_pos, y_pos);
+ x_pos += _placeSizeWidth + width_between;
+ i_collection++;
+ }
+ }
+ y_pos = y_pos + _placeSizeHeight;
+ }
+ }
+ }
+}
+
+
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.Designer.cs
index ebe2b0c..7370768 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.Designer.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxDumpTruck = new PictureBox();
- buttonCreateDumpTruck = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
- buttonCreateTruck = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).BeginInit();
@@ -49,17 +47,6 @@
pictureBoxDumpTruck.TabIndex = 0;
pictureBoxDumpTruck.TabStop = false;
//
- // buttonCreateDumpTruck
- //
- buttonCreateDumpTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateDumpTruck.Location = new Point(14, 505);
- buttonCreateDumpTruck.Name = "buttonCreateDumpTruck";
- buttonCreateDumpTruck.Size = new Size(237, 29);
- buttonCreateDumpTruck.TabIndex = 1;
- buttonCreateDumpTruck.Text = "Создать самосвал";
- buttonCreateDumpTruck.UseVisualStyleBackColor = true;
- buttonCreateDumpTruck.Click += ButtonCreateDumpTruck_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -108,17 +95,6 @@
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
- // buttonCreateTruck
- //
- buttonCreateTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateTruck.Location = new Point(269, 504);
- buttonCreateTruck.Name = "buttonCreateTruck";
- buttonCreateTruck.Size = new Size(237, 29);
- buttonCreateTruck.TabIndex = 6;
- buttonCreateTruck.Text = "Создать грузовик";
- buttonCreateTruck.UseVisualStyleBackColor = true;
- buttonCreateTruck.Click += ButtonCreateTruck_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -128,7 +104,6 @@
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 7;
- //comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
//
// buttonStrategyStep
//
@@ -147,12 +122,10 @@
ClientSize = new Size(894, 545);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateTruck);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateDumpTruck);
Controls.Add(pictureBoxDumpTruck);
Name = "FormDumpTruck";
Text = "Самосвал";
@@ -160,17 +133,15 @@
ResumeLayout(false);
}
-
+
#endregion
private PictureBox pictureBoxDumpTruck;
- private Button buttonCreateDumpTruck;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
- private Button buttonCreateTruck;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.cs
index 3ec4f85..e1d4331 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.cs
@@ -10,159 +10,132 @@ using System.Windows.Forms;
using ProjectDumpTruck.Drawnings;
using ProjectDumpTruck.MovementStrategy;
-namespace ProjectDumpTruck
+namespace ProjectDumpTruck;
+
+public partial class FormDumpTruck : Form
{
- public partial class FormDumpTruck : Form
+ ///
+ /// Поле
+ /// объект для прорисовки объекта
+ ///
+ private DrawningTruck? _drawningTruck;
+ ///
+ /// Стратегия перемещения
+ ///
+ private AbstractStrategy? _strategy;
+
+ ///
+ /// Получение объекта
+ ///
+ public DrawningTruck SetTruck
{
- ///
- /// Поле-объект для прорисовки объекта
- ///
- private DrawningTruck? _drawningTruck;
- ///
- /// Стратегия перемещения
- ///
- private AbstractStrategy? _strategy;
- ///
- /// Конструктор формы
- ///
- public FormDumpTruck()
+ set
{
- InitializeComponent();
- _strategy = null;
- }
- ///
- /// Метод прорисовки машины
- ///
- private void Draw()
- {
- if (_drawningTruck == null)
- {
- return;
- }
-
- Bitmap bmp = new(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
- Graphics gr = Graphics.FromImage(bmp);
- _drawningTruck.DrawTransport(gr);
- pictureBoxDumpTruck.Image = bmp;
- }
-
- ///
- /// Сосздание объекста класса-перемещения
- ///
- ///
- private void CreateObject(string type)
- {
- Random random = new Random();
- switch (type)
- {
- case nameof(DrawningTruck):
- _drawningTruck = new DrawningTruck(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(DrawningDumpTruck):
- _drawningTruck = new DrawningDumpTruck(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;
- }
-
+ _drawningTruck = value;
_drawningTruck.SetPictureSize(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
- _drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
comboBoxStrategy.Enabled = true;
-
+ _strategy = null;
Draw();
}
+ }
- ///
- /// Обработка нажатия кнопки "Создать самосвал"
- ///
- ///
- ///
- private void ButtonCreateDumpTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTruck));
-
- ///
- /// Обработка нажатия кнопки "Создать грузовик"
- ///
- ///
- ///
- private void ButtonCreateTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck));
- ///
- /// Перемещение объекта по форме (нажатие кнопок навигации)
- ///
- ///
- ///
- private void ButtonMove_Click(object sender, EventArgs e)
+ ///
+ /// Конструктор формы
+ ///
+ public FormDumpTruck()
+ {
+ InitializeComponent();
+ _strategy = null;
+ }
+ ///
+ /// Метод прорисовки машины
+ ///
+ private void Draw()
+ {
+ if (_drawningTruck == null)
{
- if (_drawningTruck == null)
- {
- return;
- }
- string name = ((Button)sender)?.Name ?? string.Empty;
- bool result = false;
- switch (name)
- {
- case "buttonUp":
- result =
- _drawningTruck.MoveTransport(DirectionType.Up);
- break;
- case "buttonDown":
- result =
- _drawningTruck.MoveTransport(DirectionType.Down);
- break;
- case "buttonLeft":
- result =
- _drawningTruck.MoveTransport(DirectionType.Left);
- break;
- case "buttonRight":
- result =
- _drawningTruck.MoveTransport(DirectionType.Right);
- break;
- }
- if (result)
- {
- Draw();
- }
+ return;
}
- private void ВuttonStrategyStep_Click(object sender, EventArgs e)
+ Bitmap bmp = new(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningTruck.DrawTransport(gr);
+ pictureBoxDumpTruck.Image = bmp;
+ }
+
+
+ ///
+ /// Перемещение объекта по форме (нажатие кнопок навигации)
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_drawningTruck == null)
{
- if (_drawningTruck == null)
+ return;
+ }
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ bool result = false;
+ switch (name)
+ {
+ case "buttonUp":
+ result =
+ _drawningTruck.MoveTransport(DirectionType.Up);
+ break;
+ case "buttonDown":
+ result =
+ _drawningTruck.MoveTransport(DirectionType.Down);
+ break;
+ case "buttonLeft":
+ result =
+ _drawningTruck.MoveTransport(DirectionType.Left);
+ break;
+ case "buttonRight":
+ result =
+ _drawningTruck.MoveTransport(DirectionType.Right);
+ break;
+ }
+ if (result)
+ {
+ Draw();
+ }
+ }
+
+ private void ВuttonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningTruck == null)
+ {
+ return;
+ }
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
{
- return;
- }
- if (comboBoxStrategy.Enabled)
- {
- _strategy = comboBoxStrategy.SelectedIndex switch
- {
- 0 => new MoveToCenter(),
- 1 => new MoveToBorder(),
- _ => null,
- };
- if (_strategy == null)
- {
- return;
- }
- _strategy.SetData(new MoveableTruck(_drawningTruck), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
- }
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
if (_strategy == null)
{
return;
}
- comboBoxStrategy.Enabled = false;
- _strategy.MakeStep();
- Draw();
- if (_strategy.GetStatus() == StrategyStatus.Finish)
- {
- comboBoxStrategy.Enabled = true;
- _strategy = null;
- }
+ _strategy.SetData(new MoveableTruck(_drawningTruck), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
+ }
+ if (_strategy == null)
+ {
+ return;
+ }
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
}
-
}
+
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs
new file mode 100644
index 0000000..b9648e0
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs
@@ -0,0 +1,169 @@
+namespace ProjectDumpTruck
+{
+ partial class FormTruckCollection
+ {
+ ///
+ /// 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();
+ buttonGoToChek = new Button();
+ buttonRemoveTruck = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddDumpTruck = new Button();
+ buttonAddTruck = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGoToChek);
+ groupBoxTools.Controls.Add(buttonRemoveTruck);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddDumpTruck);
+ groupBoxTools.Controls.Add(buttonAddTruck);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(832, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(250, 753);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(18, 507);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(220, 57);
+ buttonRefresh.TabIndex = 7;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToChek
+ //
+ buttonGoToChek.Location = new Point(18, 406);
+ buttonGoToChek.Name = "buttonGoToChek";
+ buttonGoToChek.Size = new Size(220, 57);
+ buttonGoToChek.TabIndex = 6;
+ buttonGoToChek.Text = "Передать на тесты";
+ buttonGoToChek.UseVisualStyleBackColor = true;
+ buttonGoToChek.Click += ButtonGoToChek_Click;
+ //
+ // buttonRemoveTruck
+ //
+ buttonRemoveTruck.Location = new Point(18, 309);
+ buttonRemoveTruck.Name = "buttonRemoveTruck";
+ buttonRemoveTruck.Size = new Size(220, 57);
+ buttonRemoveTruck.TabIndex = 5;
+ buttonRemoveTruck.Text = "Удаление грузовика";
+ buttonRemoveTruck.UseVisualStyleBackColor = true;
+ buttonRemoveTruck.Click += ButtonRemoveTruck_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(18, 276);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(226, 27);
+ maskedTextBoxPosition.TabIndex = 4;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddDumpTruck
+ //
+ buttonAddDumpTruck.Location = new Point(18, 173);
+ buttonAddDumpTruck.Name = "buttonAddDumpTruck";
+ buttonAddDumpTruck.Size = new Size(220, 57);
+ buttonAddDumpTruck.TabIndex = 2;
+ buttonAddDumpTruck.Text = "Добавление самосвала";
+ buttonAddDumpTruck.UseVisualStyleBackColor = true;
+ buttonAddDumpTruck.Click += ButtonAddDumpTruck_Click;
+ //
+ // buttonAddTruck
+ //
+ buttonAddTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTruck.Location = new Point(18, 110);
+ buttonAddTruck.Name = "buttonAddTruck";
+ buttonAddTruck.Size = new Size(220, 57);
+ buttonAddTruck.TabIndex = 1;
+ buttonAddTruck.Text = "Добавление грузовика";
+ buttonAddTruck.UseVisualStyleBackColor = true;
+ buttonAddTruck.Click += ButtonAddTruck_Click;
+ //
+ // comboBoxSelectorCompany
+ //
+ comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectorCompany.FormattingEnabled = true;
+ comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
+ comboBoxSelectorCompany.Location = new Point(18, 26);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(220, 28);
+ 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(832, 753);
+ pictureBox.TabIndex = 3;
+ pictureBox.TabStop = false;
+ //
+ // FormTruckCollection
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1082, 753);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormTruckCollection";
+ Text = "Коллекция грузовиков";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private Button buttonAddDumpTruck;
+ private Button buttonAddTruck;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonRemoveTruck;
+ private MaskedTextBox maskedTextBoxPosition;
+ private PictureBox pictureBox;
+ private Button buttonRefresh;
+ private Button buttonGoToChek;
+ }
+}
\ No newline at end of file
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs
new file mode 100644
index 0000000..cbe8b57
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs
@@ -0,0 +1,185 @@
+using ProjectDumpTruck.CollectionGenericObjects;
+using ProjectDumpTruck.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 ProjectDumpTruck;
+
+public partial class FormTruckCollection : Form
+{
+
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ public FormTruckCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new TruckSharingService(pictureBox.Width,
+ pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+
+ ///
+ /// Добавление грузовика
+ ///
+ ///
+ ///
+ private void ButtonAddTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck));
+ ///
+ /// Добавление спортивного автомобиля
+ ///
+ /// CreateObject(nameof(DrawningDumpTruck));
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ Random random = new();
+ DrawningTruck drawningTruck;
+ switch (type)
+ {
+ case nameof(DrawningTruck):
+ drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random));
+ break;
+ case nameof(DrawningDumpTruck):
+ drawningTruck = new DrawningDumpTruck(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 + drawningTruck >= 0)
+ {
+ 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 ButtonRemoveTruck_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 ButtonGoToChek_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ DrawningTruck? truck = null;
+ int counter = 100;
+ while (truck == null)
+ {
+ truck = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+ if (truck == null)
+ {
+ return;
+ }
+ FormDumpTruck form = new()
+ {
+ SetTruck = truck
+ };
+ form.ShowDialog();
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ pictureBox.Image = _company.Show();
+ }
+}
+
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.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/ProjectDumpTruck/ProjectDumpTruck/MovementStrategy/AbstractStrategy.cs b/ProjectDumpTruck/ProjectDumpTruck/MovementStrategy/AbstractStrategy.cs
index bbd8e36..3dc17c6 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/MovementStrategy/AbstractStrategy.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/MovementStrategy/AbstractStrategy.cs
@@ -65,7 +65,8 @@ public abstract class AbstractStrategy
///
/// Перемещение влево
///
- /// Результат перемещения (true - удалось переместиться, false - неудача)
+ /// Результат перемещения (true
+ /// удалось переместиться, false - неудача)
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
///
/// Перемещение вправо
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Program.cs b/ProjectDumpTruck/ProjectDumpTruck/Program.cs
index 6379f87..589f4a5 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Program.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectDumpTruck
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormDumpTruck());
+ Application.Run(new FormTruckCollection());
}
}
}
\ No newline at end of file