diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs
index 91e1a56..8d2b54e 100644
--- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs
+++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs
@@ -121,7 +121,7 @@ namespace AirBomber
{
MessageBox.Show(text, caption);
}
- else if (!(_mapsCollection[NameMap] + airplane))
+ else if ((_mapsCollection[NameMap] + airplane) == -1)
{
MessageBox.Show("Не удалось добавить объект");
}
@@ -239,17 +239,14 @@ namespace AirBomber
///
private void ButtonRemoveAirplane_Click(object sender, EventArgs e)
{
- if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text))
- {
- return;
- }
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text)
+ || MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
var deletedObject = _mapsCollection[NameMap, pos];
- if (_mapsCollection[NameMap] - pos)
+ if (_mapsCollection[NameMap] - pos != null)
{
MessageBox.Show("Объект удален");
_deletedObjects.AddLast(deletedObject);
diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs
index 5228e27..46ee9e8 100644
--- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs
+++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs
@@ -55,7 +55,7 @@ namespace AirBomber
///
///
///
- public static bool operator +(MapWithSetAirplanesGeneric map, T airplane)
+ public static int operator +(MapWithSetAirplanesGeneric map, T airplane)
{
return map.SetAirplanes.Insert(airplane);
}
@@ -65,7 +65,7 @@ namespace AirBomber
///
///
///
- public static bool operator -(MapWithSetAirplanesGeneric map, int position)
+ public static T operator -(MapWithSetAirplanesGeneric map, int position)
{
return map.SetAirplanes.Remove(position);
}
diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs
index 8577377..fffa285 100644
--- a/AirBomber/AirBomber/SetAirplanesGeneric.cs
+++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs
@@ -36,8 +36,8 @@ namespace AirBomber
/// Добавление объекта в набор
///
/// Добавляемый самолет
- ///
- public bool Insert(T airplane)
+ /// Возвращает позицию вставленого объекта либо -1, если не получилось его добавить
+ public int Insert(T airplane)
{
return Insert(airplane, 0);
}
@@ -51,27 +51,28 @@ namespace AirBomber
///
/// Добавляемый самолет
/// Позиция
- ///
- public bool Insert(T airplane, int position)
+ /// Возвращает позицию вставленого объекта либо -1, если не получилось его добавить
+ public int Insert(T airplane, int position)
{
if (!isCorrectPosition(position))
{
- return false;
+ return -1;
}
_places.Insert(position, airplane);
- return true;
+ return position;
}
///
/// Удаление объекта из набора с конкретной позиции
///
///
- ///
- public bool Remove(int position)
+ /// Возвращает удаленный объект, либо null если его не удалось удалить
+ public T Remove(int position)
{
if (!isCorrectPosition(position) || position >= Count)
- return false;
+ return null;
+ var deletedObj = _places[position];
_places.RemoveAt(position);
- return true;
+ return deletedObj;
}
///
/// Получение объекта из набора по позиции