From 59677e8cdaf907cebc048a666e16e2cafce6c980 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Tue, 27 Sep 2022 13:48:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D1=88=D0=B8=D0=B5=D1=81=D1=8F=20?= =?UTF-8?q?2=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B(SeaMap,SwampMap).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Liner/FormMap.cs | 8 ++++++- Liner/Liner/SeaMap.cs | 52 +++++++++++++++++++++++++++++++++++++++++ Liner/Liner/SwampMap.cs | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 Liner/Liner/SeaMap.cs create mode 100644 Liner/Liner/SwampMap.cs diff --git a/Liner/Liner/FormMap.cs b/Liner/Liner/FormMap.cs index d015036..53e5bfd 100644 --- a/Liner/Liner/FormMap.cs +++ b/Liner/Liner/FormMap.cs @@ -105,7 +105,13 @@ namespace Liner case "Простая карта": _abstractMap = new SimpleMap(); break; - + case "Море и айсберги": + _abstractMap = new SeaMap(); + break; + case "Болото": + _abstractMap = new SwampMap(); + break; + } } diff --git a/Liner/Liner/SeaMap.cs b/Liner/Liner/SeaMap.cs new file mode 100644 index 0000000..43b2616 --- /dev/null +++ b/Liner/Liner/SeaMap.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Liner +{ + internal class SeaMap : AbstractMap + { + private readonly Brush barrierColor = new SolidBrush(Color.White); + + 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, 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 < 25) + { + int x = _random.Next(0, 97); + int y = _random.Next(0, 97); + if (_map[x, y] == _freeRoad) + { + _map[x, y + 1] = _barrier; + _map[x + 1, y + 1] = _barrier; + _map[x + 2, y + 1] = _barrier; + _map[x + 1, y] = _barrier; + counter++; + } + } + } + } +} diff --git a/Liner/Liner/SwampMap.cs b/Liner/Liner/SwampMap.cs new file mode 100644 index 0000000..6d19977 --- /dev/null +++ b/Liner/Liner/SwampMap.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Liner +{ + internal class SwampMap : AbstractMap + { + private readonly Brush barrierColor = new SolidBrush(Color.DarkGreen); + + private readonly Brush roadColor = new SolidBrush(Color.AliceBlue); + + 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 < 25) + { + int x = _random.Next(0, 97); + int y = _random.Next(0, 97); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + _map[x + 2, y] = _barrier; + _map[x, y + 2] = _barrier; + counter++; + } + } + } + } +}