diff --git a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs
index 63ad8f1..939321f 100644
--- a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs
+++ b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs
@@ -67,7 +67,7 @@ namespace AntiAircraftGun
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectAntiAircraftGun antiAircraftGun = new(form.SelectedAntiAircraftGun);
- if (_mapAntiAircraftGunsCollectionGeneric + antiAircraftGun)
+ if (_mapAntiAircraftGunsCollectionGeneric + antiAircraftGun >= 0)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();
@@ -94,7 +94,7 @@ namespace AntiAircraftGun
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapAntiAircraftGunsCollectionGeneric - pos)
+ if (_mapAntiAircraftGunsCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapAntiAircraftGunsCollectionGeneric.ShowSet();
diff --git a/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs
index ae58bf9..75f7020 100644
--- a/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs
+++ b/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs
@@ -60,7 +60,7 @@ namespace AntiAircraftGun
///
///
///
- public static bool operator +(MapWithSetAntiAircraftGunsGeneric map, T antiAircraftGuns)
+ public static int operator +(MapWithSetAntiAircraftGunsGeneric map, T antiAircraftGuns)
{
return map._setAntiAircraftGuns.Insert(antiAircraftGuns);
}
@@ -70,7 +70,7 @@ namespace AntiAircraftGun
///
///
///
- public static bool operator -(MapWithSetAntiAircraftGunsGeneric map, int position)
+ public static T operator -(MapWithSetAntiAircraftGunsGeneric map, int position)
{
return map._setAntiAircraftGuns.Remove(position);
}
@@ -149,7 +149,6 @@ namespace AntiAircraftGun
///
private void DrawBackground(Graphics g)
{
- Pen pen = new(Color.Black, 3);
Brush brushGreen = new SolidBrush(Color.Green);
Brush brushLightGray = new SolidBrush(Color.LightGray);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
@@ -167,10 +166,18 @@ namespace AntiAircraftGun
///
private void DrawAntiAircraftGuns(Graphics g)
{
+ int xPositionInStorage = _placeSizeWidth / 10;
+ int yPositionInStorage = _placeSizeHeight / 10;
for (int i = 0; i < _setAntiAircraftGuns.Count; i++)
{
- // TODO установка позиции
+ _setAntiAircraftGuns.Get(i)?.SetObject(xPositionInStorage, yPositionInStorage, _pictureWidth, _pictureHeight);
_setAntiAircraftGuns.Get(i)?.DrawingObjectAntiAircraftGun(g);
+ xPositionInStorage += _placeSizeWidth;
+ if (xPositionInStorage > _pictureWidth - _placeSizeWidth)
+ {
+ xPositionInStorage = _placeSizeWidth / 10;
+ yPositionInStorage += _placeSizeHeight;
+ }
}
}
}
diff --git a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs
index 56639ce..36fbfde 100644
--- a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs
+++ b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs
@@ -34,9 +34,8 @@ namespace AntiAircraftGun
///
/// Добавляемый автомобиль
///
- public bool Insert(T antiAircraftGun)
+ public int Insert(T antiAircraftGun)
{
- // TODO вставка в начало набора
if (_places[Count - 1] == null)
{
for(int i = Count - 1; i > 0; i--)
@@ -44,9 +43,9 @@ namespace AntiAircraftGun
_places[i] = _places[i - 1];
}
_places[0] = antiAircraftGun;
- return true;
+ return 0;
}
- return false;
+ return -1;
}
///
/// Добавление объекта в набор на конкретную позицию
@@ -54,13 +53,13 @@ namespace AntiAircraftGun
/// Добавляемое орудие
/// Позиция
///
- public bool Insert(T antiAircraftGun, int position)
+ public int Insert(T antiAircraftGun, int position)
{
- if (position < 0 || position >= Count) return false;
+ if (position < 0 || position >= Count) return -1;
if (_places[position] == null)
{
_places[position] = antiAircraftGun;
- return true;
+ return position;
}
else
{
@@ -71,9 +70,9 @@ namespace AntiAircraftGun
_places[i] = _places[i - 1];
}
_places[position] = antiAircraftGun;
- return true;
+ return position;
}
- return false;
+ return -1;
}
}
///
@@ -81,15 +80,23 @@ namespace AntiAircraftGun
///
///
///
- public bool Remove(int position)
+ public T Remove(int position)
{
- if (position < 0 || position >= Count) return false;
+ if (position < 0 || position >= Count) return null;
if (_places[position] != null)
{
+ T removed = _places[position];
_places[position] = null;
- return true;
+ if (position < Count - 1)
+ {
+ for (int k = position; k < Count - 1; k++)
+ {
+ _places[k] = _places[k + 1];
+ }
+ }
+ return removed;
}
- return false;
+ return null;
}
///
/// Получение объекта из набора по позиции