From 79c4158fba40522e3e1f7629cd01eb66f8b57b87 Mon Sep 17 00:00:00 2001 From: user <732603@gmail.com> Date: Thu, 4 Apr 2024 21:26:23 +0400 Subject: [PATCH] fix --- .../AbstractCompany.cs | 8 ++++---- .../BoatHarborService.cs | 18 +++++++++--------- .../ICollectionGenericObjects.cs | 2 +- .../MassiveGenericObjects.cs | 8 ++++---- .../ProjectMotorBoat/FormBoatCollection.cs | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs index b2cfc59..1403f66 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs @@ -68,9 +68,9 @@ public abstract class AbstractCompany /// Компания /// Номер удаляемого объекта /// - public static bool operator -(AbstractCompany company, int position) + public static DrawingBoat? operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; + return company._collection?.Remove(position); } /// @@ -91,7 +91,7 @@ public abstract class AbstractCompany { Bitmap bitmap = new(_pictureWidth, _pictureHeight); Graphics graphics = Graphics.FromImage(bitmap); - DrawBackgound(graphics); + DrawBackground(graphics); SetObjectsPosition(); for (int i = 0; i < (_collection?.Count ?? 0); ++i) @@ -107,7 +107,7 @@ public abstract class AbstractCompany /// Вывод заднего фона /// /// - protected abstract void DrawBackgound(Graphics g); + protected abstract void DrawBackground(Graphics g); /// /// Расстановка объектов diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs index 778154f..0854001 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs @@ -20,13 +20,13 @@ public class BoatHarborService : AbstractCompany } - protected override void DrawBackgound(Graphics g) + protected override void DrawBackground(Graphics g) { Pen pen = new(Color.BurlyWood, 4); - for (int startPosX = 5; (startPosX + _placeSizeWidth) < _pictureWidth; startPosX += (_placeSizeWidth + 8)) + for (int startPosX = 5; (startPosX + _placeSizeWidth) < _pictureWidth; startPosX += _placeSizeWidth) { - for (int startPosY = 5; (startPosY + _placeSizeHeight) < _pictureHeight; startPosY += (_placeSizeHeight + 8)) + for (int startPosY = 5; (startPosY + _placeSizeHeight) < _pictureHeight; startPosY += _placeSizeHeight) { Point[] points = { @@ -45,18 +45,18 @@ public class BoatHarborService : AbstractCompany int startPosX = 10; int startPosY = 10; - for (int i = 0; _collection.Get(i) != null; i++) + for (int i = 0; _collection?.Get(i) != null; i++) { if (startPosX + _placeSizeWidth > _pictureWidth) { - startPosX = 5; - startPosY += _placeSizeHeight + 8; + startPosX = 10; + startPosY += _placeSizeHeight; } - _collection?.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); - _collection?.Get(i).SetPosition(startPosX, startPosY); + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(startPosX, startPosY); - startPosX += _placeSizeWidth + 8; + startPosX += _placeSizeWidth; } } } diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs index 15f971d..f5e51e7 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -37,7 +37,7 @@ public interface ICollectionGenericObjects /// /// Позиция /// true - удаление прошло удачно, false - удаление не удалось - bool Remove(int position); + T? Remove(int position); /// /// Получение объекта по позиции diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs index 01fc45f..1c056ac 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs @@ -43,7 +43,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { // TODO проверка позиции ✔ - if (_collection[position] != null) + if (_collection[position] != null && position < Count - 1) { return _collection[position]; } @@ -95,16 +95,16 @@ public class MassiveGenericObjects : ICollectionGenericObjects return -1; } - public bool Remove(int position) + public T? Remove(int position) { // TODO проверка позиции ✔ // TODO удаление объекта из массива, присвоив элементу массива значение null ✔ if (_collection[position] != null) { _collection[position] = null; - return true; + return _collection[position]; } - return false; + return null; } } diff --git a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs index 6a34c4c..4c35f84 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs @@ -79,7 +79,7 @@ public partial class FormBoatCollection : Form return; } - if (_company + drawingBoat != null) + if (_company + drawingBoat >= 0) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -125,7 +125,7 @@ public partial class FormBoatCollection : Form } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos) + if (_company - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show();