From 9f91f903a1b75734c9d664a39ea5130403b77a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=91=D0=B0=D1=82=D1=8B?= =?UTF-8?q?=D0=BB=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Wed, 5 Oct 2022 23:12:18 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs | 2 +- WarmlyShip/WarmlyShip/FormMap.Designer.cs | 5 +- WarmlyShip/WarmlyShip/FormMap.cs | 6 +++ WarmlyShip/WarmlyShip/OceanMap.cs | 56 +++++++++++++++++++++ WarmlyShip/WarmlyShip/RiverMap.cs | 52 +++++++++++++++++++ 5 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/OceanMap.cs create mode 100644 WarmlyShip/WarmlyShip/RiverMap.cs diff --git a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs index d798835..8d7305d 100644 --- a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs @@ -20,7 +20,7 @@ namespace WarmlyShip return; } - Pen pen = new(Color.Black); + Pen pen = new(Color.Black, 2); Brush dopBrush = new SolidBrush(warmlyShip.DopColor); base.DrawTransport(g); diff --git a/WarmlyShip/WarmlyShip/FormMap.Designer.cs b/WarmlyShip/WarmlyShip/FormMap.Designer.cs index 0c5b45a..0c0ad6b 100644 --- a/WarmlyShip/WarmlyShip/FormMap.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormMap.Designer.cs @@ -157,11 +157,14 @@ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта"}); + "Простая карта", + "Карта океана с островами", + "Карта речки c камнями"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); // // FormMap // diff --git a/WarmlyShip/WarmlyShip/FormMap.cs b/WarmlyShip/WarmlyShip/FormMap.cs index 3438a11..017b48f 100644 --- a/WarmlyShip/WarmlyShip/FormMap.cs +++ b/WarmlyShip/WarmlyShip/FormMap.cs @@ -94,6 +94,12 @@ namespace WarmlyShip case "Простая карта": _abstractMap = new SimpleMap(); break; + case "Карта океана с островами": + _abstractMap = new OceanMap(); + break; + case "Карта речки c камнями": + _abstractMap = new RiverMap(); + break; } } } diff --git a/WarmlyShip/WarmlyShip/OceanMap.cs b/WarmlyShip/WarmlyShip/OceanMap.cs new file mode 100644 index 0000000..661b10e --- /dev/null +++ b/WarmlyShip/WarmlyShip/OceanMap.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + /// + /// Простая реализация абсрактного класса AbstractMap + /// + internal class OceanMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.DarkGray); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.LightBlue); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillEllipse(barrierColor, i * (_size_x - 1), j * (_size_y - 1), 40, 24); + } + 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 < 7) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} diff --git a/WarmlyShip/WarmlyShip/RiverMap.cs b/WarmlyShip/WarmlyShip/RiverMap.cs new file mode 100644 index 0000000..2debe6a --- /dev/null +++ b/WarmlyShip/WarmlyShip/RiverMap.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class RiverMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Gray); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.Blue); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + 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 < 30) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +}