From f0dd67650aff32a4710608aa3ad47f93967daef5 Mon Sep 17 00:00:00 2001 From: just1valery Date: Wed, 28 Sep 2022 16:56:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B0=20"=D0=9E=D0=BA=D0=B5=D0=B0=D0=BD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/AbstractMap.cs | 1 + WarmlyShip/WarmlyShip/FormMap.Designer.cs | 4 +- WarmlyShip/WarmlyShip/FormMap.cs | 8 +++- WarmlyShip/WarmlyShip/OceanMap.cs | 54 +++++++++++++++++++++++ WarmlyShip/WarmlyShip/SimpleMap.cs | 2 +- 5 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/OceanMap.cs diff --git a/WarmlyShip/WarmlyShip/AbstractMap.cs b/WarmlyShip/WarmlyShip/AbstractMap.cs index cb8f4d9..c0e4cd5 100644 --- a/WarmlyShip/WarmlyShip/AbstractMap.cs +++ b/WarmlyShip/WarmlyShip/AbstractMap.cs @@ -59,6 +59,7 @@ namespace WarmlyShip _drawningObject.MoveObject(MoveObjectBack(direction)); } return DrawMapWithObject(); + } private Direction MoveObjectBack(Direction direction) { diff --git a/WarmlyShip/WarmlyShip/FormMap.Designer.cs b/WarmlyShip/WarmlyShip/FormMap.Designer.cs index 85950b1..7c1068f 100644 --- a/WarmlyShip/WarmlyShip/FormMap.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormMap.Designer.cs @@ -163,11 +163,13 @@ // 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, 28); 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 887873f..766ee90 100644 --- a/WarmlyShip/WarmlyShip/FormMap.cs +++ b/WarmlyShip/WarmlyShip/FormMap.cs @@ -81,8 +81,12 @@ namespace WarmlyShip switch (ComboBoxSelectorMap.Text) { case " ": - _abstractMap = new SimpleMap(); - break; + _abstractMap = new SimpleMap(); + break; + + case "": + _abstractMap = new OceanMap(); + break; } } } diff --git a/WarmlyShip/WarmlyShip/OceanMap.cs b/WarmlyShip/WarmlyShip/OceanMap.cs new file mode 100644 index 0000000..a1e73c6 --- /dev/null +++ b/WarmlyShip/WarmlyShip/OceanMap.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class OceanMap : AbstractMap + { + private readonly Brush barrierColor = new SolidBrush(Color.Gray); + + private readonly Brush roadColor = new SolidBrush(Color.DeepSkyBlue); + + 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)); + 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 < 15) + { + int x = _random.Next(0, 95); + int y = _random.Next(0, 95); + if (_map[x, y] == _freeRoad) + { + _map[x, y + 1] = _barrier; + _map[x, y + 2] = _barrier; + _map[x + 1, y + 1] = _barrier; + _map[x + 2, y + 1] = _barrier; + _map[x + 1, y] = _barrier; + _map[x + 2, y] = _barrier; + counter++; + } + } + } + } +} diff --git a/WarmlyShip/WarmlyShip/SimpleMap.cs b/WarmlyShip/WarmlyShip/SimpleMap.cs index 8c58c62..eb35ab5 100644 --- a/WarmlyShip/WarmlyShip/SimpleMap.cs +++ b/WarmlyShip/WarmlyShip/SimpleMap.cs @@ -38,7 +38,7 @@ namespace WarmlyShip _map[i, j] = _freeRoad; } } - while (counter < 50) + while (counter < 25) { int x = _random.Next(0, 100); int y = _random.Next(0, 100);