From b740601834486a7f0ee898bc10901395a6d47f70 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 26 Sep 2022 22:07:05 +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=B0=20=D0=BA=D0=B0=D1=80=D1=82=D0=B0=20=D1=81=20=D1=80?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D1=81=D0=B0=D0=BC=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/FormMap.Designer.cs | 3 +- Locomotive/Locomotive/FormMap.cs | 3 ++ Locomotive/Locomotive/RailroadMap.cs | 62 +++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Locomotive/Locomotive/RailroadMap.cs diff --git a/Locomotive/Locomotive/FormMap.Designer.cs b/Locomotive/Locomotive/FormMap.Designer.cs index f3b9c62..e885489 100644 --- a/Locomotive/Locomotive/FormMap.Designer.cs +++ b/Locomotive/Locomotive/FormMap.Designer.cs @@ -160,7 +160,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(151, 28); diff --git a/Locomotive/Locomotive/FormMap.cs b/Locomotive/Locomotive/FormMap.cs index bfd3a2f..4333523 100644 --- a/Locomotive/Locomotive/FormMap.cs +++ b/Locomotive/Locomotive/FormMap.cs @@ -89,6 +89,9 @@ namespace Locomotive case "Карта с шипами": _abstractMap = new SpikeMap(); break; + case "Карта с рельсами": + _abstractMap = new RailroadMap(); + break; } } diff --git a/Locomotive/Locomotive/RailroadMap.cs b/Locomotive/Locomotive/RailroadMap.cs new file mode 100644 index 0000000..f532e07 --- /dev/null +++ b/Locomotive/Locomotive/RailroadMap.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class RailroadMap : AbstractMap + { + /// Цвет участка закрытого + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// Цвет участка открытого + private readonly Brush roadColor = new SolidBrush(Color.Gray); + + 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 * (_size_x + + 1), j * (_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 counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 1) + { + int y = _random.Next(0, 95); + + for(int x = 0; x < 99; x++) + { + _map[x, y] = _barrier; + _map[x, y + 5] = _barrier; + + if (x % 5 == 0) + { + _map[x, y + 1] = _barrier; + _map[x, y + 2] = _barrier; + _map[x, y + 3] = _barrier; + _map[x, y + 4] = _barrier; + } + } + counter += 1; + } + } + } +}