diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs
index c0b5631..62d766b 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs
@@ -1,9 +1,4 @@
using ProjectCleaningCar.Drawnings;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace ProjectCleaningCar.CollectionGenericObjects;
///
@@ -54,9 +49,9 @@ public abstract class AbstractCompany
/// Компания
/// Добавляемый объект
///
- public static bool operator +(AbstractCompany company, DrawningTruck truck)
+ public static int operator +(AbstractCompany company, DrawningTruck truck)
{
- return company._collection?.Insert(truck) ?? false;
+ return company._collection?.Insert(truck) ?? -1;
}
///
/// Перегрузка оператора удаления для класса
@@ -64,9 +59,9 @@ public abstract class AbstractCompany
/// Компания
/// Номер удаляемого объекта
///
- public static bool operator -(AbstractCompany company, int position)
+ public static DrawningTruck operator -(AbstractCompany company, int position)
{
- return company._collection?.Remove(position) ?? false;
+ return company._collection?.Remove(position) ?? null;
}
///
/// Получение случайного объекта из коллекции
diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs
index 51961b0..da9ba28 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -25,20 +25,20 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj);
+ int Insert(T obj);
///
/// Добавление объекта в коллекцию на конкретную позицию
///
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
/// true - удаление прошло удачно, false - удаление не удалось
- bool Remove(int position);
+ T Remove(int position);
///
/// Получение объекта по позиции
///
diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs
index f2bcd08..7a1f83d 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -41,56 +41,70 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
{
_collection = Array.Empty();
}
+
public T? Get(int position)
{
- if (position < 0 || position >= _collection.Length)
+ if (position >= 0 && position < Count)
{
- throw new IndexOutOfRangeException("Position is out of range.");
+ return _collection[position];
}
- return _collection[position];
+
+ return null;
}
- public bool Insert(T obj)
+
+ public int Insert(T obj)
{
- for (int i = 0; i < _collection.Length; i++)
+ for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
- return true;
+ return i;
}
}
-
- return false;
+ return -1;
}
- public bool Insert(T obj, int position)
- {
- if (position < 0 || position >= _collection.Length)
- {
- throw new IndexOutOfRangeException("Position is out of range.");
- }
+ public int Insert(T obj, int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
if (_collection[position] == null)
{
_collection[position] = obj;
- return true;
+ return position;
}
- return false;
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+ for (int i = position - 1; i >= 0; i--)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+
+ return -1;
}
- public bool Remove(int position)
+ public T Remove(int position)
{
- if (position < 0 || position >= _collection.Length)
+ if (position < 0 || position >= Count)
{
- throw new IndexOutOfRangeException("Position is out of range.");
+ return null;
}
-
- if (_collection[position] != null)
- {
- _collection[position] = null;
- return true;
- }
-
- return true;
+ T obj = _collection[position];
+ _collection[position] = null;
+ return obj;
}
}
diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormTruckCollection.Designer.cs b/ProjectCleaningCar/ProjectCleaningCar/FormTruckCollection.Designer.cs
index b950ffa..32c34f3 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/FormTruckCollection.Designer.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/FormTruckCollection.Designer.cs
@@ -68,7 +68,7 @@ namespace ProjectCleaningCar
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
- buttonRefresh.Click += buttonRefresh_Click;
+ buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheck
//
@@ -79,7 +79,7 @@ namespace ProjectCleaningCar
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
- buttonGoToCheck.Click += buttonGoToCheck_Click;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveTruck
//
@@ -90,7 +90,7 @@ namespace ProjectCleaningCar
buttonRemoveTruck.TabIndex = 4;
buttonRemoveTruck.Text = "Удаление грузовика";
buttonRemoveTruck.UseVisualStyleBackColor = true;
- buttonRemoveTruck.Click += buttonRemoveTruck_Click;
+ buttonRemoveTruck.Click += ButtonRemoveTruck_Click;
//
// maskedTextBoxPosition
//
@@ -100,7 +100,7 @@ namespace ProjectCleaningCar
maskedTextBoxPosition.Size = new Size(226, 27);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
- maskedTextBoxPosition.MaskInputRejected += maskedTextBoxPosition_MaskInputRejected;
+ maskedTextBoxPosition.MaskInputRejected += MaskedTextBoxPosition_MaskInputRejected;
//
// buttonAddCleaningCar
//
diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormTruckCollection.cs b/ProjectCleaningCar/ProjectCleaningCar/FormTruckCollection.cs
index 1d9140e..6b8778d 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/FormTruckCollection.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/FormTruckCollection.cs
@@ -67,55 +67,23 @@ public partial class FormTruckCollection : Form
return;
}
Random random = new();
- DrawningTruck drawningTruck;
+ DrawningTruck _drawningTruck;
switch (type)
{
case nameof(DrawningTruck):
- drawningTruck = new DrawningTruck(random.Next(100, 300),
+ _drawningTruck = new DrawningTruck(random.Next(100, 300),
random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningCleaningCar):
- // Вызываем диалоговое окно для выбора основного цвета машины
- Color bodyColor;
- using (ColorDialog dialogBody = new ColorDialog())
- {
- if (dialogBody.ShowDialog() == DialogResult.OK)
- {
- bodyColor = dialogBody.Color;
- }
- else
- {
- // Если диалог был закрыт без выбора цвета, выходим из метода
- return;
- }
- }
- // Вызываем диалоговое окно для выбора дополнительного цвета машины
- Color additionalColor;
- using (ColorDialog dialogAdditional = new ColorDialog())
- {
- if (dialogAdditional.ShowDialog() == DialogResult.OK)
- {
- additionalColor = dialogAdditional.Color;
- }
- else
- {
- // Если диалог был закрыт без выбора цвета, выходим из метода
- return;
- }
- }
- // Создаем объект класса DrawningCleaningCar с выбранными цветами
- drawningTruck = new DrawningCleaningCar(
- random.Next(100, 300),
- random.Next(1000, 3000),
- bodyColor,
- additionalColor,
- Convert.ToBoolean(random.Next(0, 2)),
- Convert.ToBoolean(random.Next(0, 2)));
+ _drawningTruck = new DrawningCleaningCar(random.Next(1000, 3000), random.Next(100, 500),
+ GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
- if (_company + drawningTruck)
+
+ if (_company + _drawningTruck != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@@ -146,7 +114,7 @@ public partial class FormTruckCollection : Form
///
///
///
- private void buttonRemoveTruck_Click(object sender, EventArgs e)
+ private void ButtonRemoveTruck_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company ==
null)
@@ -158,8 +126,9 @@ public partial class FormTruckCollection : Form
{
return;
}
+
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_company - pos)
+ if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
@@ -174,7 +143,7 @@ public partial class FormTruckCollection : Form
///
///
///
- private void buttonGoToCheck_Click(object sender, EventArgs e)
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
@@ -206,7 +175,7 @@ public partial class FormTruckCollection : Form
///
///
///
- private void buttonRefresh_Click(object sender, EventArgs e)
+ private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
@@ -215,7 +184,7 @@ public partial class FormTruckCollection : Form
pictureBox.Image = _company.Show();
}
- private void maskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
+ private void MaskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
}
diff --git a/ProjectCleaningCar/ProjectCleaningCar/ProjectCleaningCar.csproj b/ProjectCleaningCar/ProjectCleaningCar/ProjectCleaningCar.csproj
index 244387d..8bf3ed6 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/ProjectCleaningCar.csproj
+++ b/ProjectCleaningCar/ProjectCleaningCar/ProjectCleaningCar.csproj
@@ -2,7 +2,7 @@
WinExe
- net7.0-windows
+ net7.0-windows7.0
enable
true
enable