diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index 1b88ac8..1c2eb7e 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -55,7 +55,7 @@ if (form.ShowDialog() == DialogResult.OK) { DrawningObject airplane = new(form.SelectedAirplane); - if (form.SelectedAirplane == null || !(_mapAirplanesCollectionGeneric + airplane)) + if (form.SelectedAirplane == null || (_mapAirplanesCollectionGeneric + airplane) == -1) { MessageBox.Show("Не удалось добавить объект"); } @@ -82,7 +82,7 @@ return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapAirplanesCollectionGeneric - pos) + if (_mapAirplanesCollectionGeneric - pos == -1) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet(); diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs index efe2f6c..3db04b7 100644 --- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs @@ -58,7 +58,7 @@ namespace AirBomber /// /// /// - public static bool operator +(MapWithSetAirplanesGeneric map, T airplane) + public static int operator +(MapWithSetAirplanesGeneric map, T airplane) { return map._setAirplanes.Insert(airplane); } @@ -68,7 +68,7 @@ namespace AirBomber /// /// /// - public static bool operator -(MapWithSetAirplanesGeneric map, int position) + public static int operator -(MapWithSetAirplanesGeneric map, int position) { return map._setAirplanes.Remove(position); } diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 178d798..103ade0 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -33,8 +33,8 @@ namespace AirBomber /// Добавление объекта в набор /// /// Добавляемый самолет - /// - public bool Insert(T airplane) + /// Возвращает позицию вставленого объекта либо -1, если не получилось его добавить + public int Insert(T airplane) { return Insert(airplane, 0); } @@ -48,8 +48,8 @@ namespace AirBomber /// /// Добавляемый самолет /// Позиция - /// - public bool Insert(T airplane, int position) + /// Возвращает позицию вставленого объекта либо -1, если не получилось его добавить + public int Insert(T airplane, int position) { int positionNullElement = position; while (Get(positionNullElement) != null) @@ -59,7 +59,7 @@ namespace AirBomber // Если изначальная позиция была некорректной или пустых элементов справа не оказалось возвращаем false if (!isCorrectPosition(positionNullElement)) { - return false; + return -1; } while (positionNullElement != position) // Смещение вправо { @@ -67,19 +67,19 @@ namespace AirBomber positionNullElement--; } _places[position] = airplane; - return true; + return position; } /// /// Удаление объекта из набора с конкретной позиции /// /// - /// - public bool Remove(int position) + /// Возвращает позицию вставленого объекта либо -1, если не получилось его добавить + public int Remove(int position) { if (!isCorrectPosition(position)) - return false; + return -1; _places[position] = null; - return true; + return position; } /// /// Получение объекта из набора по позиции