From 9e7872158eda04c0ed556961d21aeec2e0935f6a Mon Sep 17 00:00:00 2001
From: ksenianeva <95441235+ksenianeva@users.noreply.github.com>
Date: Tue, 4 Oct 2022 00:23:44 +0400
Subject: [PATCH 1/3] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20?=
=?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?=
=?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.=20=D0=9F?=
=?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=BA?=
=?UTF-8?q?=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80?=
=?UTF-8?q?=D1=8B.=20=D0=9F=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD=D1=83?=
=?UTF-8?q?=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
---
.../ContainerShip/DrawingContainerShip.cs | 99 +++++++++++++++++++
ContainerShip/ContainerShip/DrawingShip.cs | 13 ++-
.../ContainerShip/EntityContainerShip.cs | 32 ++++++
ContainerShip/ContainerShip/EntityShip.cs | 2 +-
.../ContainerShip/FormShip.Designer.cs | 15 +++
ContainerShip/ContainerShip/FormShip.cs | 22 ++++-
6 files changed, 173 insertions(+), 10 deletions(-)
create mode 100644 ContainerShip/ContainerShip/DrawingContainerShip.cs
create mode 100644 ContainerShip/ContainerShip/EntityContainerShip.cs
diff --git a/ContainerShip/ContainerShip/DrawingContainerShip.cs b/ContainerShip/ContainerShip/DrawingContainerShip.cs
new file mode 100644
index 0000000..c7718c3
--- /dev/null
+++ b/ContainerShip/ContainerShip/DrawingContainerShip.cs
@@ -0,0 +1,99 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ContainerShip
+{
+ internal class DrawingContainerShip : DrawingShip
+ {
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия обвеса
+ /// Признак наличия антикрыла
+ /// Признак наличия гоночной полосы
+ public DrawingContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) :
+ base(speed, weight, bodyColor)
+ {
+ Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers);
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (Ship is not EntityContainerShip containerShip)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush dopBrush = new SolidBrush(containerShip.DopColor);
+ Pen dopPen = new (containerShip.DopColor);
+
+ base.DrawTransport(g);
+ if (containerShip.Containers)
+ {
+ Point[] container1 =
+ {
+ new Point((int)(_startPosX + 5), (int)(_startPosY + 15)),
+ new Point((int)(_startPosX + 5), (int)(_startPosY + 5)),
+ new Point((int)(_startPosX + 25), (int)_startPosY + 5),
+ new Point((int)_startPosX + 25, (int)_startPosY + 15)
+ };
+
+
+ Point[] container2 =
+ {
+ new Point((int)_startPosX + 40, (int)_startPosY + 15),
+ new Point((int)_startPosX + 40, (int)_startPosY + 5),
+ new Point((int)_startPosX + 75, (int)_startPosY + 5),
+ new Point((int)_startPosX + 75, (int)_startPosY + 15)
+ };
+
+ Point[] container3 =
+ {
+ new Point((int)_startPosX + 16 * 5, (int)_startPosY + 15),
+ new Point((int)_startPosX + 16 * 5, (int)_startPosY + 5),
+ new Point((int)_startPosX + 22 * 5, (int)_startPosY + 5),
+ new Point((int)_startPosX + 22 * 5, (int)_startPosY + 15)
+ };
+
+ Point[] container4 =
+ {
+ new Point((int)_startPosX + 22 * 5, (int)_startPosY + 15),
+ new Point((int)_startPosX + 22 * 5, (int)_startPosY),
+ new Point((int)_startPosX + 26 * 5, (int)_startPosY),
+ new Point((int)_startPosX + 26 * 5, (int)_startPosY + 15)
+ };
+
+ g.FillPolygon(dopBrush, container1);
+ g.DrawPolygon(pen, container1);
+ g.FillPolygon(dopBrush, container2);
+ g.DrawPolygon(pen, container2);
+ g.FillPolygon(dopBrush, container3);
+ g.DrawPolygon(pen, container3);
+ g.FillPolygon(dopBrush, container4);
+ g.DrawPolygon(pen, container4);
+
+
+ }
+
+
+
+
+ if (containerShip.Crane)
+ {
+ g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 15, _startPosX + 8 * 5, _startPosY - 30);
+ g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY - 30);
+ g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY - 25);
+ g.DrawLine(dopPen, _startPosX + 8 * 5 + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY);
+ }
+
+ }
+ }
+}
+
diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs
index 00b6e4c..e11497c 100644
--- a/ContainerShip/ContainerShip/DrawingShip.cs
+++ b/ContainerShip/ContainerShip/DrawingShip.cs
@@ -9,9 +9,9 @@ namespace ContainerShip
{
internal class DrawingShip
{
- public EntityShip Ship { private set; get; }
- private float _startPosX;
- private float _startPosY;
+ public EntityShip Ship { protected set; get; }
+ protected float _startPosX;
+ protected float _startPosY;
private int? _pictureWidth = null;
private int _startPosXInt;
private int _startPosYInt;
@@ -33,10 +33,9 @@ namespace ContainerShip
/// Скорость
/// Вес автомобиля
/// Цвет кузова
- public void Init(int speed, float weight, Color bodyColor)
+ public DrawingShip(int speed, float weight, Color bodyColor)
{
- Ship = new EntityShip();
- Ship.Init(speed, weight, bodyColor);
+ Ship = new EntityShip(speed, weight, bodyColor);
}
/// Координата X
@@ -100,7 +99,7 @@ namespace ContainerShip
/// Отрисовка
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
diff --git a/ContainerShip/ContainerShip/EntityContainerShip.cs b/ContainerShip/ContainerShip/EntityContainerShip.cs
new file mode 100644
index 0000000..816351d
--- /dev/null
+++ b/ContainerShip/ContainerShip/EntityContainerShip.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ContainerShip
+{
+ internal class EntityContainerShip : EntityShip
+ {
+ public Color DopColor { get; private set; }
+ public bool Containers { get; private set; }
+ public bool Crane { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия обвеса
+ /// Признак наличия антикрыла
+ /// Признак наличия гоночной полосы
+ public EntityContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) :
+ base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ Crane = crane;
+ Containers = containers;
+ }
+ }
+}
diff --git a/ContainerShip/ContainerShip/EntityShip.cs b/ContainerShip/ContainerShip/EntityShip.cs
index 15ca4a1..df462f0 100644
--- a/ContainerShip/ContainerShip/EntityShip.cs
+++ b/ContainerShip/ContainerShip/EntityShip.cs
@@ -31,7 +31,7 @@ namespace ContainerShip
///
///
///
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityShip(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
diff --git a/ContainerShip/ContainerShip/FormShip.Designer.cs b/ContainerShip/ContainerShip/FormShip.Designer.cs
index de9ee47..7d6bb68 100644
--- a/ContainerShip/ContainerShip/FormShip.Designer.cs
+++ b/ContainerShip/ContainerShip/FormShip.Designer.cs
@@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.pictureBoxShip = new System.Windows.Forms.PictureBox();
this.ButtonCreate = new System.Windows.Forms.Button();
+ this.ButtonCreateModif = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
this.SuspendLayout();
@@ -142,11 +143,24 @@
this.ButtonCreate.UseVisualStyleBackColor = false;
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
+ // ButtonCreateModif
+ //
+ this.ButtonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.ButtonCreateModif.BackColor = System.Drawing.SystemColors.Window;
+ this.ButtonCreateModif.Location = new System.Drawing.Point(130, 381);
+ this.ButtonCreateModif.Name = "ButtonCreateModif";
+ this.ButtonCreateModif.Size = new System.Drawing.Size(143, 34);
+ this.ButtonCreateModif.TabIndex = 9;
+ this.ButtonCreateModif.Text = "Модификация";
+ this.ButtonCreateModif.UseVisualStyleBackColor = false;
+ this.ButtonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
// FormShip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.ButtonCreateModif);
this.Controls.Add(this.ButtonCreate);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
@@ -177,5 +191,6 @@
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private PictureBox pictureBoxShip;
private Button ButtonCreate;
+ private Button ButtonCreateModif;
}
}
\ No newline at end of file
diff --git a/ContainerShip/ContainerShip/FormShip.cs b/ContainerShip/ContainerShip/FormShip.cs
index 46bfc3c..af5a79a 100644
--- a/ContainerShip/ContainerShip/FormShip.cs
+++ b/ContainerShip/ContainerShip/FormShip.cs
@@ -61,16 +61,34 @@ namespace ContainerShip
Draw();
}
+ private void SetData()
+ {
+ Random rnd = new();
+ _ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
+ toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}";
+ toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}";
+ toolStripStatusLabelBodyColor.Text = $": {_ship.Ship.BodyColor.Name}";
+ }
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _ship = new DrawingShip();
- _ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ _ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}";
toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}";
toolStripStatusLabelBodyColor.Text = $": {_ship.Ship.BodyColor.Name}";
Draw();
}
+
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ Color.FromArgb(rnd.Next(0,256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Convert.ToBoolean(rnd.Next(0,2)), Convert.ToBoolean(rnd.Next(0,2)));
+ SetData();
+ Draw();
+ }
}
}
\ No newline at end of file
--
2.25.1
From fecbbfd46911cce19608bc2f8c60388dc3227603 Mon Sep 17 00:00:00 2001
From: ksenianeva <95441235+ksenianeva@users.noreply.github.com>
Date: Tue, 4 Oct 2022 00:57:48 +0400
Subject: [PATCH 2/3] =?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
---
.../ContainerShip/DrawingObjectShip.cs | 40 +++++++++++++++++++
ContainerShip/ContainerShip/DrawingShip.cs | 9 +++++
ContainerShip/ContainerShip/IDrawingObject.cs | 40 +++++++++++++++++++
3 files changed, 89 insertions(+)
create mode 100644 ContainerShip/ContainerShip/DrawingObjectShip.cs
create mode 100644 ContainerShip/ContainerShip/IDrawingObject.cs
diff --git a/ContainerShip/ContainerShip/DrawingObjectShip.cs b/ContainerShip/ContainerShip/DrawingObjectShip.cs
new file mode 100644
index 0000000..ad486ff
--- /dev/null
+++ b/ContainerShip/ContainerShip/DrawingObjectShip.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ContainerShip
+{
+ internal class DrawingObjectShip : IDrawingObject
+ {
+ private DrawingShip _ship = null;
+
+ public DrawingObjectShip(DrawingShip ship)
+ {
+ _ship = ship;
+ }
+
+ public float Step => _ship?.Ship?.Step ?? 0;
+
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return _ship?.GetCurrentPosition() ?? default;
+ }
+
+ public void MoveObject(Direction direction)
+ {
+ _ship?.MoveTransport(direction);
+ }
+
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _ship.SetPosition(x, y, width, height);
+ }
+
+ void IDrawingObject.DrawingObject(Graphics g)
+ {
+ //TODO
+ }
+ }
+}
diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs
index e11497c..49b7aa4 100644
--- a/ContainerShip/ContainerShip/DrawingShip.cs
+++ b/ContainerShip/ContainerShip/DrawingShip.cs
@@ -155,5 +155,14 @@ namespace ContainerShip
_startPosY = _pictureHeight.Value - _shipHeight;
}
}
+
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight);
+ }
}
}
diff --git a/ContainerShip/ContainerShip/IDrawingObject.cs b/ContainerShip/ContainerShip/IDrawingObject.cs
new file mode 100644
index 0000000..9cc5652
--- /dev/null
+++ b/ContainerShip/ContainerShip/IDrawingObject.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ContainerShip
+{
+ 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 Right, float Top, float Bottom) GetCurrentPosition();
+ }
+}
--
2.25.1
From 4a9cdb125569e763deeb37593a142a3edf51e3ef Mon Sep 17 00:00:00 2001
From: ksenianeva <95441235+ksenianeva@users.noreply.github.com>
Date: Tue, 18 Oct 2022 12:05:10 +0400
Subject: [PATCH 3/3] =?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
---
ContainerShip/ContainerShip/AbstractMap.cs | 121 ++++++++++
ContainerShip/ContainerShip/Direction.cs | 1 +
.../ContainerShip/DrawingContainerShip.cs | 51 ++---
.../ContainerShip/DrawingObjectShip.cs | 12 +-
ContainerShip/ContainerShip/DrawingShip.cs | 12 +-
.../ContainerShip/FormMap.Designer.cs | 212 ++++++++++++++++++
ContainerShip/ContainerShip/FormMap.cs | 102 +++++++++
ContainerShip/ContainerShip/FormMap.resx | 63 ++++++
ContainerShip/ContainerShip/FormShip.cs | 1 +
ContainerShip/ContainerShip/IDrawingObject.cs | 2 +-
ContainerShip/ContainerShip/ModifyMap.cs | 58 +++++
ContainerShip/ContainerShip/Program.cs | 2 +-
ContainerShip/ContainerShip/SimpleMap.cs | 53 +++++
13 files changed, 658 insertions(+), 32 deletions(-)
create mode 100644 ContainerShip/ContainerShip/AbstractMap.cs
create mode 100644 ContainerShip/ContainerShip/FormMap.Designer.cs
create mode 100644 ContainerShip/ContainerShip/FormMap.cs
create mode 100644 ContainerShip/ContainerShip/FormMap.resx
create mode 100644 ContainerShip/ContainerShip/ModifyMap.cs
create mode 100644 ContainerShip/ContainerShip/SimpleMap.cs
diff --git a/ContainerShip/ContainerShip/AbstractMap.cs b/ContainerShip/ContainerShip/AbstractMap.cs
new file mode 100644
index 0000000..22310a9
--- /dev/null
+++ b/ContainerShip/ContainerShip/AbstractMap.cs
@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ContainerShip
+{
+ 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 _freeRoad = 0;
+ protected readonly int _barrier = 1;
+ public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject)
+ {
+ _width = width;
+ _height = height;
+ _drawingObject = drawingObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+ public Bitmap MoveObject(Direction direction)
+ {
+ if (_drawingObject == null) return DrawMapWithObject();
+ bool canMove = true;
+ switch (direction)
+ {
+ case Direction.Left:
+ if (!CheckForBarriers(0, -1 * _drawingObject.Step, -1 * _drawingObject.Step, 0)) canMove = false;
+ break;
+ case Direction.Right:
+ if (!CheckForBarriers(0, _drawingObject.Step, _drawingObject.Step, 0)) canMove = false;
+ break;
+ case Direction.Up:
+ if (!CheckForBarriers(-1 * _drawingObject.Step, 0, 0, -1 * _drawingObject.Step)) canMove = false;
+ break;
+ case Direction.Down:
+ if (!CheckForBarriers(_drawingObject.Step, 0, 0, _drawingObject.Step)) canMove = false;
+ break;
+ }
+ if (canMove)
+ {
+ _drawingObject.MoveObject(direction);
+ }
+ return DrawMapWithObject();
+ }
+ //Вспомогательная функция проверки
+ private bool CheckForBarriers(float topBorder, float rightBorder, float leftBorder, float bottomBorder)
+ {
+ int top = Convert.ToInt32((_drawingObject.GetCurrentPosition().Top + topBorder)/_size_y);
+ int bottom = Convert.ToInt32((_drawingObject.GetCurrentPosition().Bottom + bottomBorder)/_size_y);
+ int right = Convert.ToInt32((_drawingObject.GetCurrentPosition().Right + rightBorder)/_size_x);
+ int left = Convert.ToInt32((_drawingObject.GetCurrentPosition().Left + leftBorder)/_size_x);
+
+ if (left < 0 || top < 0 || right >= _map.GetLength(0) || bottom >= _map.GetLength(1))
+ {
+ return false;
+ }
+
+ for (int i = top; i <= bottom; i++)
+ {
+ for (int j = left; j <= right; j++)
+ {
+ if (_map[j, i] == 1) return false;
+ }
+ }
+ return true;
+ }
+ private bool SetObjectOnMap()
+ {
+ if (_drawingObject == null || _map == null)
+ {
+ return false;
+ }
+ int x = _random.Next(0, 10);
+ int y = _random.Next(0, 10);
+ _drawingObject.SetObject(x, y, _width, _height);
+ if (!CheckForBarriers(0, 0, 0, 0)) return false;
+ return true;
+ }
+ private Bitmap DrawMapWithObject()
+ {
+ Bitmap bmp = new(_width, _height);
+ if (_drawingObject == null || _map == null)
+ {
+ return bmp;
+ }
+ Graphics gr = 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] == _freeRoad)
+ {
+ DrawRoadPart(gr, i, j);
+ }
+ else if (_map[i, j] == _barrier)
+ {
+ DrawBarrierPart(gr, i, j);
+ }
+ }
+ }
+ _drawingObject.DrawingObject(gr);
+ return bmp;
+ }
+
+ protected abstract void GenerateMap();
+ protected abstract void DrawRoadPart(Graphics g, int i, int j);
+ protected abstract void DrawBarrierPart(Graphics g, int i, int j);
+ }
+}
diff --git a/ContainerShip/ContainerShip/Direction.cs b/ContainerShip/ContainerShip/Direction.cs
index 0ab478a..d3661a5 100644
--- a/ContainerShip/ContainerShip/Direction.cs
+++ b/ContainerShip/ContainerShip/Direction.cs
@@ -8,6 +8,7 @@ namespace ContainerShip
{
internal enum Direction
{
+ None = 0,
Up = 1,
Down = 2,
Left = 3,
diff --git a/ContainerShip/ContainerShip/DrawingContainerShip.cs b/ContainerShip/ContainerShip/DrawingContainerShip.cs
index c7718c3..7f3846d 100644
--- a/ContainerShip/ContainerShip/DrawingContainerShip.cs
+++ b/ContainerShip/ContainerShip/DrawingContainerShip.cs
@@ -19,7 +19,7 @@ namespace ContainerShip
/// Признак наличия антикрыла
/// Признак наличия гоночной полосы
public DrawingContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) :
- base(speed, weight, bodyColor)
+ base(speed, weight, bodyColor, 135, 70)
{
Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers);
}
@@ -34,40 +34,45 @@ namespace ContainerShip
Brush dopBrush = new SolidBrush(containerShip.DopColor);
Pen dopPen = new (containerShip.DopColor);
+ _startPosY += 30;
base.DrawTransport(g);
+ _startPosY -= 30;
+ int _startPosYInt = (int)_startPosY;
+ int _startPosXInt = (int)_startPosX;
if (containerShip.Containers)
{
Point[] container1 =
{
- new Point((int)(_startPosX + 5), (int)(_startPosY + 15)),
- new Point((int)(_startPosX + 5), (int)(_startPosY + 5)),
- new Point((int)(_startPosX + 25), (int)_startPosY + 5),
- new Point((int)_startPosX + 25, (int)_startPosY + 15)
+ new Point(_startPosXInt + 5, _startPosYInt + 45),
+ new Point(_startPosXInt + 5, _startPosYInt + 35),
+ new Point(_startPosXInt + 25, _startPosYInt + 35),
+ new Point(_startPosXInt + 25, _startPosYInt + 45)
};
Point[] container2 =
{
- new Point((int)_startPosX + 40, (int)_startPosY + 15),
- new Point((int)_startPosX + 40, (int)_startPosY + 5),
- new Point((int)_startPosX + 75, (int)_startPosY + 5),
- new Point((int)_startPosX + 75, (int)_startPosY + 15)
+ new Point(_startPosXInt + 40, _startPosYInt + 45),
+ new Point(_startPosXInt + 40, _startPosYInt + 35),
+ new Point(_startPosXInt + 75, _startPosYInt + 35),
+ new Point(_startPosXInt + 75, _startPosYInt + 45),
+
};
Point[] container3 =
{
- new Point((int)_startPosX + 16 * 5, (int)_startPosY + 15),
- new Point((int)_startPosX + 16 * 5, (int)_startPosY + 5),
- new Point((int)_startPosX + 22 * 5, (int)_startPosY + 5),
- new Point((int)_startPosX + 22 * 5, (int)_startPosY + 15)
+ new Point(_startPosXInt + 80, _startPosYInt + 45),
+ new Point(_startPosXInt + 80, _startPosYInt + 35),
+ new Point(_startPosXInt + 110, _startPosYInt + 35),
+ new Point(_startPosXInt + 110, _startPosYInt + 45)
};
Point[] container4 =
{
- new Point((int)_startPosX + 22 * 5, (int)_startPosY + 15),
- new Point((int)_startPosX + 22 * 5, (int)_startPosY),
- new Point((int)_startPosX + 26 * 5, (int)_startPosY),
- new Point((int)_startPosX + 26 * 5, (int)_startPosY + 15)
+ new Point(_startPosXInt + 110, _startPosYInt + 30),
+ new Point(_startPosXInt + 110, _startPosYInt + 45),
+ new Point(_startPosXInt + 130, _startPosYInt + 45),
+ new Point(_startPosXInt + 130, _startPosYInt + 30)
};
g.FillPolygon(dopBrush, container1);
@@ -81,16 +86,12 @@ namespace ContainerShip
}
-
-
-
-
if (containerShip.Crane)
{
- g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 15, _startPosX + 8 * 5, _startPosY - 30);
- g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY - 30);
- g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY - 25);
- g.DrawLine(dopPen, _startPosX + 8 * 5 + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY);
+ g.DrawLine(dopPen, _startPosX + 40, _startPosY + 15, _startPosX + 40, _startPosY);
+ g.DrawLine(dopPen, _startPosX + 40, _startPosY, _startPosX + 80, _startPosY);
+ g.DrawLine(dopPen, _startPosX + 40, _startPosY, _startPosX + 80, _startPosY + 5);
+ g.DrawLine(dopPen, _startPosX + 80, _startPosY, _startPosX + 80, _startPosY + 30);
}
}
diff --git a/ContainerShip/ContainerShip/DrawingObjectShip.cs b/ContainerShip/ContainerShip/DrawingObjectShip.cs
index ad486ff..963cbb9 100644
--- a/ContainerShip/ContainerShip/DrawingObjectShip.cs
+++ b/ContainerShip/ContainerShip/DrawingObjectShip.cs
@@ -17,7 +17,7 @@ namespace ContainerShip
public float Step => _ship?.Ship?.Step ?? 0;
- public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
{
return _ship?.GetCurrentPosition() ?? default;
}
@@ -34,7 +34,15 @@ namespace ContainerShip
void IDrawingObject.DrawingObject(Graphics g)
{
- //TODO
+ if (_ship == null) return;
+ if (_ship is DrawingContainerShip ship)
+ {
+ ship.DrawTransport(g);
+ }
+ else
+ {
+ _ship.DrawTransport(g);
+ }
}
}
}
diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs
index 49b7aa4..75b76ad 100644
--- a/ContainerShip/ContainerShip/DrawingShip.cs
+++ b/ContainerShip/ContainerShip/DrawingShip.cs
@@ -22,7 +22,7 @@ namespace ContainerShip
///
/// Ширина отрисовки автомобиля
///
- private readonly int _shipWidth = 120;
+ private readonly int _shipWidth = 135;
///
/// Высота отрисовки автомобиля
///
@@ -38,6 +38,13 @@ namespace ContainerShip
Ship = new EntityShip(speed, weight, bodyColor);
}
+ protected DrawingShip(int speed, float weight, Color bodyColor, int
+ shipWidth, int shipHeight) :
+ this(speed, weight, bodyColor)
+ {
+ _shipWidth = shipWidth;
+ _shipHeight = shipHeight;
+ }
/// Координата X
/// Координата Y
/// Ширина картинки
@@ -129,7 +136,6 @@ namespace ContainerShip
g.DrawLine(pen, _startPosXInt + 30, _startPosYInt + 20, _startPosXInt + 30, _startPosYInt + 30);
g.DrawLine(pen, _startPosXInt + 25, _startPosYInt + 25, _startPosXInt + 35, _startPosYInt + 25);
g.DrawLine(pen, _startPosXInt + 25, _startPosYInt + 30, _startPosXInt + 35, _startPosYInt + 30);
-
}
///
/// Смена границ формы отрисовки
@@ -160,7 +166,7 @@ namespace ContainerShip
/// Получение текущей позиции объекта
///
///
- public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight);
}
diff --git a/ContainerShip/ContainerShip/FormMap.Designer.cs b/ContainerShip/ContainerShip/FormMap.Designer.cs
new file mode 100644
index 0000000..8cdc83f
--- /dev/null
+++ b/ContainerShip/ContainerShip/FormMap.Designer.cs
@@ -0,0 +1,212 @@
+namespace ContainerShip
+{
+ 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.statusStrip1 = 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.buttonRight = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.pictureBoxShip = new System.Windows.Forms.PictureBox();
+ this.ButtonCreate = new System.Windows.Forms.Button();
+ this.ButtonCreateModif = new System.Windows.Forms.Button();
+ this.ComboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.statusStrip1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
+ this.SuspendLayout();
+ //
+ // statusStrip1
+ //
+ this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
+ this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusLabelSpeed,
+ this.toolStripStatusLabelWeight,
+ this.toolStripStatusLabelBodyColor});
+ this.statusStrip1.Location = new System.Drawing.Point(0, 418);
+ this.statusStrip1.Name = "statusStrip1";
+ this.statusStrip1.Size = new System.Drawing.Size(800, 32);
+ this.statusStrip1.TabIndex = 0;
+ this.statusStrip1.Text = "statusStrip1";
+ //
+ // toolStripStatusLabelSpeed
+ //
+ this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
+ this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(93, 25);
+ this.toolStripStatusLabelSpeed.Text = "Скорость:";
+ //
+ // toolStripStatusLabelWeight
+ //
+ this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
+ this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(43, 25);
+ this.toolStripStatusLabelWeight.Text = "Вес:";
+ //
+ // toolStripStatusLabelBodyColor
+ //
+ this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
+ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(55, 25);
+ this.toolStripStatusLabelBodyColor.Text = "Цвет:";
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::ContainerShip.Properties.Resources.LeftArrow;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(738, 353);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(50, 50);
+ this.buttonRight.TabIndex = 2;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::ContainerShip.Properties.Resources.upArrow;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(682, 306);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(50, 50);
+ this.buttonUp.TabIndex = 3;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.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::ContainerShip.Properties.Resources.DownArrow;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(682, 352);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(50, 50);
+ this.buttonDown.TabIndex = 4;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.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::ContainerShip.Properties.Resources.RightArrow;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(626, 353);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(50, 50);
+ this.buttonLeft.TabIndex = 5;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // pictureBoxShip
+ //
+ this.pictureBoxShip.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxShip.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxShip.Name = "pictureBoxShip";
+ this.pictureBoxShip.Size = new System.Drawing.Size(800, 418);
+ this.pictureBoxShip.TabIndex = 7;
+ this.pictureBoxShip.TabStop = false;
+ //
+ // ButtonCreate
+ //
+ this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.ButtonCreate.BackColor = System.Drawing.SystemColors.Window;
+ this.ButtonCreate.Location = new System.Drawing.Point(12, 381);
+ this.ButtonCreate.Name = "ButtonCreate";
+ this.ButtonCreate.Size = new System.Drawing.Size(112, 34);
+ this.ButtonCreate.TabIndex = 8;
+ this.ButtonCreate.Text = "Создать";
+ this.ButtonCreate.UseVisualStyleBackColor = false;
+ this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
+ //
+ // ButtonCreateModif
+ //
+ this.ButtonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.ButtonCreateModif.BackColor = System.Drawing.SystemColors.Window;
+ this.ButtonCreateModif.Location = new System.Drawing.Point(130, 381);
+ this.ButtonCreateModif.Name = "ButtonCreateModif";
+ this.ButtonCreateModif.Size = new System.Drawing.Size(143, 34);
+ this.ButtonCreateModif.TabIndex = 9;
+ this.ButtonCreateModif.Text = "Модификация";
+ this.ButtonCreateModif.UseVisualStyleBackColor = false;
+ this.ButtonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_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(279, 385);
+ this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
+ this.ComboBoxSelectorMap.Size = new System.Drawing.Size(182, 33);
+ this.ComboBoxSelectorMap.TabIndex = 10;
+ this.ComboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged_1);
+ //
+ // FormMap
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.ComboBoxSelectorMap);
+ this.Controls.Add(this.ButtonCreateModif);
+ this.Controls.Add(this.ButtonCreate);
+ this.Controls.Add(this.buttonLeft);
+ this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.buttonUp);
+ this.Controls.Add(this.buttonRight);
+ this.Controls.Add(this.pictureBoxShip);
+ this.Controls.Add(this.statusStrip1);
+ this.Name = "FormMap";
+ this.Text = "Карта";
+ this.Click += new System.EventHandler(this.ButtonMove_Click);
+ this.statusStrip1.ResumeLayout(false);
+ this.statusStrip1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private StatusStrip statusStrip1;
+ private Button buttonRight;
+ private Button buttonUp;
+ private Button buttonDown;
+ private Button buttonLeft;
+ private ToolStripStatusLabel toolStripStatusLabelSpeed;
+ private ToolStripStatusLabel toolStripStatusLabelWeight;
+ private ToolStripStatusLabel toolStripStatusLabelBodyColor;
+ private PictureBox pictureBoxShip;
+ private Button ButtonCreate;
+ private Button ButtonCreateModif;
+ private ComboBox ComboBoxSelectorMap;
+ }
+}
\ No newline at end of file
diff --git a/ContainerShip/ContainerShip/FormMap.cs b/ContainerShip/ContainerShip/FormMap.cs
new file mode 100644
index 0000000..0dedff7
--- /dev/null
+++ b/ContainerShip/ContainerShip/FormMap.cs
@@ -0,0 +1,102 @@
+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 ContainerShip
+{
+ public partial class FormMap : Form
+ {
+ private DrawingShip _ship;
+ private AbstractMap _abstractMap;
+
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+ ///
+ /// Изменение размеров формы
+ ///
+ ///
+ ///
+ private void SetData(DrawingShip ship)
+ {
+ toolStripStatusLabelSpeed.Text = $"Скорость: {ship.Ship.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {ship.Ship.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет: {ship.Ship.BodyColor.Name}";
+ pictureBoxShip.Image = _abstractMap.CreateMap(pictureBoxShip.Width, pictureBoxShip.Height,
+ new DrawingObjectShip(ship));
+ }
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData(ship);
+ }
+ ///
+ /// Изменение размеров формы
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ //получаем имя кнопки
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ Direction dir = Direction.None;
+ switch (name)
+ {
+ case "buttonUp":
+ dir = Direction.Up;
+ break;
+ case "buttonDown":
+ dir = Direction.Down;
+ break;
+ case "buttonLeft":
+ dir = Direction.Left;
+ break;
+ case "buttonRight":
+ dir = Direction.Right;
+ break;
+ }
+ pictureBoxShip.Image = _abstractMap?.MoveObject(dir);
+ }
+ ///
+ /// Обработка нажатия кнопки "Модификация"
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
+ SetData(ship);
+ }
+ ///
+ /// Смена карты
+ ///
+ ///
+ ///
+
+ private void ComboBoxSelectorMap_SelectedIndexChanged_1(object sender, EventArgs e)
+ {
+ switch (ComboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ _abstractMap = new SimpleMap();
+ break;
+ case "Модифицированная карта":
+ _abstractMap = new ModifyMap();
+ break;
+ }
+ }
+ }
+}
diff --git a/ContainerShip/ContainerShip/FormMap.resx b/ContainerShip/ContainerShip/FormMap.resx
new file mode 100644
index 0000000..5cb320f
--- /dev/null
+++ b/ContainerShip/ContainerShip/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/ContainerShip/ContainerShip/FormShip.cs b/ContainerShip/ContainerShip/FormShip.cs
index af5a79a..3fbc50b 100644
--- a/ContainerShip/ContainerShip/FormShip.cs
+++ b/ContainerShip/ContainerShip/FormShip.cs
@@ -90,5 +90,6 @@ namespace ContainerShip
SetData();
Draw();
}
+
}
}
\ No newline at end of file
diff --git a/ContainerShip/ContainerShip/IDrawingObject.cs b/ContainerShip/ContainerShip/IDrawingObject.cs
index 9cc5652..5c50dda 100644
--- a/ContainerShip/ContainerShip/IDrawingObject.cs
+++ b/ContainerShip/ContainerShip/IDrawingObject.cs
@@ -35,6 +35,6 @@ namespace ContainerShip
/// Получение текущей позиции объекта
///
///
- (float Left, float Right, float Top, float Bottom) GetCurrentPosition();
+ (float Left, float Top, float Right, float Bottom) GetCurrentPosition();
}
}
diff --git a/ContainerShip/ContainerShip/ModifyMap.cs b/ContainerShip/ContainerShip/ModifyMap.cs
new file mode 100644
index 0000000..ceda2f4
--- /dev/null
+++ b/ContainerShip/ContainerShip/ModifyMap.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.Metrics;
+using System.Drawing;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ContainerShip
+{
+ internal class ModifyMap : AbstractMap
+ {
+ private readonly Brush barrierColor = new SolidBrush(Color.WhiteSmoke);
+ 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()
+ {
+ Random random = new Random();
+ int firstPointX;
+ int secondPointX;
+ int pointY;
+ _map = new int[100, 100];
+ _size_x = (float)_width / _map.GetLength(0);
+ _size_y = (float)_height / _map.GetLength(1);
+ int counter = 0;
+ while(counter < 15)
+ {
+ bool freePlace = true;
+ firstPointX = random.Next(0, _map.GetLength(0)-10);
+ secondPointX = random.Next(firstPointX, _map.GetLength(0)-10);
+ pointY = random.Next(0, _map.GetLength(1)-10);
+ for(int i = firstPointX; i
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Black);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush roadColor = new SolidBrush(Color.LightBlue);
+
+ 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 < 50)
+ {
+ int x = _random.Next(0, 100);
+ int y = _random.Next(0, 100);
+ if (_map[x, y] == _freeRoad)
+ {
+ _map[x, y] = _barrier;
+ counter++;
+ }
+ }
+ }
+ }
+}
--
2.25.1