From 3ce36fbe16184e57e453c5ab9d740dad69ad3b02 Mon Sep 17 00:00:00 2001 From: ENDORFIT Date: Mon, 11 Mar 2024 15:22:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectMonorail/FormMonorailCollection.cs | 6 ++--- .../AbstractCompany.cs | 10 +++---- ...aringService.cs => DepotSharingService.cs} | 11 ++++---- .../ICollectionGenericObjects.cs | 10 ++++--- .../MassiveGenericObjects.cs | 27 ++++++++++--------- 5 files changed, 33 insertions(+), 31 deletions(-) rename ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/{MonorailSharingService.cs => DepotSharingService.cs} (82%) diff --git a/ProjectMonorail/FormMonorailCollection.cs b/ProjectMonorail/FormMonorailCollection.cs index b94fae4..7ab4a7f 100644 --- a/ProjectMonorail/FormMonorailCollection.cs +++ b/ProjectMonorail/FormMonorailCollection.cs @@ -31,7 +31,7 @@ namespace ProjectMonorail switch (comboBoxSelectorCompany.Text) { case "Хранилище": - _company = new MonorailSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + _company = new DepotSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); break; } } @@ -60,7 +60,7 @@ namespace ProjectMonorail return; } - if (_company + drawningMonorail) + if (_company + drawningMonorail != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -107,7 +107,7 @@ namespace ProjectMonorail int position = Convert.ToInt32(maskedTextBox.Text); - if (_company - position) + if (_company - position != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show(); diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/AbstractCompany.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/AbstractCompany.cs index 3b6b519..9c29fae 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/AbstractCompany.cs @@ -10,7 +10,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects /// /// Размер места (ширина) /// - protected readonly int _placeSizeWidth = 210; + protected readonly int _placeSizeWidth = 240; /// /// Размер места (высота) @@ -57,9 +57,9 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects /// Компания /// Добавляемый объект /// - public static bool operator +(AbstractCompany company, DrawingMonorail monorail) + public static int operator +(AbstractCompany company, DrawingMonorail monorail) { - return company._collection?.Insert(monorail) ?? false; + return company._collection?.Insert(monorail) ?? -1; } /// @@ -68,9 +68,9 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects /// Компания /// Номер удаляемого объекта /// - public static bool operator -(AbstractCompany company, int position) + public static DrawingMonorail operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; + return company._collection?.Remove(position) ?? null; } /// diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MonorailSharingService.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/DepotSharingService.cs similarity index 82% rename from ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MonorailSharingService.cs rename to ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/DepotSharingService.cs index 3d82f79..86200c9 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MonorailSharingService.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/DepotSharingService.cs @@ -4,9 +4,9 @@ using System.Drawing; namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects { - public class MonorailSharingService : AbstractCompany + public class DepotSharingService : AbstractCompany { - public MonorailSharingService(int pictureWidth, int pictureHeight, ICollectionGenericObjects collection) : base(pictureWidth, pictureHeight, collection) {} + public DepotSharingService(int pictureWidth, int pictureHeight, ICollectionGenericObjects collection) : base(pictureWidth, pictureHeight, collection) {} private int maxCountX; private int maxCountY; @@ -39,13 +39,12 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects int boarderOffsetX = 20; int boarderOffsetY = 20; - int currentIndex = -1; + int currentIndex = 0; - for (int j = 0; j < maxCountY; j++) + for (int j = maxCountY - 1; j >= 0; j--) { - for (int i = 0; i < maxCountX; i++) + for (int i = 0; i < maxCountX; i++, currentIndex++) { - currentIndex++; if (_collection.Get(currentIndex) == null) continue; _collection.Get(currentIndex).SetPictureSize(_pictureWidth, _pictureHeight); diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ICollectionGenericObjects.cs index 4509b8d..182b693 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -1,4 +1,6 @@ -namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects +using ProjectMonorail.Scripts.Monorail.Drawnings; + +namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects { /// /// Интерфейс описания действий для набора хранимых объектов @@ -22,7 +24,7 @@ /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj); + int Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -30,14 +32,14 @@ /// Добавляемый объект /// Позиция /// 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/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MassiveGenericObjects.cs index 873a47b..81ca0b2 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MassiveGenericObjects.cs @@ -43,54 +43,55 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects public T? Get(int position) { // TODO проверка позиции - if (_collection[position] == null) return null; + if (!(position >= 0 && position < Count) || _collection[position] == null) return null; return _collection[position]; } - public bool Insert(T obj) + public int Insert(T obj) { // TODO вставка в свободное место набора for (int i = 0; i < Count; i++) { - if (InsertingElementCollection(i, obj)) return true; + if (InsertingElementCollection(i, obj)) return i; } - return false; + return -1; } - public bool Insert(T obj, int position) + public int Insert(T obj, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то // ищется свободное место после этой позиции и идет вставка туда // если нет после, ищем до // TODO вставка - - if (InsertingElementCollection(position, obj)) return true; + if (!(position >= 0 && position < Count)) return -1; + if (InsertingElementCollection(position, obj)) return position; for (int i = position + 1; i < Count; i++) { - if (InsertingElementCollection(i, obj)) return true; + if (InsertingElementCollection(i, obj)) return i; } for (int i = position - 1; i >= 0; i--) { - if (InsertingElementCollection(i, obj)) return true; + if (InsertingElementCollection(i, obj)) return i; } - return false; + return -1; } - public bool Remove(int position) + public T Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присвоив элементу массива значение null - if (_collection[position] == null) return false; + if (!(position >= 0 && position < Count) || _collection[position] == null) return null; + T obj = _collection[position]; _collection[position] = null; - return true; + return obj; } ///