From 453c7c79c4274241e19ef0da14f3bf69be002ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Thu, 13 Oct 2022 15:06:06 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=20?= =?UTF-8?q?=D1=82=D0=B8=D0=BF=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=D0=BE=D0=B3=D0=BE=20=D0=B7=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/FormMapWithSetAirplanes.cs | 11 ++++------ .../AirBomber/MapWithSetAirplanesGeneric.cs | 4 ++-- AirBomber/AirBomber/SetAirplanesGeneric.cs | 21 ++++++++++--------- 3 files changed, 17 insertions(+), 19 deletions(-) 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; } /// /// Получение объекта из набора по позиции