diff --git a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs index 3c13999..5344495 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirBomber.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirBomber.cs @@ -29,7 +29,7 @@ namespace AirBomber if (form.ShowDialog() == DialogResult.OK) { DrawningObjectBomber airBomber = new(form.SelectedAirBomber); - if (_mapAirBomberCollectionGeneric + airBomber == 1) + if (_mapAirBomberCollectionGeneric + airBomber > -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapAirBomberCollectionGeneric.ShowSet(); @@ -52,7 +52,7 @@ namespace AirBomber return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapAirBomberCollectionGeneric - pos == 1) + if (_mapAirBomberCollectionGeneric - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapAirBomberCollectionGeneric.ShowSet(); diff --git a/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs b/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs index bafc36e..6b7ecbf 100644 --- a/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs @@ -32,7 +32,7 @@ namespace AirBomber return map._setAirBomber.Insert(airBomber); } - public static int operator -(MapWithSetAirBomberGeneric map, int position) + public static T operator -(MapWithSetAirBomberGeneric map, int position) { return map._setAirBomber.Remove(position); } diff --git a/AirBomber/AirBomber/SetAirBomberGeneric.cs b/AirBomber/AirBomber/SetAirBomberGeneric.cs index cb25d74..cb41a83 100644 --- a/AirBomber/AirBomber/SetAirBomberGeneric.cs +++ b/AirBomber/AirBomber/SetAirBomberGeneric.cs @@ -27,13 +27,13 @@ namespace AirBomber { if (position < 0 || position >= Count) { - return 0; + return -1; } int emptyPos = -1; if (_places[position] == null) { _places[position] = airBomber; - return 1; + return position; } else { @@ -56,22 +56,23 @@ namespace AirBomber if (emptyPos != -1) { _places[position] = airBomber; - return 1; + return position; } else { - return 0; + return -1; } } - public int Remove(int position) + public T Remove(int position) { if (position < 0 || position >= Count) { - return 0; + return null; } + T elem = _places[position]; _places[position] = null; - return 1; + return elem; } public T Get(int position)