From 521d4750dea15d0fe52685126db6aaef9ee78ae7 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 22 Oct 2023 14:05:39 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2?= =?UTF-8?q?=20PlanesGenericCollection=20&=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20SetGeneric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/PlanesGenericCollection.cs | 20 ++++++++++--------- AirBomber/AirBomber/SetGeneric.cs | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs index 5d4cbf8..80ca3bb 100644 --- a/AirBomber/AirBomber/PlanesGenericCollection.cs +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -65,7 +65,7 @@ namespace AirBomber /// public static bool operator -(PlanesGenericCollection collect, int pos) { - T? obj = collect._collection.Get(pos); + T? obj = collect._collection[pos]; if (obj != null) { collect._collection.Remove(pos); @@ -80,7 +80,7 @@ namespace AirBomber /// public U? GetU(int pos) { - return (U?)_collection.Get(pos)?.GetMoveableObject; + return (U?)_collection[pos]?.GetMoveableObject; } /// /// Вывод всего набора объектов @@ -121,16 +121,18 @@ namespace AirBomber private void DrawObjects(Graphics g) { int widthObjCount = _pictureWidth / _placeSizeWidth; - for (int i = 0; i < _collection.Count; i++) + int i = 0; + foreach (var plane in _collection.GetPlanes()) { - T? type = _collection.Get(i); - if (type != null) { - int row = i / widthObjCount; - int col = widthObjCount - 1 - (i % widthObjCount); + if (plane != null) + { + int row = i / widthObjCount; + int col = widthObjCount - 1 - (i % widthObjCount); - type.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight); - type?.DrawPlane(g); + plane.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight); + plane?.DrawPlane(g); + } } } } diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs index 1188285..e899acd 100644 --- a/AirBomber/AirBomber/SetGeneric.cs +++ b/AirBomber/AirBomber/SetGeneric.cs @@ -123,12 +123,12 @@ namespace AirBomber /// Проход по списку /// /// - public IEnumerable GetCars(int? maxCars = null) + public IEnumerable GetPlanes(int? maxPlanes = null) { for (int i = 0; i < _places.Count; ++i) { yield return _places[i]; - if (maxCars.HasValue && i == maxCars.Value) + if (maxPlanes.HasValue && i == maxPlanes.Value) { yield break; }