Compare commits

..

No commits in common. "10edf8895bab1a754a4b4c928aa00aaebad0a208" and "f89e86bd93dff6ad9d939764227284bd843d5973" have entirely different histories.

3 changed files with 22 additions and 29 deletions

View File

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

View File

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