diff --git a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs index 2317b42..47f71e5 100644 --- a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs @@ -52,7 +52,7 @@ namespace Artilleries if (form.ShowDialog() == DialogResult.OK) { DrawingObjectArtillery car = new(form.SelectedArtillery); - if (_mapArtilleriesCollectionGeneric + car) + if (_mapArtilleriesCollectionGeneric + car != -1) { MessageBox.Show("Объект добавлен"); pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet(); @@ -75,7 +75,7 @@ namespace Artilleries return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapArtilleriesCollectionGeneric - pos) + if (_mapArtilleriesCollectionGeneric - pos != null) { MessageBox.Show("Объект удален"); pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet(); diff --git a/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs index d53c409..4c03bfe 100644 --- a/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs @@ -27,14 +27,14 @@ namespace Artilleries _map = map; } - public static bool operator +(MapWithSetArtilleriesGeneric map, T artillery) + public static int operator +(MapWithSetArtilleriesGeneric map, T artillery) { - return map._setArtilleries.Insert(artillery); // TODO + return map._setArtilleries.Insert(artillery); } - public static bool operator -(MapWithSetArtilleriesGeneric map, int position) + public static T operator -(MapWithSetArtilleriesGeneric map, int position) { - return map._setArtilleries.Remove(position); // TODO + return map._setArtilleries.Remove(position); } public Bitmap ShowSet() diff --git a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs index 2f87663..35c69f5 100644 --- a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs @@ -17,22 +17,22 @@ namespace Artilleries _places = new T[count]; } - public bool Insert(T artillery) + public int Insert(T artillery) { return Insert(artillery, 0); } - public bool Insert(T artillery, int position) + public int Insert(T artillery, int position) { if (position < 0 || position >= Count) { - return false; + return -1; } if (_places[position] == null) { _places[position] = artillery; - return true; + return position; } int firstNull = -1; @@ -48,27 +48,29 @@ namespace Artilleries if (firstNull == -1) { - return false; + return -1; } for (int i = firstNull; i > position; i--) { - (_places[i], _places[i - 1]) = (_places[i - 1], _places[i]); + _places[i] = _places[i - 1]; } _places[position] = artillery; - return true; + return position; } - public bool Remove(int position) + public T Remove(int position) { - if (position < 0 || position >= Count || _places[position] == null) + if (position < 0 || position >= Count) { - return false; + return null; } + var result = _places[position]; + _places[position] = null; - return true; + return result; } public T Get(int position)