From a974a4341e57b60c5047313ba4630426030a8083 Mon Sep 17 00:00:00 2001 From: "nikbel2004@outlook.com" Date: Sun, 29 Oct 2023 00:39:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/Tank/DrawArmoVehicle.cs | 1 - Tank/Tank/SetGeneric.cs | 12 ++++++++++-- Tank/Tank/TanksGenericCollection.cs | 5 ++--- Tank/Tank/TanksGenericStorage.cs | 11 ++++++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Tank/Tank/DrawArmoVehicle.cs b/Tank/Tank/DrawArmoVehicle.cs index 2446515..cfdf93e 100644 --- a/Tank/Tank/DrawArmoVehicle.cs +++ b/Tank/Tank/DrawArmoVehicle.cs @@ -55,7 +55,6 @@ namespace Tank Direction.Right => _startPosX + _Width + Tank.Step < _pictureWidth, Direction.Down => _startPosY + _Height + Tank.Step < _pictureHeight, _ => false - }; } diff --git a/Tank/Tank/SetGeneric.cs b/Tank/Tank/SetGeneric.cs index 5a3d429..234613f 100644 --- a/Tank/Tank/SetGeneric.cs +++ b/Tank/Tank/SetGeneric.cs @@ -9,22 +9,27 @@ namespace Tank { internal class SetGeneric where T : class { + // Список объектов, которые храним и их количество private readonly List _places; public int Count => _places.Count; + // Максимальное количество объектов private readonly int _maxCount; + // Конструктор public SetGeneric(int count) { _maxCount = count; _places = new List(_maxCount); } + // Добавление объекта в набор public bool Insert(T tank) { return Insert(tank, 0); } + // Добавление на конкретную позицию public bool Insert(T tank, int position) { if (position < 0 || position >= _maxCount) @@ -36,6 +41,7 @@ namespace Tank return true; } + // Удаление объекта из набора с конкретной позиции public bool Remove(int position) { if (position < 0 || position > _maxCount) @@ -46,6 +52,7 @@ namespace Tank return true; } + // Получение объекта из набора по позиции public T? this[int position] { get @@ -62,12 +69,13 @@ namespace Tank } } - public IEnumerable GetTanks(int? maxCars = null) + // Проход по списку + public IEnumerable GetTanks(int? maxTanks = null) { for (int i = 0; i < _places.Count; ++i) { yield return _places[i]; - if (maxCars.HasValue && i == maxCars.Value) + if (maxTanks.HasValue && i == maxTanks.Value) { yield break; } diff --git a/Tank/Tank/TanksGenericCollection.cs b/Tank/Tank/TanksGenericCollection.cs index da282e9..5251443 100644 --- a/Tank/Tank/TanksGenericCollection.cs +++ b/Tank/Tank/TanksGenericCollection.cs @@ -99,12 +99,11 @@ namespace Tank.Generics { if (tank != null) { - tank.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight); + tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight); tank.DrawTransport(g); } i++; } } } -} - +} \ No newline at end of file diff --git a/Tank/Tank/TanksGenericStorage.cs b/Tank/Tank/TanksGenericStorage.cs index a5fac2f..f3e4320 100644 --- a/Tank/Tank/TanksGenericStorage.cs +++ b/Tank/Tank/TanksGenericStorage.cs @@ -11,28 +11,37 @@ namespace Tank { internal class TanksGenericStorage { + // Словарь readonly Dictionary> _tankStorages; + + // Возвращение списка названий наборов public List Keys => _tankStorages.Keys.ToList(); private readonly int _pictureWidth; private readonly int _pictureHeight; + + // Конструктор public TanksGenericStorage(int pictureWidth, int pictureHeight) { _tankStorages = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } + + // Добавление набора public void AddSet(string name) { if (_tankStorages.ContainsKey(name)) return; _tankStorages[name] = new TanksGenericCollection(_pictureWidth, _pictureHeight); } + // Удаление набора public void DelSet(string name) { if (!_tankStorages.ContainsKey(name)) return; _tankStorages.Remove(name); } + // Доступ к набору public TanksGenericCollection? this[string ind] { @@ -43,4 +52,4 @@ namespace Tank } } } -} +} \ No newline at end of file