LabWork03

This commit is contained in:
cleverman1337 2024-05-02 09:56:31 +04:00
parent b78ad0fb51
commit 87a93c30f8
3 changed files with 11 additions and 9 deletions

View File

@ -92,7 +92,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
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;

View File

@ -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;
}

View File

@ -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
{