From f5df18ed712381727d47ce4b705780ff6bd80eb8 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: Sun, 30 Oct 2022 01:09:29 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WarmlyShip/MapWithSetShipGeneric.cs | 4 +-- WarmlyShip/WarmlyShip/SetShipGeneric.cs | 36 ++----------------- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 655f208..3efe986 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -49,9 +49,9 @@ namespace WarmlyShip public Bitmap ShowOnMap() { Shaking(); - foreach (var car in _setShips.GetShips()) + foreach (var ship in _setShips.GetShips()) { - return _map.CreateMap(_pictureWidth, _pictureHeight, car); + return _map.CreateMap(_pictureWidth, _pictureHeight, ship); } return new(_pictureWidth, _pictureHeight); } diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs index 2740f09..d5d72d1 100644 --- a/WarmlyShip/WarmlyShip/SetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -20,47 +20,15 @@ namespace WarmlyShip _places = new List(); } - private bool CanInsert(int position) - { - for (int i = position; i < Count; ++i) - if (_places[i] == null) return true; - return false; - } - public int Insert(T ship) { - if (CanInsert(0)) - { - for (int i = Count - 1; i > 0; --i) - { - if (_places[i] == null) - { - _places[i] = _places[i - 1]; - _places[i - 1] = null; - } - } - _places[0] = ship; - return 1; - } - return 0; + _places.Insert(0, ship); + return 1; } public int Insert(T ship, int position) { if (position < 0 || position > Count || Count == _maxCount) return 0; - /*if (_places[position] != null && CanInsert(position)) - { - for (int i = _places.Count - 1; i > position; --i) - { - if (_places[i] == null) - { - _places[i] = _places[i - 1]; - _places[i - 1] = null; - } - } - } - _places[position] = ship; - return 1;*/ _places.Insert(position, ship); return 1; }