From a761e843c9777a81e14e707ae0005889ed529e44 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sun, 2 Oct 2022 18:48:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5,=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5,=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapWithSetAntiAircraftGunsGeneric.cs | 30 ++++++----- .../SetAntiAircraftGunsGeneric.cs | 51 ++++++++++++++----- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs index a877ef6..ae58bf9 100644 --- a/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs +++ b/AntiAircraftGun/AntiAircraftGun/MapWithSetAntiAircraftGunsGeneric.cs @@ -26,7 +26,7 @@ namespace AntiAircraftGun /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 210; + private readonly int _placeSizeWidth = 150; /// /// Размер занимаемого объектом места (высота) /// @@ -58,7 +58,7 @@ namespace AntiAircraftGun /// Перегрузка оператора сложения /// /// - /// + /// /// public static bool operator +(MapWithSetAntiAircraftGunsGeneric map, T antiAircraftGuns) { @@ -83,7 +83,7 @@ namespace AntiAircraftGun Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); DrawBackground(gr); - DrawCars(gr); + DrawAntiAircraftGuns(gr); return bmp; } /// @@ -95,10 +95,10 @@ namespace AntiAircraftGun Shaking(); for (int i = 0; i < _setAntiAircraftGuns.Count; i++) { - var car = _setAntiAircraftGuns.Get(i); - if (car != null) + var antiAircraftGun = _setAntiAircraftGuns.Get(i); + if (antiAircraftGun != null) { - return _map.CreateMap(_pictureWidth, _pictureHeight, car); + return _map.CreateMap(_pictureWidth, _pictureHeight, antiAircraftGun); } } return new(_pictureWidth, _pictureHeight); @@ -128,10 +128,10 @@ namespace AntiAircraftGun { for (; j > i; j--) { - var car = _setAntiAircraftGuns.Get(j); - if (car != null) + var antiAircraftGun = _setAntiAircraftGuns.Get(j); + if (antiAircraftGun != null) { - _setAntiAircraftGuns.Insert(car, i); + _setAntiAircraftGuns.Insert(antiAircraftGun, i); _setAntiAircraftGuns.Remove(j); break; } @@ -150,20 +150,22 @@ namespace AntiAircraftGun private void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); + Brush brushGreen = new SolidBrush(Color.Green); + Brush brushLightGray = new SolidBrush(Color.LightGray); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) - {//линия рамзетки места - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + for (int j = 0; j < _pictureHeight / _placeSizeHeight; ++j) + { + g.FillRectangle(brushGreen, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth, _placeSizeHeight); + g.FillRectangle(brushLightGray, i * _placeSizeWidth + _placeSizeWidth / 10, j * _placeSizeHeight + _placeSizeHeight / 10, _placeSizeWidth * 8 / 10, _placeSizeHeight * 8 / 10); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } } /// /// Метод прорисовки объектов /// /// - private void DrawCars(Graphics g) + private void DrawAntiAircraftGuns(Graphics g) { for (int i = 0; i < _setAntiAircraftGuns.Count; i++) { diff --git a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs index 1f4fa88..56639ce 100644 --- a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs +++ b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs @@ -32,12 +32,21 @@ namespace AntiAircraftGun /// /// Добавление объекта в набор /// - /// Добавляемый автомобиль + /// Добавляемый автомобиль /// public bool Insert(T antiAircraftGun) { // TODO вставка в начало набора - return true; + if (_places[Count - 1] == null) + { + for(int i = Count - 1; i > 0; i--) + { + _places[i] = _places[i - 1]; + } + _places[0] = antiAircraftGun; + return true; + } + return false; } /// /// Добавление объекта в набор на конкретную позицию @@ -47,13 +56,25 @@ namespace AntiAircraftGun /// public bool Insert(T antiAircraftGun, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - // TODO вставка по позиции - _places[position] = antiAircraftGun; - return true; + if (position < 0 || position >= Count) return false; + if (_places[position] == null) + { + _places[position] = antiAircraftGun; + return true; + } + else + { + if (_places[Count - 1] == null) + { + for (int i = Count - 1; i > position; i--) + { + _places[i] = _places[i - 1]; + } + _places[position] = antiAircraftGun; + return true; + } + return false; + } } /// /// Удаление объекта из набора с конкретной позиции @@ -62,9 +83,13 @@ namespace AntiAircraftGun /// public bool Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присовив элементу массива значение null - return true; + if (position < 0 || position >= Count) return false; + if (_places[position] != null) + { + _places[position] = null; + return true; + } + return false; } /// /// Получение объекта из набора по позиции @@ -73,7 +98,7 @@ namespace AntiAircraftGun /// public T Get(int position) { - // TODO проверка позиции + if (position < 0 || position >= Count) return null; return _places[position]; } }