diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..82ef4db
--- /dev/null
+++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,101 @@
+using ProjectCleaningCar.Drawning;
+
+namespace ProjectCleaningCar.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 bool operator +(AbstractCompany company, DrawningCar car)
+ {
+ return company._collection?.Insert(car) ?? false;
+ }
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static bool operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position) ?? false;
+ }
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningCar? GetRandomObject()
+ {
+ Random random = new();
+ return _collection?.Get(random.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)
+ {
+ DrawningCar? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/CarSharingService.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/CarSharingService.cs
new file mode 100644
index 0000000..47b2c81
--- /dev/null
+++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/CarSharingService.cs
@@ -0,0 +1,58 @@
+using ProjectCleaningCar.Drawning;
+using ProjectCleaningCar.Entities;
+using System.Drawing;
+
+namespace ProjectCleaningCar.CollectionGenericObjects;
+///
+/// Реализация абстрактной компании каршеринг
+///
+public class CarSharingService : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public CarSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+
+ }
+ protected override void DrawBackgound(Graphics g)
+ {
+ Pen pen = new Pen(Color.Black, 4f);
+ for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++)
+ {
+ g.DrawLine(pen, 0, i * _placeSizeHeight * 2, _pictureWidth / _placeSizeWidth * _placeSizeWidth, i * _placeSizeHeight * 2);
+ for (int j = 0; j < _pictureWidth / _placeSizeWidth + 1; ++j)
+ {
+ g.DrawLine(pen, j * _placeSizeWidth, i * _placeSizeHeight * 2, j * _placeSizeWidth, i * _placeSizeHeight * 2 + _placeSizeHeight);
+ }
+ }
+ }
+ protected override void SetObjectsPosition()
+ {
+ int nowWidth = 0;
+ int nowHeight = 0;
+
+ for (int i = 0; i < (_collection?.Count ?? 0); i++)
+ {
+ if (nowHeight > _pictureHeight / _placeSizeHeight)
+ {
+ return;
+ }
+ if (_collection?.Get(i) != null)
+ {
+ _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection?.Get(i)?.SetPosition(_placeSizeWidth * nowWidth + 30, nowHeight * _placeSizeHeight * 2 + 20);
+ }
+
+ if (nowWidth < _pictureWidth / _placeSizeWidth - 1) nowWidth++;
+ else
+ {
+ nowWidth = 0;
+ nowHeight++;
+ }
+ }
+ }
+}
diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs
index d190d81..f9132c4 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -9,7 +9,8 @@ public interface ICollectionGenericObjects
///
/// Количество объектов в коллекции
///
- /// ///
+ int Count { get; }
+ ///
/// Установка максимального количества элементов
///
int SetMaxCount { set; }
diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs
index 29bd181..4eff2eb 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -32,11 +32,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
// TODO проверка позиции
+ if (position < 0 || position >= Count) return null;
return _collection[position];
}
public bool Insert(T obj)
{
- for (int i = 0; i < _collection.Length; i++)
+ for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
{
@@ -54,13 +55,40 @@ public class MassiveGenericObjects : ICollectionGenericObjects
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
+ if (position >= Count || position < 0) return false;
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return true;
+ }
+ int temp = position + 1;
+ while(temp < Count)
+ {
+ if (_collection[temp] == null)
+ {
+ _collection[temp] = obj;
+ return true;
+ }
+ ++temp;
+ }
+ temp = position - 1;
+ while(temp > 0)
+ {
+ if (_collection[temp] == null)
+ {
+ _collection[temp] = obj;
+ return true;
+ }
+ --temp;
+ }
return false;
}
public bool Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
+ if (position >= Count || position < 0) return false;
+ _collection[position] = null;
return true;
}
-
}
diff --git a/ProjectCleaningCar/ProjectCleaningCar/Drawning/DrawningCleaningCar.cs b/ProjectCleaningCar/ProjectCleaningCar/Drawning/DrawningCleaningCar.cs
index 05ca635..1b6eb20 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/Drawning/DrawningCleaningCar.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/Drawning/DrawningCleaningCar.cs
@@ -16,11 +16,9 @@ public class DrawningCleaningCar : DrawningCar
/// Бак с водой
/// Подметательная щётка
/// Проблескового маячок
- public DrawningCleaningCar(int speed, double weight, Color bodyColor, Color
-additionalColor, bool tank, bool sweepingBrush, bool flashlight) : base(132, 65)
+ public DrawningCleaningCar(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool sweepingBrush, bool flashlight) : base(132, 65)
{
- EntityCar = new EntityCleaningCar(speed, weight, bodyColor, additionalColor,
-tank, sweepingBrush, flashlight);
+ EntityCar = new EntityCleaningCar(speed, weight, bodyColor, additionalColor, tank, sweepingBrush, flashlight);
}
///
/// Отрисовка объекта
diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.Designer.cs b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.Designer.cs
index d27cb84..372b198 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.Designer.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxCleaningCar = new PictureBox();
- buttonCreateCleaningCar = new Button();
buttonRight = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
- buttonCreateCar = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCleaningCar).BeginInit();
@@ -49,18 +47,6 @@
pictureBoxCleaningCar.TabIndex = 0;
pictureBoxCleaningCar.TabStop = false;
//
- // buttonCreateCleaningCar
- //
- buttonCreateCleaningCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateCleaningCar.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
- buttonCreateCleaningCar.Location = new Point(12, 421);
- buttonCreateCleaningCar.Name = "buttonCreateCleaningCar";
- buttonCreateCleaningCar.Size = new Size(192, 32);
- buttonCreateCleaningCar.TabIndex = 1;
- buttonCreateCleaningCar.Text = "Создать уборочную машину";
- buttonCreateCleaningCar.UseVisualStyleBackColor = true;
- buttonCreateCleaningCar.Click += ButtonCreateCleaningCar_Click;
- //
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -109,17 +95,6 @@
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
- // buttonCreateCar
- //
- buttonCreateCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateCar.Location = new Point(210, 421);
- buttonCreateCar.Name = "buttonCreateCar";
- buttonCreateCar.Size = new Size(192, 32);
- buttonCreateCar.TabIndex = 6;
- buttonCreateCar.Text = "Создать машину";
- buttonCreateCar.UseVisualStyleBackColor = true;
- buttonCreateCar.Click += ButtonCreateCar_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
@@ -149,12 +124,10 @@
ClientSize = new Size(824, 465);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateCar);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonRight);
- Controls.Add(buttonCreateCleaningCar);
Controls.Add(pictureBoxCleaningCar);
Name = "FormCleaningCar";
Text = "FormCleaningCar";
@@ -165,12 +138,10 @@
#endregion
private PictureBox pictureBoxCleaningCar;
- private Button buttonCreateCleaningCar;
private Button buttonRight;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
- private Button buttonCreateCar;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs
index f0604e8..41d7544 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs
@@ -16,6 +16,20 @@ public partial class FormCleaningCar : Form
///
private AbstractStrategy? _strategy;
///
+ /// Получение объекта
+ ///
+ public DrawningCar SetCar
+ {
+ set
+ {
+ _drawningCar = value;
+ _drawningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+ ///
/// Конструктор формы
///
public FormCleaningCar()
@@ -39,48 +53,6 @@ public partial class FormCleaningCar : Form
pictureBoxCleaningCar.Image = bmp;
}
///
- /// Обработка нажатия кнопки "Создать подметательно-уборочную машину"
- ///
- ///
- ///
- private void ButtonCreateCleaningCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCleaningCar));
- ///
- /// Обработка нажатия кнопки "Создать машину"
- ///
- ///
- ///
- private void ButtonCreateCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCar));
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- public void CreateObject(string type)
- {
- Random random = new Random();
- switch (type)
- {
- case nameof(DrawningCar):
- _drawningCar = new DrawningCar(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)));
- break;
- case nameof(DrawningCleaningCar):
- _drawningCar = new DrawningCleaningCar(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
- Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
- Convert.ToBoolean(random.Next(0, 2)),
- Convert.ToBoolean(random.Next(0, 2)),
- Convert.ToBoolean(random.Next(0, 2)));
- break;
- default:
- return;
- }
- _drawningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
- _drawningCar.SetPosition(random.Next(0, 200), random.Next(0, 200));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
- ///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
///
diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCarCollection.Designer.cs b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCarCollection.Designer.cs
new file mode 100644
index 0000000..9b539c9
--- /dev/null
+++ b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCarCollection.Designer.cs
@@ -0,0 +1,170 @@
+namespace ProjectCleaningCar
+{
+ partial class FormCleaningCarCollection
+ {
+ ///
+ /// 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()
+ {
+ tools = new GroupBox();
+ buttonRefresh = new Button();
+ buttonGoToCheck = new Button();
+ buttonDelCar = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddCleaningCar = new Button();
+ buttonAddCar = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ tools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ SuspendLayout();
+ //
+ // tools
+ //
+ tools.Controls.Add(buttonRefresh);
+ tools.Controls.Add(buttonGoToCheck);
+ tools.Controls.Add(buttonDelCar);
+ tools.Controls.Add(maskedTextBoxPosition);
+ tools.Controls.Add(buttonAddCleaningCar);
+ tools.Controls.Add(buttonAddCar);
+ tools.Controls.Add(comboBoxSelectorCompany);
+ tools.Dock = DockStyle.Right;
+ tools.Location = new Point(752, 0);
+ tools.Name = "tools";
+ tools.Size = new Size(208, 557);
+ tools.TabIndex = 0;
+ tools.TabStop = false;
+ tools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(24, 389);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(163, 38);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Location = new Point(24, 274);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(163, 38);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonDelCar
+ //
+ buttonDelCar.Location = new Point(24, 187);
+ buttonDelCar.Name = "buttonDelCar";
+ buttonDelCar.Size = new Size(163, 38);
+ buttonDelCar.TabIndex = 4;
+ buttonDelCar.Text = "Удалить машину";
+ buttonDelCar.UseVisualStyleBackColor = true;
+ buttonDelCar.Click += ButtonRemoveCar_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(24, 158);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(163, 23);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddCleaningCar
+ //
+ buttonAddCleaningCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddCleaningCar.Location = new Point(24, 114);
+ buttonAddCleaningCar.Name = "buttonAddCleaningCar";
+ buttonAddCleaningCar.Size = new Size(163, 38);
+ buttonAddCleaningCar.TabIndex = 2;
+ buttonAddCleaningCar.Text = "Добавление уборочной машины";
+ buttonAddCleaningCar.UseVisualStyleBackColor = true;
+ buttonAddCleaningCar.Click += ButtonAddCleaningCar_Click;
+ //
+ // buttonAddCar
+ //
+ buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddCar.Location = new Point(24, 70);
+ buttonAddCar.Name = "buttonAddCar";
+ buttonAddCar.Size = new Size(163, 38);
+ buttonAddCar.TabIndex = 1;
+ buttonAddCar.Text = "Добавление машины";
+ buttonAddCar.UseVisualStyleBackColor = true;
+ buttonAddCar.Click += ButtonAddCar_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(24, 22);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(163, 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(752, 557);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormCleaningCarCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(960, 557);
+ Controls.Add(pictureBox);
+ Controls.Add(tools);
+ Name = "FormCleaningCarCollection";
+ Text = "Коллекция уборочных машин";
+ tools.ResumeLayout(false);
+ tools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox tools;
+ private Button buttonAddCar;
+ private ComboBox comboBoxSelectorCompany;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonAddCleaningCar;
+ private PictureBox pictureBox;
+ private Button buttonDelCar;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCarCollection.cs b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCarCollection.cs
new file mode 100644
index 0000000..70f14ff
--- /dev/null
+++ b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCarCollection.cs
@@ -0,0 +1,190 @@
+using ProjectCleaningCar.CollectionGenericObjects;
+using ProjectCleaningCar.Drawning;
+
+namespace ProjectCleaningCar;
+///
+/// Форма работы с компанией и ее коллекцией
+///
+public partial class FormCleaningCarCollection : Form
+{
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+ ///
+ /// Конструктор
+ ///
+ public FormCleaningCarCollection()
+ {
+ InitializeComponent();
+ }
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new CarSharingService(pictureBox.Width,
+ pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+ ///
+ /// Добавление спортивного автомобиля
+ ///
+ ///
+ ///
+ private void ButtonAddCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCar));
+ ///
+ /// Добавление подметательно-уборочной машины
+ ///
+ ///
+ ///
+ private void ButtonAddCleaningCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCleaningCar));
+ ///
+ /// Создание объекта класса-перемещенияв
+ ///
+ ///
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ Random random = new();
+ DrawningCar drawningCar;
+ switch (type)
+ {
+ case nameof(DrawningCar):
+ drawningCar = new DrawningCar(random.Next(100, 300),
+ random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningCleaningCar):
+ // TODO вызов диалогового окна для выбора цвета
+ drawningCar = new DrawningCleaningCar(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 + drawningCar)
+ {
+ 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 ButtonRemoveCar_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)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+
+ }
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ DrawningCar? car = null;
+ int counter = 100;
+ while (car == null)
+ {
+ car = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0) break;
+ }
+ if (car == null)
+ {
+ return;
+ }
+ FormCleaningCar form = new FormCleaningCar();
+ form.SetCar = car;
+ form.ShowDialog();
+ }
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ DrawningCar? car = null;
+ int counter = 100;
+ while (car == null)
+ {
+ car = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+ if (car == null)
+ {
+ return;
+ }
+ FormCleaningCar form = new()
+ {
+ SetCar = car
+ };
+ form.ShowDialog();
+
+ }
+
+}
diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCarCollection.resx b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCarCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCarCollection.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/ProjectCleaningCar/ProjectCleaningCar/MovementStrategy/MoveToBorder.cs b/ProjectCleaningCar/ProjectCleaningCar/MovementStrategy/MoveToBorder.cs
index 2cd33b8..1b71561 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/MovementStrategy/MoveToBorder.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/MovementStrategy/MoveToBorder.cs
@@ -11,7 +11,7 @@ public class MoveToBorder : AbstractStrategy
{
return false;
}
- return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;\
+ return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
diff --git a/ProjectCleaningCar/ProjectCleaningCar/Program.cs b/ProjectCleaningCar/ProjectCleaningCar/Program.cs
index 67932ee..6c327ba 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/Program.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectCleaningCar
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormCleaningCar());
+ Application.Run(new FormCleaningCarCollection());
}
}
}
\ No newline at end of file