From 3e7c3c7f5f82a14538580654cdd303cb046f728d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 2 Nov 2022 09:32:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/FormMapWithSetShip.cs | 4 ++-- .../WarmlyShip/MapWithSetShipGeneric.cs | 2 +- WarmlyShip/WarmlyShip/SetShipGeneric.cs | 24 +++++-------------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs index 3df2a6b..4bece63 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -55,7 +55,7 @@ namespace WarmlyShip if (form.ShowDialog() == DialogResult.OK) { DrawningObjectShip ship = new(form.SelectedShip); - if (_mapShipCollectionGeneric + ship == 1) + if (_mapShipCollectionGeneric + ship > -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); @@ -78,7 +78,7 @@ namespace WarmlyShip return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapShipCollectionGeneric - pos == 1) + if (_mapShipCollectionGeneric - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 8b7019a..c0edbc9 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -32,7 +32,7 @@ namespace WarmlyShip return map._setShips.Insert(ship); } - public static int operator -(MapWithSetShipGeneric map, int position) + public static T operator -(MapWithSetShipGeneric map, int position) { return map._setShips.Remove(position); } diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs index e22a337..1184902 100644 --- a/WarmlyShip/WarmlyShip/SetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -26,25 +26,12 @@ namespace WarmlyShip public int Insert(T ship) { - if (CanInsert(0)) - { - for (int i = _places.Length - 1; i > 0; --i) - { - if (_places[i] == null) - { - _places[i] = _places[i - 1]; - _places[i - 1] = null; - } - } - _places[0] = ship; - return 1; - } - return 0; + return Insert(ship, 0); } public int Insert(T ship, int position) { - if (position < 0 || position > _places.Length) return 0; + if (position < 0 || position > _places.Length) return -1; if (_places[position] != null && CanInsert(position)) { for (int i = _places.Length - 1; i > position; --i) @@ -57,13 +44,14 @@ namespace WarmlyShip } } _places[position] = ship; - return 1; + return position; } - public int Remove(int position) + public T Remove(int position) { + T DelElement = _places[position]; _places[position] = null; - return 1; + return DelElement; } public T Get(int position)