fix
This commit is contained in:
parent
42e483a76d
commit
79c4158fba
@ -68,9 +68,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
protected abstract void DrawBackgound(Graphics g);
|
||||
protected abstract void DrawBackground(Graphics g);
|
||||
|
||||
/// <summary>
|
||||
/// Расстановка объектов
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
bool Remove(int position);
|
||||
T? Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
|
@ -43,7 +43,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
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<T> : ICollectionGenericObjects<T>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user