From 187957395ea947ec5216dfcdfead61933583412b Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Tue, 18 Oct 2022 16:19:04 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BC=D0=B5=D0=BD=D0=B0=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B8=D0=B2=D0=B0=20=D0=BD=D0=B0=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Warship/Warship/MapWithSetWarshipsGeneric.cs | 19 ++++----- Warship/Warship/SetWarshipsGeneric.cs | 41 ++++++++++++++++---- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/Warship/Warship/MapWithSetWarshipsGeneric.cs b/Warship/Warship/MapWithSetWarshipsGeneric.cs index deec30f..aa751fd 100644 --- a/Warship/Warship/MapWithSetWarshipsGeneric.cs +++ b/Warship/Warship/MapWithSetWarshipsGeneric.cs @@ -49,13 +49,9 @@ namespace Warship public Bitmap ShowOnMap() { Shaking(); - for (int i = 0; i < _setWarship.Count; i++) + foreach(var warship in _setWarship.GetWarships()) { - var warship = _setWarship.Get(i); - if (warship != null) - { - return _map.CreateMap(_pictureWidth, _pictureHeight, warship); - } + return _map.CreateMap(_pictureWidth, _pictureHeight, warship); } return new(_pictureWidth, _pictureHeight); } @@ -74,11 +70,11 @@ namespace Warship int j = _setWarship.Count - 1; for (int i = 0; i < _setWarship.Count; i++) { - if (_setWarship.Get(i) == null) + if (_setWarship[i] == null) { for (; j > i; j--) { - var warship = _setWarship.Get(j); + var warship = _setWarship[j]; if (warship != null) { _setWarship.Insert(warship, i); @@ -111,15 +107,16 @@ namespace Warship private void DrawWarship(Graphics gr) { + //todo int width = _pictureWidth / _placeSizeWidth; int height = _pictureHeight / _placeSizeHeight; for (int i = 0; i < _setWarship.Count; i++) { - if (_setWarship.Get(i) != null) + if (_setWarship[i] != null) { - _setWarship.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight); - _setWarship.Get(i)?.DrawingObject(gr); + _setWarship[i].SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight); + _setWarship[i]?.DrawingObject(gr); } } } diff --git a/Warship/Warship/SetWarshipsGeneric.cs b/Warship/Warship/SetWarshipsGeneric.cs index ac9c126..d523774 100644 --- a/Warship/Warship/SetWarshipsGeneric.cs +++ b/Warship/Warship/SetWarshipsGeneric.cs @@ -9,22 +9,27 @@ namespace Warship internal class SetWarshipsGeneric where T : class { - private readonly T[] _places; + private readonly List _places; - public int Count => _places.Length; + public int Count => _places.Count; + + private readonly int _maxCount; public SetWarshipsGeneric(int count) { - _places = new T[count]; + _maxCount = count; + _places = new List(); } public int Insert(T warship) { + //todo return Insert(warship,0); } public int Insert(T warship, int position) { + //todo int EmptyEl=-1; if (position>=Count || position < 0) @@ -58,6 +63,7 @@ namespace Warship public T Remove(int position) { + //todo if (position >= Count || position < 0 || _places[position]==null) return null; @@ -66,12 +72,31 @@ namespace Warship return deleted; } - public T Get(int position) + public T this[int position] { - if (position >= Count || position < 0) - return null; - - return _places[position]; + get + { + //todo + return _places[position]; + } + set + { + //todo + } + } + public IEnumerable GetWarships() + { + foreach(var warship in _places) + { + if (warship != null) + { + yield return warship; + } + else + { + yield break; + } + } } } }