From 0c3397fcee860d2ea8a8867b9e3c183fc5b5d6f9 Mon Sep 17 00:00:00 2001 From: "Dmitriev.An" Date: Mon, 4 Mar 2024 10:06:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20#3=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 10 ++++---- .../ICollectionGenericObjects.cs | 6 ++--- .../MassiveGenericObjects.cs | 25 ++++++++++--------- .../ShipPortService.cs | 4 +-- .../ProjectWarmlyShip/FormShipCollection.cs | 4 +-- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/AbstractCompany.cs b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/AbstractCompany.cs index af3b83b..c7c30c6 100644 --- a/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/AbstractCompany.cs @@ -23,7 +23,7 @@ public abstract class AbstractCompany /// /// Коллекция судов /// - protected ICollectionGenericObjects? _collection = null; + public ICollectionGenericObjects? _collection = null; /// /// Вычисление максимального количества элементов, который можно разместить в окне /// @@ -47,9 +47,9 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static bool operator +(AbstractCompany company, DrawningShip ship) + public static int operator +(AbstractCompany company, DrawningShip ship) { - return company._collection?.Insert(ship) ?? false; + return company._collection.Insert(ship); } /// /// Перегрузка оператора удаления для класса @@ -57,9 +57,9 @@ public abstract class AbstractCompany /// Компания /// Номер удаляемого объекта /// - public static bool operator -(AbstractCompany company, int position) + public static DrawningShip operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; + return company._collection?.Remove(position); } /// /// Получение случайного объекта из коллекции diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/ICollectionGenericObjects.cs index e36ab6e..bca9d15 100644 --- a/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -16,20 +16,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/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/MassiveGenericObjects.cs index 3106b42..333e7a1 100644 --- a/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/MassiveGenericObjects.cs @@ -22,7 +22,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (position >= _collection.Length || position < 0) return null; return _collection[position]; } - public bool Insert(T obj) + public int Insert(T obj) { // TODO вставка в свободное место набора int index = 0; @@ -31,13 +31,13 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[index] == null) { _collection[index] = obj; - return true; + return index; } ++index; } - return false; + return -1; } - public bool Insert(T obj, int position) + public int Insert(T obj, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то @@ -45,10 +45,10 @@ public class MassiveGenericObjects : ICollectionGenericObjects // если нет после, ищем до // TODO вставка if (position >= _collection.Length || position < 0) - return false; + return -1; if (_collection[position] == null) { _collection[position] = obj; - return true; + return position; } int index = position + 1; while (index < _collection.Length) @@ -56,7 +56,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[index] == null) { _collection[index] = obj; - return true; + return index; } ++index; } @@ -66,19 +66,20 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[index] == null) { _collection[index] = obj; - return true; + return index; } --index; } - return false; + return -1; } - public bool Remove(int position) + public T Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присвоив элементу массива значение null if (position >= _collection.Length || position < 0) - return false; + return null; + T obj = _collection[position]; _collection[position] = null; - return true; + return obj; } } \ No newline at end of file diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/ShipPortService.cs b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/ShipPortService.cs index 0531e8b..97f46c0 100644 --- a/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/ShipPortService.cs +++ b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/ShipPortService.cs @@ -19,8 +19,7 @@ public class ShipPortService : AbstractCompany { for (int j = 0; j < height + 1; ++j) { - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, - i * _placeSizeWidth + _placeSizeWidth - 5, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 5, j * _placeSizeHeight); } } } @@ -40,7 +39,6 @@ public class ShipPortService : AbstractCompany _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 4); } - if (curWidth > 0) curWidth--; else diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.cs b/ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.cs index 404b0f4..e0ad221 100644 --- a/ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.cs +++ b/ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.cs @@ -42,7 +42,7 @@ public partial class FormShipCollection : Form default: return; } - if (_company + drawningShip) + if (_company + drawningShip != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -84,7 +84,7 @@ public partial class FormShipCollection : Form return; } int pos = Convert.ToInt32(maskedTextBox.Text); - if (_company - pos) + if (_company - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show();