Compare commits

...

3 Commits

3 changed files with 29 additions and 22 deletions

View File

@ -106,7 +106,7 @@ namespace AntiAircraftGun
FormAntiAirCraftGun form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (obj + form.SelectedZenit)
if ((obj + form.SelectedZenit)==1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowZenits();

View File

@ -51,31 +51,26 @@ namespace AntiAircraftGun.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(AntiAirCraftGunGenericCollection<T, U> collect, T? obj)
public static int operator +(AntiAirCraftGunGenericCollection<T,U> collect, T? obj)
{
if (obj == null)
{
MessageBox.Show("Объект пустой. Невозможно добавить.");
return false;
return -1;
return collect?._collection.Insert(obj) ?? -1;
}
return collect?._collection.Insert(obj) ?? false;
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(AntiAirCraftGunGenericCollection<T, U> collect, int pos)
public static bool operator -(AntiAirCraftGunGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
T? obj = collect._collection.Get(pos);
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
return collect._collection.Remove(pos);
return false;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
@ -156,9 +151,21 @@ namespace AntiAircraftGun.Generics
if (y + distance_between_objects >= maxY)
{
y = 0;
x += obj.GetWidth + 10 + _placeSizeWidth;
x += _placeSizeWidth;
}
}
if (obj == null)
{
// Увеличиваем координату Y для следующего объекта
y += distance_between_objects;
// Проверяем, если Y достигло максимума, изменяем X и сбрасываем Y
if (y+distance_between_objects >= maxY)
{
y = 0;
x += _placeSizeWidth;
}
};
}
}
}

View File

@ -35,21 +35,21 @@ namespace AntiAircraftGun.Generics
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <returns></returns>
public bool Insert(T car)
public int Insert(T car)
{
if (_places.Count == _maxCount)
return false;
return -1;
Insert(car, 0);
return true;
return 1;
}
public bool Insert(T car, int position)
public int Insert(T car, int position)
{
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
return false;
return -1;
_places.Insert(position, car);
return true;
return 1;
}
/// <summary>