diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs index 302c514..2db825c 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs @@ -63,9 +63,9 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static bool operator +(AbstractCompany company, DrawningDozer dozer) + public static int operator +(AbstractCompany company, DrawningDozer dozer) { - return company._collection?.Insert(dozer) ?? false; + return company._collection.Insert(dozer); } /// @@ -74,9 +74,9 @@ public abstract class AbstractCompany /// Компания /// Номер удаляемого объекта /// - public static bool operator -(AbstractCompany company, int position) + public static DrawningDozer? operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; + return company._collection.Remove(position); } /// diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs index 1e25e8d..c1131d7 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs @@ -31,8 +31,10 @@ public class Garage : AbstractCompany { int cntVertically = _pictureHeight / _placeSizeHeight; //Колличество мест по вертикали int cntHorizontally = _pictureWidth / _placeSizeWidth; //Колличество мест по горизонтали - Pen pen = new Pen(Color.FromArgb(185, 140, 0)); - pen.Width = 3; + Pen pen = new(Color.FromArgb(185, 140, 0)) + { + Width = 3 + }; for (int i = 0; i < cntHorizontally; i++) { @@ -78,7 +80,5 @@ public class Garage : AbstractCompany placeVertically--; } } - - //throw new NotImplementedException(); } } diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ICollectoinGenericObjects.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ICollectoinGenericObjects.cs index be6c0e0..ef584bc 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ICollectoinGenericObjects.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ICollectoinGenericObjects.cs @@ -28,7 +28,7 @@ public interface ICollectoinGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj); + int Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -36,14 +36,14 @@ public interface ICollectoinGenericObjects /// Добавляемый объект /// Позиция /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj, int position); + int Insert(T obj, int position); /// /// Удаление объекта из коллекции на конкретной позиции /// /// Позиция /// - bool Remove(int position); + T? Remove(int position); /// /// Получение объекта по позиции diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs index 22bf179..8a90051 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs @@ -52,7 +52,7 @@ public class MassiveGenericObject : ICollectoinGenericObjects } } - public bool Insert(T obj) + public int Insert(T obj) { //Вставка в свободное место набора for (int i = 0; i < Count; i++) @@ -60,19 +60,19 @@ public class MassiveGenericObject : ICollectoinGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } - return false; + return -1; } - public bool Insert(T obj, int position) + public int Insert(T obj, int position) { //Проверка позиции if ((position < 0) || (position >= Count)) { - return false; + return -1; } //Проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой @@ -105,25 +105,26 @@ public class MassiveGenericObject : ICollectoinGenericObjects if (placed == false) { - return false; + return -1; } } //Вставка _collection[position] = obj; - return true; + return position; } - public bool Remove(int position) + public T? Remove(int position) { //Проверка позиции if ((position < 0) || (position >= Count) || (_collection[position] == null)) { - return false; + return null; } //Удаление объекта из массива, присвоив элементу массива значение null + T? elem = _collection[position]; _collection[position] = null; - return true; + return elem; } } diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs index a9ff02a..5dad03e 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs @@ -137,7 +137,7 @@ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(332, 41); comboBoxSelectorCompany.TabIndex = 1; - comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs index 6e42ba8..3c0a7b4 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs @@ -36,7 +36,7 @@ public partial class FormBulldozerCollection : Form /// /// /// - private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxSelectorCompany.Text) { @@ -46,15 +46,6 @@ public partial class FormBulldozerCollection : Form } } -/* private void ComboBoxSelectorCompany_SelectedIndexChanget(object sender, EventArgs e) - { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObject()); - break; - } - }*/ /// /// Добавление обычного бульдозера @@ -101,7 +92,7 @@ public partial class FormBulldozerCollection : Form return; } - if (_company + drawningDozer) + if (_company + drawningDozer != -1) { MessageBox.Show("Объект добавлен."); pictureBox.Image = _company.Show(); @@ -162,7 +153,7 @@ public partial class FormBulldozerCollection : Form } int pos = Convert.ToInt32(maskedTextBox.Text); - if (_company - pos) + if (_company - pos != null) { MessageBox.Show("Объект удалён."); pictureBox.Image = _company.Show();