From aae1f51ef5ec2ad8d12ef889da0c375b958e1fda Mon Sep 17 00:00:00 2001 From: Anastasia Date: Tue, 1 Nov 2022 12:40:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B5=D1=89=D0=B5=20=D0=BE=D0=B4=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B=20+=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneWithRadar/AbstractMap.cs | 5 +- .../AirplaneWithRadar/BlockMap.cs | 80 +++++++++++++++++++ .../AirplaneWithRadar/FormMap.Designer.cs | 3 +- .../AirplaneWithRadar/FormMap.cs | 7 +- .../{MyMap.cs => LineMap.cs} | 2 +- 5 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 AirplaneWithRadar/AirplaneWithRadar/BlockMap.cs rename AirplaneWithRadar/AirplaneWithRadar/{MyMap.cs => LineMap.cs} (98%) diff --git a/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs b/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs index ea02d63..30d189f 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs @@ -81,7 +81,10 @@ namespace AirplaneWithRadar { for (int j = left; j <= right; j++) { - if (_map[j, i] == 1) return false; + if (_map[j, i] == 1) + { + return false; + } } } return true; diff --git a/AirplaneWithRadar/AirplaneWithRadar/BlockMap.cs b/AirplaneWithRadar/AirplaneWithRadar/BlockMap.cs new file mode 100644 index 0000000..2c920c7 --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/BlockMap.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + internal class BlockMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Beige); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.LightBlue); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * (_size_x + 1), (j + 1) * (_size_y + 1)); + + } + + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int block = 0; + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + _map[i, j] = _freeRoad; + } + } + int numberBlocks = _random.Next(10, 15); + while (block < numberBlocks) + { + int x = _random.Next(0, 80); + int y = _random.Next(0, 80); + int blockWidth = _random.Next(0, 19); + int blockHeight = _random.Next(0, 19); + + bool isFree = true; + for (int i = x; i < x + blockWidth; i++) + { + for (int j = y; j < y + blockHeight; j++) + { + if (_map[i, j] != _freeRoad) + { + isFree = false; + break; + } + + } + } + if (isFree) + { + for (int i = x; i < x + blockWidth; i++) + { + for (int j = y; j < y + blockHeight; j++) + { + _map[i, j] = _barrier; + } + } + block++; + } + } + } + } +} diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMap.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMap.Designer.cs index 977ebcf..aa2bb3e 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormMap.Designer.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMap.Designer.cs @@ -159,7 +159,8 @@ this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { "Простая карта", - "Собственная карта"}); + "Карта с линиями", + "Карта с блоками"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(182, 33); diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMap.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMap.cs index 9313a2d..49f17cc 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormMap.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMap.cs @@ -93,8 +93,11 @@ namespace AirplaneWithRadar case "Простая карта": _abstractMap = new SimpleMap(); break; - case "Собственная карта": - _abstractMap = new MyMap(); + case "Карта с линиями": + _abstractMap = new LineMap(); + break; + case "Карта с блоками": + _abstractMap = new BlockMap(); break; } } diff --git a/AirplaneWithRadar/AirplaneWithRadar/MyMap.cs b/AirplaneWithRadar/AirplaneWithRadar/LineMap.cs similarity index 98% rename from AirplaneWithRadar/AirplaneWithRadar/MyMap.cs rename to AirplaneWithRadar/AirplaneWithRadar/LineMap.cs index 06ce687..f26f73d 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/MyMap.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/LineMap.cs @@ -9,7 +9,7 @@ namespace AirplaneWithRadar /// /// Собственная реализация абсрактного класса AbstractMap /// - internal class MyMap : AbstractMap + internal class LineMap : AbstractMap { /// /// Цвет участка закрытого