From dfa874b91feb0a2dd799d44f3b21d03b07d20f98 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 29 Oct 2023 22:25:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20TODO,=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 1 - AirBomber/AirBomber/FormPlaneCollection.cs | 7 ++-- .../AirBomber/PlanesGenericCollection.cs | 28 ++++++-------- AirBomber/AirBomber/PlanesGenericStorage.cs | 18 +++++++-- AirBomber/AirBomber/SetGeneric.cs | 37 ++++--------------- 5 files changed, 38 insertions(+), 53 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index ba2b1e2..4308f24 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -274,6 +274,5 @@ namespace AirBomber /// public IMoveableObject GetMoveableObject => new DrawningObjectAirPlane(this); - } } diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs index 9754cce..8646a07 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.cs @@ -45,10 +45,9 @@ namespace AirBomber /// /// /// - private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e) + private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e) { - pictureBoxCollection.Image = - _storage[listBoxStorages.SelectedItem?.ToString()?? string.Empty]?.ShowPlanes(); + pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString()?? string.Empty]?.ShowPlanes(); } /// @@ -70,7 +69,7 @@ namespace AirBomber FormAirBomber form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (obj + form.SelectedPlane != -1) + if (obj + form.SelectedPlane > -1) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowPlanes(); diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs index 80ca3bb..b9950a1 100644 --- a/AirBomber/AirBomber/PlanesGenericCollection.cs +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -103,15 +103,13 @@ namespace AirBomber Pen pen = new(Color.Black, 3); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + - 1; ++j) - {//линия рамзетки места + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { + //линия рамзетки места g.DrawLine(pen, i * _placeSizeWidth, j * - _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * - _placeSizeHeight); + _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * - _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); } } /// @@ -121,18 +119,16 @@ namespace AirBomber private void DrawObjects(Graphics g) { int widthObjCount = _pictureWidth / _placeSizeWidth; - int i = 0; - foreach (var plane in _collection.GetPlanes()) + for (int i = 0; i < _collection.Count; i++) { + T? type = _collection[i]; + if (type != null) { - if (plane != null) - { - int row = i / widthObjCount; - int col = widthObjCount - 1 - (i % widthObjCount); + int row = i / widthObjCount; + int col = widthObjCount - 1 - (i % widthObjCount); - plane.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight); - plane?.DrawPlane(g); - } + type.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight); + type?.DrawPlane(g); } } } diff --git a/AirBomber/AirBomber/PlanesGenericStorage.cs b/AirBomber/AirBomber/PlanesGenericStorage.cs index 0526f7e..40918b3 100644 --- a/AirBomber/AirBomber/PlanesGenericStorage.cs +++ b/AirBomber/AirBomber/PlanesGenericStorage.cs @@ -41,7 +41,11 @@ namespace AirBomber /// Название набора public void AddSet(string name) { - // TODO Прописать логику для добавления + // TODO Прописать логику для добавления DONE + if (!_planeStorages.ContainsKey(name)) + { + _planeStorages.Add(name, new PlanesGenericCollection(_pictureWidth, _pictureHeight)); + } } /// /// Удаление набора @@ -49,7 +53,11 @@ namespace AirBomber /// Название набора public void DelSet(string name) { - // TODO Прописать логику для удаления + // TODO Прописать логику для удаления DONE + if (_planeStorages.ContainsKey(name)) + { + _planeStorages.Remove(name); + } } /// /// Доступ к набору @@ -61,7 +69,11 @@ namespace AirBomber { get { - // TODO Продумать логику получения набора + // TODO Продумать логику получения набора DONE + if (_planeStorages.ContainsKey(ind)) + { + return _planeStorages[ind]; + } return null; } } diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs index e899acd..ca8d15b 100644 --- a/AirBomber/AirBomber/SetGeneric.cs +++ b/AirBomber/AirBomber/SetGeneric.cs @@ -53,32 +53,9 @@ namespace AirBomber // проверка, что после вставляемого элемента в массиве есть пустой элемент // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента // TODO вставка по позиции - int NoEmpty = 0, temp = 0; - for (int i = position; i < Count; i++) - { - if (_places[i] != null) NoEmpty++; - } - if (NoEmpty == Count - position) return -1; - - if (position < Count && position >= 0) - { - for (int j = position; j < Count; j++) - { - if (_places[j] == null) - { - temp = j; - break; - } - } - - for (int i = temp; i > position; i--) - { - _places[i] = _places[i - 1]; - } - _places[position] = plane; - return position; - } - return -1; + if (position < 0 || position >= _maxCount) return -1; + _places.Insert(position, plane); + return position; } /// /// Удаление объекта из набора с конкретной позиции @@ -114,9 +91,11 @@ namespace AirBomber } set { - // TODO проверка позиции - // TODO проверка свободных мест в списке - // TODO вставка в список по позиции + // TODO проверка позиции DONE + // TODO проверка свободных мест в списке DONE + // TODO вставка в список по позиции DONE + if (position < 0 || position >= Count || Count == _maxCount) return; + _places.Insert(position, value); } } ///