diff --git a/Tank/Tank/FormTank.Designer.cs b/Tank/Tank/FormTank.Designer.cs index 0f9e611..4a148c0 100644 --- a/Tank/Tank/FormTank.Designer.cs +++ b/Tank/Tank/FormTank.Designer.cs @@ -173,7 +173,6 @@ Margin = new Padding(3, 4, 3, 4); Name = "FormTank"; Text = "FormTank"; - Load += FormTank_Load; ((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit(); ResumeLayout(false); } diff --git a/Tank/Tank/FormTank.cs b/Tank/Tank/FormTank.cs index 8d1fe16..aae6222 100644 --- a/Tank/Tank/FormTank.cs +++ b/Tank/Tank/FormTank.cs @@ -128,10 +128,5 @@ namespace Tank SelectedTank = _Tank; DialogResult = DialogResult.OK; } - - private void FormTank_Load(object sender, EventArgs e) - { - - } } } \ No newline at end of file diff --git a/Tank/Tank/SetGeneric.cs b/Tank/Tank/SetGeneric.cs index 4488f34..b8c369d 100644 --- a/Tank/Tank/SetGeneric.cs +++ b/Tank/Tank/SetGeneric.cs @@ -9,21 +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 car) { return Insert(car, 0); } + + // Добавление на конкретную позицию public bool Insert(T car, int position) { if (position < 0 || position >= _maxCount) @@ -35,6 +41,7 @@ namespace Tank return true; } + // Удаление объекта из набора с конкретной позиции public bool Remove(int position) { if (position < 0 || position > _maxCount) @@ -44,6 +51,8 @@ namespace Tank _places.RemoveAt(position); return true; } + + // Получение объекта из набора по позиции public T? this[int position] { get @@ -60,18 +69,17 @@ namespace Tank } } - - public IEnumerable GetCars(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; } } } - } } \ No newline at end of file diff --git a/Tank/Tank/TanksGenericCollection.cs b/Tank/Tank/TanksGenericCollection.cs index 27ac758..70c5411 100644 --- a/Tank/Tank/TanksGenericCollection.cs +++ b/Tank/Tank/TanksGenericCollection.cs @@ -95,18 +95,17 @@ namespace Tank.Generics int width = _pictureWidth / _placeSizeWidth; int height = _pictureHeight / _placeSizeHeight; int i = 0; - foreach(var tank in _collection.GetCars()) + foreach(var tank in _collection.GetTanks()) { if (tank != null) { tank._pictureWidth = _pictureWidth; tank._pictureHeight = _pictureHeight; - 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