From 87a93c30f8cd4e78e9c695c716d798bc923eef53 Mon Sep 17 00:00:00 2001 From: cleverman1337 <74911264+cleverman1337@users.noreply.github.com> Date: Thu, 2 May 2024 09:56:31 +0400 Subject: [PATCH] LabWork03 --- .../MassiveGenericObjects.cs | 2 +- .../TankSharingService.cs | 16 ++++++++-------- .../FormTankCollection.cs | 2 ++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs index 6f73281..d092beb 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs @@ -92,7 +92,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Remove(int position) { - if (position < 0 || position >= _collection.Length || _collection[position] == null) // проверка позиции и наличия объекта + if (position < 0 || position >= _collection.Length || _collection[position] == null) return null; T? temp = _collection[position]; _collection[position] = null; diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/TankSharingService.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/TankSharingService.cs index a49855e..f81a2a9 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/TankSharingService.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/TankSharingService.cs @@ -36,25 +36,25 @@ public class TankSharingService : AbstractCompany int width = _pictureWidth / _placeSizeWidth; int height = _pictureHeight / _placeSizeHeight; - int locomotiveWidth = 0; - int locomotiveHeight = height - 1; + int tankWidth = 0; + int tankHeight = height - 1; for (int i = 0; i < (_collection?.Count ?? 0); i++) { if (_collection.Get(i) != null) { _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); - _collection.Get(i).SetPosition(_placeSizeWidth * locomotiveWidth + 20, locomotiveHeight * _placeSizeHeight + 20); + _collection.Get(i).SetPosition(_placeSizeWidth * tankWidth + 20, tankHeight * _placeSizeHeight + 20); } - if (locomotiveWidth < width - 1) - locomotiveWidth++; + if (tankWidth < width - 1) + tankWidth++; else { - locomotiveWidth = 0; - locomotiveHeight--; + tankWidth = 0; + tankHeight--; } - if (locomotiveHeight < 0) + if (tankHeight < 0) { return; } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs index 32f052a..6af2c20 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs @@ -107,10 +107,12 @@ public partial class FormTankCollection : Form } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show(); + } else {