From 6b21c7943957aafb76089f7b1d3ae3ea25099640 Mon Sep 17 00:00:00 2001 From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com> Date: Fri, 4 Nov 2022 11:54:35 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Boats/Boats/DrawingBoat.cs | 5 ++--- Boats/Boats/EntityBoat.cs | 2 +- Boats/Boats/FormBoat.cs | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Boats/Boats/DrawingBoat.cs b/Boats/Boats/DrawingBoat.cs index ca5142b..5b33362 100644 --- a/Boats/Boats/DrawingBoat.cs +++ b/Boats/Boats/DrawingBoat.cs @@ -45,10 +45,9 @@ namespace Boats /// Скорость /// Вес лодки /// Цвет корпуса - public void Init(int speed, float weight, Color bodyColor) + public DrawingBoat(int speed, float weight, Color bodyColor) { - Boat = new EntityBoat(); - Boat.Init(speed, weight, bodyColor); + Boat = new EntityBoat(speed, weight, bodyColor); } /// /// Установка позиции лодки diff --git a/Boats/Boats/EntityBoat.cs b/Boats/Boats/EntityBoat.cs index 8e01db9..0d4ce07 100644 --- a/Boats/Boats/EntityBoat.cs +++ b/Boats/Boats/EntityBoat.cs @@ -34,7 +34,7 @@ namespace Boats /// /// /// - public void Init(int speed, float weight, Color bodyColor) + public EntityBoat(int speed, float weight, Color bodyColor) { Random rnd = new(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/Boats/Boats/FormBoat.cs b/Boats/Boats/FormBoat.cs index 44d3490..f858665 100644 --- a/Boats/Boats/FormBoat.cs +++ b/Boats/Boats/FormBoat.cs @@ -35,8 +35,7 @@ namespace Boats private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _boat = new DrawingBoat(); - _boat.Init( + _boat = new DrawingBoat( rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), -- 2.25.1 From b3426afea9f3c5db06a292a9979e0a3374b29143 Mon Sep 17 00:00:00 2001 From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com> Date: Fri, 4 Nov 2022 13:12:14 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Boats/Boats/DrawingBoat.cs | 26 +++++++--- Boats/Boats/DrawingCatamaran.cs | 82 ++++++++++++++++++++++++++++++++ Boats/Boats/EntityCatamaran.cs | 41 ++++++++++++++++ Boats/Boats/FormBoat.Designer.cs | 14 ++++++ Boats/Boats/FormBoat.cs | 45 ++++++++++++++---- 5 files changed, 193 insertions(+), 15 deletions(-) create mode 100644 Boats/Boats/DrawingCatamaran.cs create mode 100644 Boats/Boats/EntityCatamaran.cs diff --git a/Boats/Boats/DrawingBoat.cs b/Boats/Boats/DrawingBoat.cs index 5b33362..fb44500 100644 --- a/Boats/Boats/DrawingBoat.cs +++ b/Boats/Boats/DrawingBoat.cs @@ -14,15 +14,15 @@ namespace Boats /// /// Класс-сущность /// - public EntityBoat Boat { private set; get; } + public EntityBoat Boat { protected set; get; } /// /// Левая координата отрисовки лодки /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки лодки /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -34,11 +34,11 @@ namespace Boats /// /// Ширина отрисовки лодки /// - private readonly int _boatWidth = 100; + protected readonly int _boatWidth = 100; /// /// Высота отрисовки лодки /// - private readonly int _boatHeight = 40; + protected readonly int _boatHeight = 40; /// /// Инициализация свойств /// @@ -50,6 +50,20 @@ namespace Boats Boat = new EntityBoat(speed, weight, bodyColor); } /// + /// Инициализация свойств + /// + /// Скорость + /// Вес лодки + /// Цвет корпуса + /// Ширина отрисовки лодки + /// Высота отрисовки лодки + protected DrawingBoat(int speed, float weight, Color bodyColor, int boatWidth, int boatHeight) : + this(speed, weight, bodyColor) + { + _boatWidth = boatWidth; + _boatHeight = boatHeight; + } + /// /// Установка позиции лодки /// /// Координата X @@ -113,7 +127,7 @@ namespace Boats /// Отрисовка лодки /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/Boats/Boats/DrawingCatamaran.cs b/Boats/Boats/DrawingCatamaran.cs new file mode 100644 index 0000000..9e9142a --- /dev/null +++ b/Boats/Boats/DrawingCatamaran.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + /// + /// Класс для отрисовки катамарана + /// + internal class DrawingCatamaran : DrawingBoat + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес катамарана + /// Цвет корпуса + /// Дополнительный цвет + /// Признак наличия поплавков + /// Признак наличия паруса + public DrawingCatamaran(int speed, float weight, Color bodyColor, + Color dopColor, bool bobbers, bool sail) : + base(speed, weight, bodyColor, 110, 60) + { + Boat = new EntityCatamaran(speed, weight, bodyColor, dopColor, bobbers, sail); + } + /// + /// Метод для отрисовки катамарана + /// + /// + public override void DrawTransport(Graphics g) + { + if (Boat is not EntityCatamaran catamaran) + { + return; + } + Brush dopBrush = new SolidBrush(catamaran.DopColor); + + int bobbersWidth = _boatWidth / 4; + int bobbersHeight = _boatHeight / 5; + + base.DrawTransport(g); + + if (catamaran.Bobbers) + { + // Отрисовка верхних поплавков + g.FillRectangle(dopBrush, _startPosX, _startPosY, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX, _startPosY, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight); + + g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight); + + // Отрисовка нижних поплавков + g.FillRectangle(dopBrush, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight); + + g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight); + } + + if (catamaran.Sail) + { + float downPointSailX = _startPosX + _boatWidth / 2 - _boatWidth / 8; + float downPointSailY = _startPosY + _boatHeight / 2 + _boatWidth / 8; + + PointF[] sailPoints = new PointF[3]; + sailPoints[0] = new PointF(downPointSailX, downPointSailY); + sailPoints[1] = new PointF(downPointSailX, _startPosY); + sailPoints[2] = new PointF(downPointSailX - _boatWidth / 4, downPointSailY - _boatHeight / 4); + // Отрисовка паруса + g.FillPolygon(dopBrush, sailPoints); + g.DrawPolygon(Pens.Black, sailPoints); + } + } + } +} diff --git a/Boats/Boats/EntityCatamaran.cs b/Boats/Boats/EntityCatamaran.cs new file mode 100644 index 0000000..4569a7f --- /dev/null +++ b/Boats/Boats/EntityCatamaran.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + internal class EntityCatamaran : EntityBoat + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия поплавков + /// + public bool Bobbers { get; private set; } + /// + /// Признак наличия паруса + /// + public bool Sail { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес катамарана + /// Цвет корпуса + /// Дополнительный цвет + /// Признак наличия поплавков + /// Признак наличия паруса + public EntityCatamaran(int speed, float weight, Color bodyColor, + Color dopColor, bool bobbers, bool sail) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Bobbers = bobbers; + Sail = sail; + } + } +} diff --git a/Boats/Boats/FormBoat.Designer.cs b/Boats/Boats/FormBoat.Designer.cs index d17c12d..e7e7ab0 100644 --- a/Boats/Boats/FormBoat.Designer.cs +++ b/Boats/Boats/FormBoat.Designer.cs @@ -38,6 +38,7 @@ this.ButtonLeft = new System.Windows.Forms.Button(); this.ButtonRight = new System.Windows.Forms.Button(); this.ButtonDown = new System.Windows.Forms.Button(); + this.ButtonCreateModificate = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -143,11 +144,23 @@ this.ButtonDown.UseVisualStyleBackColor = true; this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click); // + // ButtonCreateModificate + // + this.ButtonCreateModificate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonCreateModificate.Location = new System.Drawing.Point(138, 381); + this.ButtonCreateModificate.Name = "ButtonCreateModificate"; + this.ButtonCreateModificate.Size = new System.Drawing.Size(117, 29); + this.ButtonCreateModificate.TabIndex = 7; + this.ButtonCreateModificate.Text = "Модификация"; + this.ButtonCreateModificate.UseVisualStyleBackColor = true; + this.ButtonCreateModificate.Click += new System.EventHandler(this.ButtonCreateModificate_Click); + // // FormBoat // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ButtonCreateModificate); this.Controls.Add(this.ButtonDown); this.Controls.Add(this.ButtonRight); this.Controls.Add(this.ButtonLeft); @@ -177,5 +190,6 @@ private Button ButtonLeft; private Button ButtonRight; private Button ButtonDown; + private Button ButtonCreateModificate; } } \ No newline at end of file diff --git a/Boats/Boats/FormBoat.cs b/Boats/Boats/FormBoat.cs index f858665..2599211 100644 --- a/Boats/Boats/FormBoat.cs +++ b/Boats/Boats/FormBoat.cs @@ -18,6 +18,22 @@ namespace Boats InitializeComponent(); } /// + /// Метод установки данных + /// + private void SetData() + { + Random rnd = new Random(); + _boat.SetPosition( + rnd.Next(10, 100), + rnd.Next(10, 100), + pictureBoxBoat.Width, + pictureBoxBoat.Height + ); + toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}"; + } + /// /// Метод прорисовки лодки /// private void Draw() @@ -41,15 +57,7 @@ namespace Boats Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)) ); - _boat.SetPosition( - rnd.Next(10, 100), - rnd.Next(10, 100), - pictureBoxBoat.Width, - pictureBoxBoat.Height - ); - toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}"; + SetData(); Draw(); } /// @@ -88,5 +96,24 @@ namespace Boats _boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height); Draw(); } + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + private void ButtonCreateModificate_Click(object sender, EventArgs e) + { + Random rnd = new Random(); + _boat = new DrawingCatamaran( + rnd.Next(100, 300), + rnd.Next(1000, 3000), + Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), + Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), + Convert.ToBoolean(rnd.Next(0, 2)), + Convert.ToBoolean(rnd.Next(0, 2)) + ); + SetData(); + Draw(); + } } } -- 2.25.1 From 52f9190f2fad132eb3b766ef4ac7d274c332df40 Mon Sep 17 00:00:00 2001 From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com> Date: Fri, 4 Nov 2022 13:34:29 +0400 Subject: [PATCH 3/4] =?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=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Boats/Boats/DrawingBoat.cs | 10 +++++++- Boats/Boats/DrawingObjectBoat.cs | 34 ++++++++++++++++++++++++++ Boats/Boats/IDrawingObject.cs | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 Boats/Boats/DrawingObjectBoat.cs create mode 100644 Boats/Boats/IDrawingObject.cs diff --git a/Boats/Boats/DrawingBoat.cs b/Boats/Boats/DrawingBoat.cs index fb44500..e9b3975 100644 --- a/Boats/Boats/DrawingBoat.cs +++ b/Boats/Boats/DrawingBoat.cs @@ -154,7 +154,7 @@ namespace Boats g.DrawEllipse(Pens.Black, _startPosX + _boatWidth / 8, _startPosY + _boatHeight / 8, _boatWidth / 2, _boatHeight - _boatHeight / 4); } - /// + /// /// Смена границ формы отрисовки /// /// Ширина картинки @@ -178,5 +178,13 @@ namespace Boats _startPosY = _pictureHeight.Value - _boatHeight; } } + /// + /// Получение текущей позиции объекта + /// + /// + public (float Left, float Top, float Right, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _boatWidth, _startPosY + _boatHeight); + } } } diff --git a/Boats/Boats/DrawingObjectBoat.cs b/Boats/Boats/DrawingObjectBoat.cs new file mode 100644 index 0000000..5ca71f6 --- /dev/null +++ b/Boats/Boats/DrawingObjectBoat.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + internal class DrawingObjectBoat : IDrawingObject + { + private DrawingBoat _boat = null; + public DrawingObjectBoat(DrawingBoat boat) + { + _boat = boat; + } + public float Step => _boat?.Boat?.Step ?? 0; + public (float Left, float Top, float Right, float Bottom) GetCurrentPosition() + { + return _boat?.GetCurrentPosition() ?? default; + } + public void MoveObject(Direction direction) + { + _boat?.MoveTransport(direction); + } + public void SetObject(int x, int y, int width, int height) + { + _boat.SetPosition(x, y, width, height); + } + public void DrawingObject(Graphics g) + { + _boat.DrawTransport(g); + } + } +} diff --git a/Boats/Boats/IDrawingObject.cs b/Boats/Boats/IDrawingObject.cs new file mode 100644 index 0000000..8ba69e3 --- /dev/null +++ b/Boats/Boats/IDrawingObject.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + /// + /// Интерфейс для работы с объектом, прорисовываемым на форме + /// + internal interface IDrawingObject + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawingObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + (float Left, float Top, float Right, float Bottom) GetCurrentPosition(); + } +} -- 2.25.1 From 9569218404d26fd18912bd75f1305c08135b1b4b Mon Sep 17 00:00:00 2001 From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com> Date: Fri, 4 Nov 2022 14:26:09 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=90=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Boats/Boats/AbstractMap.cs | 200 ++++++++++++++++++++++++++++++ Boats/Boats/Direction.cs | 1 + Boats/Boats/FormMap.Designer.cs | 211 ++++++++++++++++++++++++++++++++ Boats/Boats/FormMap.cs | 126 +++++++++++++++++++ Boats/Boats/FormMap.resx | 63 ++++++++++ Boats/Boats/LineMap.cs | 92 ++++++++++++++ Boats/Boats/OceanMap.cs | 90 ++++++++++++++ Boats/Boats/Program.cs | 2 +- Boats/Boats/SimpleMap.cs | 70 +++++++++++ 9 files changed, 854 insertions(+), 1 deletion(-) create mode 100644 Boats/Boats/AbstractMap.cs create mode 100644 Boats/Boats/FormMap.Designer.cs create mode 100644 Boats/Boats/FormMap.cs create mode 100644 Boats/Boats/FormMap.resx create mode 100644 Boats/Boats/LineMap.cs create mode 100644 Boats/Boats/OceanMap.cs create mode 100644 Boats/Boats/SimpleMap.cs diff --git a/Boats/Boats/AbstractMap.cs b/Boats/Boats/AbstractMap.cs new file mode 100644 index 0000000..dfa1b1b --- /dev/null +++ b/Boats/Boats/AbstractMap.cs @@ -0,0 +1,200 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + internal abstract class AbstractMap + { + private IDrawingObject _drawingObject = null; + protected int[,] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected readonly Random _random = new(); + protected readonly int _freeWater = 0; + protected readonly int _barrier = 1; + /// + /// Функция инициализирует карту, + /// устанавливает объект и отрисовывает карту с объектом + /// + /// + /// + /// + /// Bitmap карты с объектом + public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject) + { + _width = width; + _height = height; + _drawingObject = drawingObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + /// + /// Функция для передвижения объекта по карте + /// + /// + /// Bitmap карты с объектом + public Bitmap MoveObject(Direction direction) + { + // Проверка, что объект может переместится в требуемом направлении + // Получаем текщую позицию объекта + var objectPos = _drawingObject.GetCurrentPosition(); + float currentX = objectPos.Left; + float currentY = objectPos.Top; + + // В зависимости от направления уставналиваем dx, dy + float dx = 0; + float dy = 0; + switch (direction) + { + case Direction.None: + break; + case Direction.Up: + { + dy = -_drawingObject.Step; + } + break; + case Direction.Down: + { + dy = _drawingObject.Step; + } + break; + case Direction.Left: + { + dx = -_drawingObject.Step; + } + break; + case Direction.Right: + { + dx = _drawingObject.Step; + } + break; + default: + break; + } + // ЕСли нет коллизии, то перемещаем объект + if (!CheckCollision(currentX + dx, currentY + dy)) + { + _drawingObject.MoveObject(direction); + } + return DrawMapWithObject(); + } + /// + /// Функция пытается поместить объект на карту + /// + /// Если удачно возвращает true, иначе - false + private bool SetObjectOnMap() + { + if (_drawingObject == null || _map == null) + { + return false; + } + // Генерируем новые координаты объекта + int x = _random.Next(100, 200); + int y = _random.Next(100, 200); + _drawingObject.SetObject(x, y, _width, _height); + + // Проверка, что объект не "накладывается" на закрытые участки + return !CheckCollision(x, y); + } + /// + /// Функция для проверки коллизии объекта с препятствиями на карте. + /// + /// Координата x объекта + /// Координата y объекта + /// Возвращает true если есть коллизия и false - если ее нет + protected bool CheckCollision(float x, float y) + { + // Получаем ширину и высоту отображаемого объекта + var objectPos = _drawingObject.GetCurrentPosition(); + float objectWidth = objectPos.Right - objectPos.Left; + float objectHeight = objectPos.Bottom - objectPos.Top; + + // Теперь узнаем сколько клеток в ширину и высоту объект занимает на карте + int objectCellsCountX = (int)Math.Ceiling(objectWidth / _size_x); + int objectCellsCountY = (int)Math.Ceiling(objectHeight / _size_y); + + // Получим координаты объекта в сетке карты + int objectMapX = (int)Math.Floor((float)x / _size_x); + int objectMapY = (int)Math.Floor((float)y / _size_y); + + // В цикле проверяем все клетки карты на коллизию с объектом + int dy = 0; + int mapCellsX = _map.GetLength(1); + int mapCellsY = _map.GetLength(0); + int mapState = _freeWater; + + while (objectMapY + dy < mapCellsY && dy <= objectCellsCountY) + { + int dx = 0; + while (objectMapX + dx < mapCellsX && dx <= objectCellsCountX) + { + mapState = _map[objectMapX + dx, objectMapY + dy]; + if (mapState == _barrier) + { + return true; + } + dx++; + } + dy++; + } + return false; + } + /// + /// Функция для отрисовки карты с объектом + /// + /// + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + if (_drawingObject == null || _map == null) + { + return bmp; + } + Graphics g = Graphics.FromImage(bmp); + + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (_map[i, j] == _freeWater) + { + DrawWaterPart(g, i, j); + } + else if (_map[i, j] == _barrier) + { + DrawBarrierPart(g, i, j); + } + } + } + _drawingObject.DrawingObject(g); + return bmp; + } + /// + /// Метод для генерации карты + /// + protected abstract void GenerateMap(); + /// + /// Метод для отрисовки свободного участка на экране + /// + /// + /// + /// + protected abstract void DrawWaterPart(Graphics g, int i, int j); + /// + /// Метод для отрисовки закрытого участка на экране + /// + /// + /// + /// + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + } +} diff --git a/Boats/Boats/Direction.cs b/Boats/Boats/Direction.cs index 36fa672..0c4d00a 100644 --- a/Boats/Boats/Direction.cs +++ b/Boats/Boats/Direction.cs @@ -11,6 +11,7 @@ namespace Boats /// internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/Boats/Boats/FormMap.Designer.cs b/Boats/Boats/FormMap.Designer.cs new file mode 100644 index 0000000..ae9e3ce --- /dev/null +++ b/Boats/Boats/FormMap.Designer.cs @@ -0,0 +1,211 @@ +namespace Boats +{ + partial class FormMap + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBoxMap = new System.Windows.Forms.PictureBox(); + this.statusStrip = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.ButtonCreate = new System.Windows.Forms.Button(); + this.ButtonUp = new System.Windows.Forms.Button(); + this.ButtonLeft = new System.Windows.Forms.Button(); + this.ButtonRight = new System.Windows.Forms.Button(); + this.ButtonDown = new System.Windows.Forms.Button(); + this.ButtonCreateModificate = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxMap)).BeginInit(); + this.statusStrip.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxMap + // + this.pictureBoxMap.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxMap.Location = new System.Drawing.Point(0, 0); + this.pictureBoxMap.Name = "pictureBoxMap"; + this.pictureBoxMap.Size = new System.Drawing.Size(800, 424); + this.pictureBoxMap.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxMap.TabIndex = 0; + this.pictureBoxMap.TabStop = false; + // + // statusStrip + // + this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip.Location = new System.Drawing.Point(0, 424); + this.statusStrip.Name = "statusStrip"; + this.statusStrip.Size = new System.Drawing.Size(800, 26); + this.statusStrip.TabIndex = 1; + this.statusStrip.Text = "statusStrip1"; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20); + this.toolStripStatusLabelSpeed.Text = "Скорость:"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20); + this.toolStripStatusLabelWeight.Text = "Вес:"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20); + this.toolStripStatusLabelBodyColor.Text = "Цвет:"; + // + // ButtonCreate + // + this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonCreate.Location = new System.Drawing.Point(12, 381); + this.ButtonCreate.Name = "ButtonCreate"; + this.ButtonCreate.Size = new System.Drawing.Size(94, 29); + this.ButtonCreate.TabIndex = 2; + this.ButtonCreate.Text = "Создать"; + this.ButtonCreate.UseVisualStyleBackColor = true; + this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // ButtonUp + // + this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonUp.BackgroundImage = global::Boats.Properties.Resources.arrow_up; + this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonUp.Location = new System.Drawing.Point(710, 344); + this.ButtonUp.Name = "ButtonUp"; + this.ButtonUp.Size = new System.Drawing.Size(30, 30); + this.ButtonUp.TabIndex = 3; + this.ButtonUp.UseVisualStyleBackColor = true; + this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonLeft + // + this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonLeft.BackgroundImage = global::Boats.Properties.Resources.arrow_left; + this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonLeft.Location = new System.Drawing.Point(674, 380); + this.ButtonLeft.Name = "ButtonLeft"; + this.ButtonLeft.Size = new System.Drawing.Size(30, 30); + this.ButtonLeft.TabIndex = 4; + this.ButtonLeft.UseVisualStyleBackColor = true; + this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonRight + // + this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRight.BackgroundImage = global::Boats.Properties.Resources.arrow_right; + this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonRight.Location = new System.Drawing.Point(746, 380); + this.ButtonRight.Name = "ButtonRight"; + this.ButtonRight.Size = new System.Drawing.Size(30, 30); + this.ButtonRight.TabIndex = 5; + this.ButtonRight.UseVisualStyleBackColor = true; + this.ButtonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonDown + // + this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonDown.BackgroundImage = global::Boats.Properties.Resources.arrow_down; + this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.ButtonDown.Location = new System.Drawing.Point(710, 380); + this.ButtonDown.Name = "ButtonDown"; + this.ButtonDown.Size = new System.Drawing.Size(30, 30); + this.ButtonDown.TabIndex = 6; + this.ButtonDown.UseVisualStyleBackColor = true; + this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // ButtonCreateModificate + // + this.ButtonCreateModificate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonCreateModificate.Location = new System.Drawing.Point(138, 381); + this.ButtonCreateModificate.Name = "ButtonCreateModificate"; + this.ButtonCreateModificate.Size = new System.Drawing.Size(117, 29); + this.ButtonCreateModificate.TabIndex = 7; + this.ButtonCreateModificate.Text = "Модификация"; + this.ButtonCreateModificate.UseVisualStyleBackColor = true; + this.ButtonCreateModificate.Click += new System.EventHandler(this.ButtonCreateModificate_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + 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); + this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // + // FormMap + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.ButtonCreateModificate); + this.Controls.Add(this.ButtonDown); + this.Controls.Add(this.ButtonRight); + this.Controls.Add(this.ButtonLeft); + this.Controls.Add(this.ButtonUp); + this.Controls.Add(this.ButtonCreate); + this.Controls.Add(this.pictureBoxMap); + this.Controls.Add(this.statusStrip); + this.Name = "FormMap"; + this.Text = "Лодка"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxMap)).EndInit(); + this.statusStrip.ResumeLayout(false); + this.statusStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxMap; + private StatusStrip statusStrip; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private Button ButtonCreate; + private Button ButtonUp; + private Button ButtonLeft; + private Button ButtonRight; + private Button ButtonDown; + private Button ButtonCreateModificate; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/Boats/Boats/FormMap.cs b/Boats/Boats/FormMap.cs new file mode 100644 index 0000000..169273a --- /dev/null +++ b/Boats/Boats/FormMap.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Boats +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + /// + /// Метод установки данных + /// + private void SetData(DrawingBoat boat) + { + toolStripStatusLabelSpeed.Text = $"Скорость: {boat.Boat.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {boat.Boat.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {boat.Boat.BodyColor.Name}"; + pictureBoxMap.Image = _abstractMap.CreateMap(pictureBoxMap.Width, pictureBoxMap.Height, + new DrawingObjectBoat(boat)); + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var boat = new DrawingBoat( + rnd.Next(100, 300), + rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), + rnd.Next(0, 256), rnd.Next(0, 256)) + ); + SetData(boat); + } + /// + /// Обработчик нажатий кнопок передвижения + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + //получаем имя кнопки + string btnName = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + + switch (btnName) + { + case "ButtonUp": + { + dir = Direction.Up; + } + break; + case "ButtonDown": + { + dir = Direction.Down; + } + break; + case "ButtonLeft": + { + dir = Direction.Left; + } + break; + case "ButtonRight": + { + dir = Direction.Right; + } + break; + default: + break; + } + pictureBoxMap.Image = _abstractMap?.MoveObject(dir); + } + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + private void ButtonCreateModificate_Click(object sender, EventArgs e) + { + Random rnd = new Random(); + + var boat = new DrawingCatamaran( + rnd.Next(100, 300), + rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), + Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), + Convert.ToBoolean(rnd.Next(0, 2)), + Convert.ToBoolean(rnd.Next(0, 2)) + ); + SetData(boat); + } + /// + /// Смена карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + case "Океан карта": + _abstractMap = new OceanMap(); + break; + case "Линии карта": + _abstractMap = new LineMap(); + break; + } + } + } +} diff --git a/Boats/Boats/FormMap.resx b/Boats/Boats/FormMap.resx new file mode 100644 index 0000000..2c0949d --- /dev/null +++ b/Boats/Boats/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Boats/Boats/LineMap.cs b/Boats/Boats/LineMap.cs new file mode 100644 index 0000000..0e85857 --- /dev/null +++ b/Boats/Boats/LineMap.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + /// + /// Класс линейной карты + /// + internal class LineMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.White); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.Black); + /// + /// Метод для отрисовки закрытого участка карты + /// + /// + /// + /// + 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 DrawWaterPart(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); + + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeWater; + } + } + // Будем рисовать линии + // из непроходимых блоков + int counter = 0; + while (counter < 20) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + + int lineLength = 5; + + if (_map[x, y] == _freeWater) + { + int d = 0; + if (Convert.ToBoolean(_random.Next(0, 2))) + { + while (y + d < _map.GetLength(0) && d < lineLength * 2) + { + _map[x, y + d] = _barrier; + d++; + } + } + else + { + while (x + d < _map.GetLength(1) && d < lineLength) + { + _map[x + d, y] = _barrier; + d++; + } + } + counter++; + } + } + } + } +} diff --git a/Boats/Boats/OceanMap.cs b/Boats/Boats/OceanMap.cs new file mode 100644 index 0000000..fc7f85d --- /dev/null +++ b/Boats/Boats/OceanMap.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + /// + /// Класс океанической карты + /// + internal class OceanMap : AbstractMap + { + /// + /// Количество мин воруг центральной мины + /// + private readonly int minesAroundCount = 6; + /// + /// Количество центральных мин + /// + private readonly int circlesCount = 12; + /// + /// Цвет участка закрытого + /// + private readonly Brush mineColor = Brushes.Silver; + /// + /// Цвет участка открытого + /// + private readonly Brush openColor = Brushes.Aqua; + /// + /// Метод для отрисовки закрытого участка карты + /// + /// + /// + /// + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(openColor, i * _size_x, j * _size_y, _size_x, _size_y); + g.FillEllipse(mineColor, i * _size_x, j * _size_y, _size_x, _size_y); + g.FillEllipse(Brushes.Black, i * _size_x + _size_x * 0.25f, j * _size_y + _size_y * 0.25f, _size_x * 0.5f, _size_y * 0.5f); + g.FillEllipse(Brushes.Red, i * _size_x + _size_x * 0.375f, j * _size_y + _size_y * 0.375f, _size_x * 0.25f, _size_y * 0.25f); + } + /// + /// Метод для отрисовки открытого участка карты + /// + /// + /// + /// + protected override void DrawWaterPart(Graphics g, int i, int j) + { + g.FillRectangle(openColor, 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] = _freeWater; + } + } + // Отрисовка "мин" + double radius = Math.Min(_size_x, _size_y); + while (counter < circlesCount) + { + int x = _random.Next(0, 99); + int y = _random.Next(0, 99); + _map[y, x] = _barrier; + for (int i = 0; i < minesAroundCount; i++) + { + int row = (int)Math.Ceiling(radius * Math.Sin(Math.PI * 2 / minesAroundCount * i)) + y; + int col = (int)Math.Ceiling(radius * Math.Cos(Math.PI * 2 / minesAroundCount * i)) + x; + + if (row > -1 && col > -1 && row < _map.GetLength(0) && col < _map.GetLength(1)) + { + _map[row, col] = _barrier; + } + } + counter++; + } + } + } +} diff --git a/Boats/Boats/Program.cs b/Boats/Boats/Program.cs index e4a9a17..45769f2 100644 --- a/Boats/Boats/Program.cs +++ b/Boats/Boats/Program.cs @@ -11,7 +11,7 @@ namespace Boats // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormBoat()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/Boats/Boats/SimpleMap.cs b/Boats/Boats/SimpleMap.cs new file mode 100644 index 0000000..93c5db3 --- /dev/null +++ b/Boats/Boats/SimpleMap.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + /// + /// Класс стандартной карты + /// + internal class SimpleMap : 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, _size_x, _size_y); + } + /// + /// Метод для отрисовки открытого участка карты + /// + /// + /// + /// + protected override void DrawWaterPart(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] = _freeWater; + } + } + while (counter < 50) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeWater) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} -- 2.25.1