From ff1d888ee60432f6c17cd3b45c4a25d9d7096721 Mon Sep 17 00:00:00 2001
From: IlyasValiulov <148232695+IlyasValiulov@users.noreply.github.com>
Date: Sat, 17 Feb 2024 22:27:24 +0400
Subject: [PATCH 1/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=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB?=
=?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE?=
=?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?=
=?UTF-8?q?=D0=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../{ => Drawnings}/DirectionType.cs | 2 +-
.../DrawningShip.cs} | 129 ++++++++----------
.../Drawnings/DrawningWarmlyShip.cs | 49 +++++++
.../ProjectWarmlyShip/Entities/EntityShip.cs | 34 +++++
.../Entities/EntityWarmlyShip.cs | 29 ++++
.../ProjectWarmlyShip/EntityWarmlyShip.cs | 51 -------
.../FormWarmlyShip.Designer.cs | 21 ++-
.../ProjectWarmlyShip/FormWarmlyShip.cs | 69 +++++++---
8 files changed, 235 insertions(+), 149 deletions(-)
rename ProjectWarmlyShip/ProjectWarmlyShip/{ => Drawnings}/DirectionType.cs (90%)
rename ProjectWarmlyShip/ProjectWarmlyShip/{DrawningWarmlyShip.cs => Drawnings/DrawningShip.cs} (51%)
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/Entities/EntityShip.cs
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/Entities/EntityWarmlyShip.cs
delete mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/EntityWarmlyShip.cs
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/DirectionType.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DirectionType.cs
similarity index 90%
rename from ProjectWarmlyShip/ProjectWarmlyShip/DirectionType.cs
rename to ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DirectionType.cs
index 07d8193..80c84f9 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/DirectionType.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DirectionType.cs
@@ -1,4 +1,4 @@
-namespace ProjectWarmlyShip;
+namespace ProjectWarmlyShip.Drawnings;
///
/// Направления при перемещении
///
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/DrawningWarmlyShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs
similarity index 51%
rename from ProjectWarmlyShip/ProjectWarmlyShip/DrawningWarmlyShip.cs
rename to ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs
index 1f5f2dc..fa543cd 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/DrawningWarmlyShip.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs
@@ -1,11 +1,13 @@
-namespace ProjectWarmlyShip;
+using ProjectWarmlyShip.Entities;
-public class DrawningWarmlyShip
+namespace ProjectWarmlyShip.Drawnings;
+
+public class DrawningShip
{
///
/// Класс-сущность
///
- public EntityWarmlyShip? EntityWarmlyShip { get; private set; }
+ public EntityShip? EntityShip { get; protected set; }
///
/// Ширина окна
@@ -20,12 +22,12 @@ public class DrawningWarmlyShip
///
/// Левая координата прорисовки
///
- private int? _startPosX;
+ protected int? _startPosX;
///
/// Верхняя кооридната прорисовки
///
- private int? _startPosY;
+ protected int? _startPosY;
///
/// Ширина прорисовки
@@ -35,26 +37,37 @@ public class DrawningWarmlyShip
///
/// Высота прорисовки
///
- private int _drawningShipHeight = 140;
-
+ private int _drawningShipHeight = 80;
///
- /// Инициализация свойств
+ /// Пустой конструктор
///
- ///
- ///
- ///
- ///
- ///
- ///
- public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, bool shpipipes, bool fueltank)
+ private DrawningShip()
{
- EntityWarmlyShip = new EntityWarmlyShip();
- EntityWarmlyShip.Init(speed, weight, bodycolor, additionalcolor, shpipipes, fueltank);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public DrawningShip(int speed, double weight, Color bodycolor) : this()
+ {
+ EntityShip = new EntityShip(speed, weight, bodycolor);
+ }
+ ///
+ /// Конструктор для наследования
+ ///
+ ///
+ ///
+ protected DrawningShip(int _drawningShipWidth, int _drawnShipHeight) : this()
+ {
+ this._drawningShipWidth= _drawningShipWidth;
+ this._drawningShipHeight = _drawnShipHeight;
+ }
public bool SetPictureSize(int width, int height)
{
// TODO проверка, что объект "влезает" в размеры поля
@@ -105,7 +118,7 @@ public class DrawningWarmlyShip
}
public bool MoveTransport(DirectionType direction)
{
- if (EntityWarmlyShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
@@ -113,32 +126,32 @@ public class DrawningWarmlyShip
{
//влево
case DirectionType.Left:
- if (_startPosX.Value - EntityWarmlyShip.Step > 0)
+ if (_startPosX.Value - EntityShip.Step > 0)
{
- _startPosX -= (int)EntityWarmlyShip.Step;
+ _startPosX -= (int)EntityShip.Step;
}
return true;
//вверх
case DirectionType.Up:
- if (_startPosY.Value - EntityWarmlyShip.Step > 0)
+ if (_startPosY.Value - EntityShip.Step > 0)
{
- _startPosY -= (int)EntityWarmlyShip.Step;
+ _startPosY -= (int)EntityShip.Step;
}
return true;
// вправо
case DirectionType.Right:
- if (_startPosX.Value + _drawningShipWidth + EntityWarmlyShip.Step < _pictureWidth)
+ if (_startPosX.Value + _drawningShipWidth + EntityShip.Step < _pictureWidth)
{
- _startPosX += (int)EntityWarmlyShip.Step;
+ _startPosX += (int)EntityShip.Step;
}
return true;
//вниз
case DirectionType.Down:
- if (_startPosY.Value + _drawningShipHeight + EntityWarmlyShip.Step < _pictureHeight)
+ if (_startPosY.Value + _drawningShipHeight + EntityShip.Step < _pictureHeight)
{
- _startPosY += (int)EntityWarmlyShip.Step;
+ _startPosY += (int)EntityShip.Step;
}
- return true;
+ return true;
default:
return false;
}
@@ -147,58 +160,24 @@ public class DrawningWarmlyShip
/// Отрисовка объекта
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
- if (EntityWarmlyShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
- Pen pen = new(Color.Black , 5);
-
- //трубы
- Brush brush = new SolidBrush(EntityWarmlyShip.AdditionalColor);
- if (EntityWarmlyShip.ShipPipes)
+ Pen pen = new(Color.Black, 5);
+ //надстройка
+ Brush brush = new SolidBrush(EntityShip.BodyColor);
+ g.FillRectangle(brush, _startPosX.Value + 30, _startPosY.Value, 100, 30);
+ //корпус
+ g.FillPolygon(brush, new Point[]
{
- g.FillRectangle(brush, _startPosX.Value + 70, _startPosY.Value, 12, 60);
- g.FillRectangle(brush, _startPosX.Value + 90, _startPosY.Value, 12, 60);
- //надстройка
- brush = new SolidBrush(EntityWarmlyShip.BodyColor);
- g.FillRectangle(brush, _startPosX.Value + 30, _startPosY.Value + 60, 100, 30);
- //корпус
- g.FillPolygon(brush, new Point[]
- {
- new Point(_startPosX.Value,_startPosY.Value + 90), new Point(_startPosX.Value + 150, _startPosY.Value + 90),
- new Point(_startPosX.Value + 150, _startPosY.Value + 90), new Point(_startPosX.Value + 120,_startPosY.Value + 140),
- new Point(_startPosX.Value + 120,_startPosY.Value + 140), new Point(_startPosX.Value + 30,_startPosY.Value + 140),
- new Point(_startPosX.Value + 30,_startPosY.Value + 140), new Point(_startPosX.Value,_startPosY.Value + 90),
- });
- _drawningShipHeight = 140;
- }
- else
- {
- //надстройка
- brush = new SolidBrush(EntityWarmlyShip.BodyColor);
- g.FillRectangle(brush, _startPosX.Value + 30, _startPosY.Value, 100, 30);
- //корпус
- g.FillPolygon(brush, new Point[]
- {
- new Point(_startPosX.Value,_startPosY.Value + 30), new Point(_startPosX.Value + 150, _startPosY.Value + 30),
- new Point(_startPosX.Value + 150, _startPosY.Value + 30), new Point(_startPosX.Value + 120,_startPosY.Value + 80),
- new Point(_startPosX.Value + 120,_startPosY.Value + 80), new Point(_startPosX.Value + 30,_startPosY.Value + 80),
- new Point(_startPosX.Value + 30,_startPosY.Value + 80), new Point(_startPosX.Value,_startPosY.Value + 30),
- });
- _drawningShipHeight = 80;
- }
- //топливный бак
- if (EntityWarmlyShip.FuelTank)
- {
- brush = new SolidBrush(EntityWarmlyShip.AdditionalColor);
- if (EntityWarmlyShip.ShipPipes)
- g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 120, 70, 10);
- else
- g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 60, 70, 10);
- }
-
+ new Point(_startPosX.Value,_startPosY.Value + 30), new Point(_startPosX.Value + 150, _startPosY.Value + 30),
+ new Point(_startPosX.Value + 150, _startPosY.Value + 30), new Point(_startPosX.Value + 120,_startPosY.Value + 80),
+ new Point(_startPosX.Value + 120,_startPosY.Value + 80), new Point(_startPosX.Value + 30,_startPosY.Value + 80),
+ new Point(_startPosX.Value + 30,_startPosY.Value + 80), new Point(_startPosX.Value,_startPosY.Value + 30),
+ });
}
-
}
+
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs
new file mode 100644
index 0000000..b076926
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs
@@ -0,0 +1,49 @@
+using ProjectWarmlyShip.Entities;
+
+namespace ProjectWarmlyShip.Drawnings;
+
+public class DrawningWarmlyShip : DrawningShip
+{
+ ///
+ /// Класс-сущность
+ ///
+ public EntityWarmlyShip? EntityWarmlyShip { get; private set; }
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public DrawningWarmlyShip(int speed, double weight, Color bodycolor, Color additionalcolor, bool shpipipes, bool fueltank) : base(150,140)
+ {
+ EntityShip = new EntityWarmlyShip(speed, weight, bodycolor, additionalcolor, shpipipes, fueltank); //дописать конструктор
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ //оператор is совместимость объекта с заданным типом
+ if (EntityShip == null || EntityShip is not EntityWarmlyShip warmlyship || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+ Brush brush = new SolidBrush(warmlyship.AdditionalColor);
+ if (warmlyship.ShipPipes)
+ {
+ g.FillRectangle(brush, _startPosX.Value + 70, _startPosY.Value, 12, 60);
+ g.FillRectangle(brush, _startPosX.Value + 90, _startPosY.Value, 12, 60);
+ _startPosY += 60;
+ }
+ base.DrawTransport(g);
+ if (warmlyship.FuelTank)
+ {
+ //if (EntityWarmlyShip.ShipPipes)
+ //{
+ // g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 120, 70, 10);
+ //}
+ //else
+ // g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 60, 70, 10);
+ g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 60, 70, 10);
+ }
+ if (warmlyship.ShipPipes) _startPosY -= 60;
+ }
+
+}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/Entities/EntityShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Entities/EntityShip.cs
new file mode 100644
index 0000000..4da86e7
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Entities/EntityShip.cs
@@ -0,0 +1,34 @@
+namespace ProjectWarmlyShip.Entities;
+
+public class EntityShip
+{
+ ///
+ /// Скорость
+ ///
+ public int Speed { get; private set; }
+ ///
+ /// Вес
+ ///
+ public double Weight { get; private set; }
+ ///
+ /// Основной цвет
+ ///
+ public Color BodyColor { get; private set; }
+ ///
+ /// Шаг перемещения судна
+ ///
+ public double Step => Speed * 100 / Weight;
+ ///
+ /// Конструктор сущности
+ ///
+ ///
+ ///
+ ///
+ public EntityShip(int speed, double weight, Color bodycolor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodycolor;
+ }
+}
+
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/Entities/EntityWarmlyShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Entities/EntityWarmlyShip.cs
new file mode 100644
index 0000000..a4a6396
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Entities/EntityWarmlyShip.cs
@@ -0,0 +1,29 @@
+namespace ProjectWarmlyShip.Entities;
+
+public class EntityWarmlyShip : EntityShip
+{
+ ///
+ /// Дополнительтный цвет
+ ///
+ public Color AdditionalColor { get; private set; }
+ ///
+ /// Признак наличия труб
+ ///
+ public bool ShipPipes { get; private set; }
+ ///
+ /// Признак наличия топливного бака
+ ///
+ public bool FuelTank { get; private set; }
+ ///
+ /// Инициализация полей класса EntityWarmlyShip
+ ///
+ ///
+ ///
+ ///
+ public EntityWarmlyShip(int speed, double weight, Color bodycolor, Color additionalcolor, bool shpipipes, bool fueltank) : base(speed, weight, bodycolor)
+ {
+ AdditionalColor = additionalcolor;
+ ShipPipes = shpipipes;
+ FuelTank = fueltank;
+ }
+}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/EntityWarmlyShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/EntityWarmlyShip.cs
deleted file mode 100644
index 1784315..0000000
--- a/ProjectWarmlyShip/ProjectWarmlyShip/EntityWarmlyShip.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-namespace ProjectWarmlyShip;
-
-public class EntityWarmlyShip
-{
- ///
- /// Скорость
- ///
- public int Speed { get; private set; }
- ///
- /// Вес
- ///
- public double Weight { get; private set; }
- ///
- /// Основной цвет
- ///
- public Color BodyColor { get; private set; }
- ///
- /// Дополнительтный цвет
- ///
- public Color AdditionalColor { get; private set; }
- ///
- /// Признак наличия труб
- ///
- public bool ShipPipes { get; private set; }
- ///
- /// Признак наличия топливного бака
- ///
- public bool FuelTank { get; private set; }
- ///
- /// Шаг перемещения судна
- ///
- public double Step => Speed * 100 / Weight;
- ///
- /// Инициализация полей класса WarmlyShip
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, bool shpipipes, bool fueltank)
- {
- Speed = speed;
- Weight = weight;
- BodyColor = bodycolor;
- AdditionalColor = additionalcolor;
- ShipPipes = shpipipes;
- FuelTank = fueltank;
- }
-}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.Designer.cs b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.Designer.cs
index ba3ee26..509d5d4 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.Designer.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.Designer.cs
@@ -34,6 +34,7 @@
buttonRight = new Button();
buttonLeft = new Button();
buttonDown = new Button();
+ buttonСreateShip = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit();
SuspendLayout();
//
@@ -55,9 +56,9 @@
buttonCreate.ForeColor = SystemColors.ControlText;
buttonCreate.Location = new Point(12, 331);
buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(75, 23);
+ buttonCreate.Size = new Size(118, 23);
buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать";
+ buttonCreate.Text = "Создать теплоход";
buttonCreate.UseVisualStyleBackColor = false;
buttonCreate.Click += ButtonCreate_Click;
//
@@ -109,11 +110,26 @@
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
+ // buttonСreateShip
+ //
+ buttonСreateShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonСreateShip.BackColor = SystemColors.ButtonHighlight;
+ buttonСreateShip.Cursor = Cursors.IBeam;
+ buttonСreateShip.ForeColor = SystemColors.ControlText;
+ buttonСreateShip.Location = new Point(146, 331);
+ buttonСreateShip.Name = "buttonСreateShip";
+ buttonСreateShip.Size = new Size(118, 23);
+ buttonСreateShip.TabIndex = 6;
+ buttonСreateShip.Text = "Создать судно";
+ buttonСreateShip.UseVisualStyleBackColor = false;
+ buttonСreateShip.Click += buttonСreateShip_Click;
+ //
// FormWarmlyShip
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(830, 366);
+ Controls.Add(buttonСreateShip);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonRight);
@@ -135,5 +151,6 @@
private Button buttonRight;
private Button buttonLeft;
private Button buttonDown;
+ private Button buttonСreateShip;
}
}
\ No newline at end of file
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs
index e625356..e1479b4 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs
@@ -1,31 +1,61 @@
-namespace ProjectWarmlyShip
+using ProjectWarmlyShip.Drawnings;
+
+namespace ProjectWarmlyShip
{
public partial class FormWarmlyShip : Form
{
- private DrawningWarmlyShip? _drawningWarmlyShip;
+ private DrawningShip? _drawningShip;
public FormWarmlyShip()
{
InitializeComponent();
}
- private void ButtonCreate_Click(object sender, EventArgs e)
+ private void CreateObject(string type)
{
- Random random = new();
- _drawningWarmlyShip = new DrawningWarmlyShip();
- _drawningWarmlyShip.Init(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
- _drawningWarmlyShip.SetPictureSize(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
- _drawningWarmlyShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
-
+ Random random = new Random();
+ switch(type)
+ {
+ case nameof(DrawningShip):
+ _drawningShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
+ break;
+ case nameof(DrawningWarmlyShip):
+ _drawningShip = new DrawningWarmlyShip(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+ _drawningShip.SetPictureSize(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
+ _drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningWarmlyShip.DrawTransport(gr);
+ _drawningShip.DrawTransport(gr);
pictureBoxWarmlyShip.Image = bmp;
+
+ }
+ ///
+ /// Кнопка создания теплохода
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningWarmlyShip));
+ }
+ ///
+ /// Кнопка создания судна
+ ///
+ ///
+ ///
+ private void buttonСreateShip_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningShip));
}
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_drawningWarmlyShip == null)
+ if (_drawningShip == null)
{
return;
}
@@ -34,27 +64,26 @@
switch (name)
{
case "buttonUp":
- result = _drawningWarmlyShip.MoveTransport(DirectionType.Up);
+ result = _drawningShip.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- result = _drawningWarmlyShip.MoveTransport(DirectionType.Down);
+ result = _drawningShip.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- result = _drawningWarmlyShip.MoveTransport(DirectionType.Left);
+ result = _drawningShip.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
- result = _drawningWarmlyShip.MoveTransport(DirectionType.Right);
+ result = _drawningShip.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningWarmlyShip.DrawTransport(gr);
+ _drawningShip.DrawTransport(gr);
pictureBoxWarmlyShip.Image = bmp;
}
}
-
}
}
--
2.25.1
From 75a051074ff28e9bafb2a56a5564a75da068ad49 Mon Sep 17 00:00:00 2001
From: IlyasValiulov <148232695+IlyasValiulov@users.noreply.github.com>
Date: Sun, 18 Feb 2024 00:55:13 +0400
Subject: [PATCH 2/3] =?UTF-8?q?=D0=A1=D1=82=D0=B0=D0=B4=D0=B8=D1=8F=20?=
=?UTF-8?q?=D1=80=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B8:?=
=?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?=
=?UTF-8?q?=20=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3=D0=B8=D0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Drawnings/DirectionType.cs | 4 +
.../Drawnings/DrawningShip.cs | 19 ++-
.../Drawnings/DrawningWarmlyShip.cs | 3 +-
.../FormWarmlyShip.Designer.cs | 26 ++++
.../ProjectWarmlyShip/FormWarmlyShip.cs | 44 ++++++-
.../MovementStrategy/AbstractStrategy.cs | 115 ++++++++++++++++++
.../MovementStrategy/IMoveableObjects.cs | 17 +++
.../MovementStrategy/MoveToBorder.cs | 31 +++++
.../MovementStrategy/MoveToCenter.cs | 49 ++++++++
.../MovementStrategy/MoveableShip.cs | 49 ++++++++
.../MovementStrategy/MovementDirection.cs | 21 ++++
.../MovementStrategy/ObjectParameters.cs | 59 +++++++++
.../MovementStrategy/StrategyStatus.cs | 15 +++
13 files changed, 448 insertions(+), 4 deletions(-)
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/AbstractStrategy.cs
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/IMoveableObjects.cs
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveToBorder.cs
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveToCenter.cs
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveableShip.cs
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MovementDirection.cs
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/ObjectParameters.cs
create mode 100644 ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/StrategyStatus.cs
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DirectionType.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DirectionType.cs
index 80c84f9..c645a8d 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DirectionType.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DirectionType.cs
@@ -4,6 +4,10 @@
///
public enum DirectionType
{
+ ///
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
///
/// Вверх
///
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs
index fa543cd..fe33413 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs
@@ -33,11 +33,26 @@ public class DrawningShip
/// Ширина прорисовки
///
private readonly int _drawningShipWidth = 150;
-
///
/// Высота прорисовки
///
- private int _drawningShipHeight = 80;
+ protected int _drawningShipHeight = 80;
+ ///
+ /// Координаты Х
+ ///
+ public int? GetPosX => _startPosX;
+ ///
+ /// Координтаы У
+ ///
+ public int? GetPosY => _startPosY;
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidht => _drawningShipWidth;
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningShipHeight;
///
/// Пустой конструктор
///
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs
index b076926..134df93 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs
@@ -14,7 +14,7 @@ public class DrawningWarmlyShip : DrawningShip
///
///
///
- public DrawningWarmlyShip(int speed, double weight, Color bodycolor, Color additionalcolor, bool shpipipes, bool fueltank) : base(150,140)
+ public DrawningWarmlyShip(int speed, double weight, Color bodycolor, Color additionalcolor, bool shpipipes, bool fueltank) : base(150,80)
{
EntityShip = new EntityWarmlyShip(speed, weight, bodycolor, additionalcolor, shpipipes, fueltank); //дописать конструктор
}
@@ -28,6 +28,7 @@ public class DrawningWarmlyShip : DrawningShip
Brush brush = new SolidBrush(warmlyship.AdditionalColor);
if (warmlyship.ShipPipes)
{
+ _drawningShipHeight = 140;
g.FillRectangle(brush, _startPosX.Value + 70, _startPosY.Value, 12, 60);
g.FillRectangle(brush, _startPosX.Value + 90, _startPosY.Value, 12, 60);
_startPosY += 60;
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.Designer.cs b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.Designer.cs
index 509d5d4..2d76590 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.Designer.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.Designer.cs
@@ -35,6 +35,8 @@
buttonLeft = new Button();
buttonDown = new Button();
buttonСreateShip = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit();
SuspendLayout();
//
@@ -124,11 +126,33 @@
buttonСreateShip.UseVisualStyleBackColor = false;
buttonСreateShip.Click += buttonСreateShip_Click;
//
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
+ comboBoxStrategy.Location = new Point(685, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(133, 23);
+ comboBoxStrategy.TabIndex = 7;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(732, 41);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(86, 23);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "Шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += buttonStrategyStep_Click;
+ //
// FormWarmlyShip
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(830, 366);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(comboBoxStrategy);
Controls.Add(buttonСreateShip);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
@@ -152,5 +176,7 @@
private Button buttonLeft;
private Button buttonDown;
private Button buttonСreateShip;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs
index e1479b4..2a47915 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs
@@ -1,18 +1,21 @@
using ProjectWarmlyShip.Drawnings;
+using ProjectWarmlyShip.MovementStrategy;
namespace ProjectWarmlyShip
{
public partial class FormWarmlyShip : Form
{
private DrawningShip? _drawningShip;
+ private AbstractStrategy? _strategy;
public FormWarmlyShip()
{
InitializeComponent();
+ _strategy = null;
}
private void CreateObject(string type)
{
Random random = new Random();
- switch(type)
+ switch (type)
{
case nameof(DrawningShip):
_drawningShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000),
@@ -29,6 +32,8 @@ namespace ProjectWarmlyShip
}
_drawningShip.SetPictureSize(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ _strategy = null;
+ comboBoxStrategy.Enabled = true;
Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningShip.DrawTransport(gr);
@@ -84,6 +89,43 @@ namespace ProjectWarmlyShip
pictureBoxWarmlyShip.Image = bmp;
}
}
+ private void buttonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningShip == null)
+ {
+ return;
+ }
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(new MoveableShip(_drawningShip),
+ pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
+ }
+ if (_strategy == null)
+ {
+ return;
+ }
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningShip.DrawTransport(gr);
+ pictureBoxWarmlyShip.Image = bmp;
+ if (_strategy.GetStatus == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
}
}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/AbstractStrategy.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..9647eaf
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,115 @@
+namespace ProjectWarmlyShip.MovementStrategy;
+
+public abstract class AbstractStrategy
+{
+ ///
+ /// Перемещаемый объект
+ ///
+ private IMoveableObjects? _moveableObject;
+ ///
+ /// Статус перемещения
+ ///
+ private StrategyStatus _state = StrategyStatus.NotInit;
+ ///
+ /// Ширина поля
+ ///
+ protected int FieldWidth { get; private set; }
+ ///
+ /// Высота поля
+ ///
+ protected int FieldHeight { get; private set; }
+ ///
+ /// Статус перемещения
+ ///
+ public StrategyStatus GetStatus {get { return _state; }}
+ ///
+ /// Установка данных
+ ///
+ ///
+ ///
+ ///
+ public void SetData(IMoveableObjects moveableObjects, int width, int height)
+ {
+ if (moveableObjects == null)
+ {
+ _state = StrategyStatus.NotInit;
+ return;
+ }
+ _state = StrategyStatus.InProgress;
+ _moveableObject = moveableObjects;
+ FieldWidth = width;
+ FieldHeight = height;
+ }
+ ///
+ /// Шаг перемещения
+ ///
+ public void MakeStep()
+ {
+ if (_state != StrategyStatus.InProgress) return;
+ if (IsTargetDestinaion())
+ {
+ _state = StrategyStatus.Finish;
+ return;
+ }
+ MoveToTarget();
+ }
+ ///
+ /// Перемещение влево
+ ///
+ /// Результат перемещения (true - удалось переместиться, false -неудача)
+ protected bool MoveLeft() => MoveTo(MovementDirection.Left);
+ ///
+ /// Перемещение вправо
+ ///
+ /// Результат перемещения (true - удалось переместиться, false -неудача)
+ protected bool MoveRight() => MoveTo(MovementDirection.Right);
+ ///
+ /// Перемещение вверх
+ ///
+ /// Результат перемещения (true - удалось переместиться, false -неудача)
+ protected bool MoveUp() => MoveTo(MovementDirection.Up);
+ ///
+ /// Перемещение вниз
+ ///
+ /// Результат перемещения (true - удалось переместиться, false -неудача)
+ protected bool MoveDown() => MoveTo(MovementDirection.Down);
+ ///
+ /// Параметры объекта
+ ///
+ protected ObjectParameters? GetObjectParameters =>_moveableObject?.GetObjectPosition;
+ ///
+ /// Шаг объекта
+ ///
+ ///
+ protected int? GetStep()
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return null;
+ }
+ return _moveableObject?.GetStep;
+ }
+ ///
+ /// Перемещение к цели
+ ///
+ protected abstract void MoveToTarget();
+ ///
+ /// Достигнута ли цель
+ ///
+ ///
+ protected abstract bool IsTargetDestinaion();
+ ///
+ /// Попытка перемещения в требуемом направлении
+ ///
+ /// Направление
+ /// Результат попытки (true - удалось переместиться, false -неудача)
+ private bool MoveTo(MovementDirection movementDirection)
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return false;
+ }
+ return _moveableObject?.TryMoveObject(movementDirection) ?? false;
+ }
+}
+
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/IMoveableObjects.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/IMoveableObjects.cs
new file mode 100644
index 0000000..33f8030
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/IMoveableObjects.cs
@@ -0,0 +1,17 @@
+namespace ProjectWarmlyShip.MovementStrategy;
+
+public interface IMoveableObjects
+{
+ //Получение координаты обхекта
+ ObjectParameters? GetObjectPosition { get; }
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ ///
+ ///
+ bool TryMoveObject(MovementDirection direction);
+}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveToBorder.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..c57aa17
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,31 @@
+namespace ProjectWarmlyShip.MovementStrategy;
+
+public class MoveToBorder : AbstractStrategy
+{
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.LeftBorder - GetStep() <= 0 ||
+ objParams.RightBorder + GetStep() >= FieldWidth ||
+ objParams.TopBorder - GetStep() <= 0
+ || objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
+ }
+
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ //реализация в правый нижний угол
+ int x = objParams.RightBorder;
+ if (x + GetStep() < FieldWidth) MoveRight();
+ int y = objParams.DownBorder;
+ if (y + GetStep() < FieldHeight) MoveDown();
+ }
+}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveToCenter.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..f72d05c
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,49 @@
+namespace ProjectWarmlyShip.MovementStrategy;
+
+public class MoveToCenter : AbstractStrategy
+{
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 &&
+ objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
+ objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
+ && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
+ }
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveableShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveableShip.cs
new file mode 100644
index 0000000..caaffc7
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveableShip.cs
@@ -0,0 +1,49 @@
+using ProjectWarmlyShip.Drawnings;
+
+namespace ProjectWarmlyShip.MovementStrategy;
+
+public class MoveableShip : IMoveableObjects
+{
+ private DrawningShip? _drawningship;
+ public MoveableShip(DrawningShip? drawningship)
+ {
+ _drawningship = drawningship;
+ }
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_drawningship == null || _drawningship.EntityShip == null || !_drawningship.GetPosX.HasValue || !_drawningship.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(_drawningship.GetPosX.Value, _drawningship.GetPosY.Value, _drawningship.GetWidht, _drawningship.GetHeight);
+ }
+ }
+ public int GetStep => (int)(_drawningship?.EntityShip?.Step ?? 0);
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (_drawningship == null || _drawningship.EntityShip == null)
+ {
+ return false;
+ }
+ return _drawningship.MoveTransport(GetDirectionType(direction));
+ }
+ ///
+ /// Конвертация из MovementDirection в DirectionType
+ ///
+ /// MovementDirection
+ /// DirectionType
+ private static DirectionType GetDirectionType(MovementDirection direction)
+ {
+ return direction switch
+ {
+ MovementDirection.Left => DirectionType.Left,
+ MovementDirection.Right => DirectionType.Right,
+ MovementDirection.Up => DirectionType.Up,
+ MovementDirection.Down => DirectionType.Down,
+ _ => DirectionType.Unknow,
+ };
+ }
+
+}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MovementDirection.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MovementDirection.cs
new file mode 100644
index 0000000..23d2856
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MovementDirection.cs
@@ -0,0 +1,21 @@
+namespace ProjectWarmlyShip.MovementStrategy;
+
+public enum MovementDirection
+{
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+ ///
+ /// Влево
+ ///
+ Left = 3,
+ ///
+ /// Вправо
+ ///
+ Right = 4
+}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/ObjectParameters.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..1790454
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,59 @@
+namespace ProjectWarmlyShip.MovementStrategy;
+
+public class ObjectParameters
+{
+ ///
+ /// Координата х
+ ///
+ private readonly int _x;
+ ///
+ /// Координата у
+ ///
+ private readonly int _y;
+ ///
+ /// Ширина объекта
+ ///
+ private readonly int _width;
+ ///
+ /// Высота объекта
+ ///
+ private readonly int _height;
+ ///
+ /// Левая граница
+ ///
+ public int LeftBorder => _x;
+ ///
+ /// Правая граница
+ ///
+ public int TopBorder => _y;
+ ///
+ /// Правая граница
+ ///
+ public int RightBorder => _x + _width;
+ ///
+ /// Нижняя граница
+ ///
+ public int DownBorder => _y + _height;
+ ///
+ /// Середина объекта
+ ///
+ public int ObjectMiddleHorizontal => _x + _width / 2;
+ ///
+ /// Середина объекта
+ ///
+ public int ObjectMiddleVertical => _y + _height / 2;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ ///
+ public ObjectParameters(int x, int y, int width, int height)
+ {
+ _x = x;
+ _y = y;
+ _width = width;
+ _height = height;
+ }
+}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/StrategyStatus.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..117b98d
--- /dev/null
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,15 @@
+namespace ProjectWarmlyShip.MovementStrategy;
+
+public enum StrategyStatus
+{
+ ///
+ /// Все готово к началу
+ ///
+ NotInit,
+ ///
+ /// Выполняется
+ ///
+ InProgress,
+ // Завершена
+ Finish
+}
--
2.25.1
From 0619b0de35a7b78d14b7f70f705f1513b03c8ace Mon Sep 17 00:00:00 2001
From: IlyasValiulov <148232695+IlyasValiulov@users.noreply.github.com>
Date: Mon, 19 Feb 2024 15:29:36 +0400
Subject: [PATCH 3/3] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=D1=80=D0=B0=D1=82?=
=?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?=
=?UTF-8?q?=D0=B0=20=E2=84=962=202?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Drawnings/DrawningShip.cs | 5 ----
.../Drawnings/DrawningWarmlyShip.cs | 11 --------
.../ProjectWarmlyShip/FormWarmlyShip.cs | 28 +++++++++----------
.../MovementStrategy/IMoveableObjects.cs | 1 -
.../MovementStrategy/MoveableShip.cs | 1 -
5 files changed, 14 insertions(+), 32 deletions(-)
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs
index fe33413..4fe08b1 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningShip.cs
@@ -8,27 +8,22 @@ public class DrawningShip
/// Класс-сущность
///
public EntityShip? EntityShip { get; protected set; }
-
///
/// Ширина окна
///
private int? _pictureWidth;
-
///
/// Высота окна
///
private int? _pictureHeight;
-
///
/// Левая координата прорисовки
///
protected int? _startPosX;
-
///
/// Верхняя кооридната прорисовки
///
protected int? _startPosY;
-
///
/// Ширина прорисовки
///
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs
index 134df93..fd00dc6 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/Drawnings/DrawningWarmlyShip.cs
@@ -4,10 +4,6 @@ namespace ProjectWarmlyShip.Drawnings;
public class DrawningWarmlyShip : DrawningShip
{
- ///
- /// Класс-сущность
- ///
- public EntityWarmlyShip? EntityWarmlyShip { get; private set; }
///
/// Конструктор
///
@@ -36,15 +32,8 @@ public class DrawningWarmlyShip : DrawningShip
base.DrawTransport(g);
if (warmlyship.FuelTank)
{
- //if (EntityWarmlyShip.ShipPipes)
- //{
- // g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 120, 70, 10);
- //}
- //else
- // g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 60, 70, 10);
g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 60, 70, 10);
}
if (warmlyship.ShipPipes) _startPosY -= 60;
}
-
}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs
index 2a47915..65c0832 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/FormWarmlyShip.cs
@@ -12,6 +12,17 @@ namespace ProjectWarmlyShip
InitializeComponent();
_strategy = null;
}
+ private void Draw()
+ {
+ if (_drawningShip == null)
+ {
+ return;
+ }
+ Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningShip.DrawTransport(gr);
+ pictureBoxWarmlyShip.Image = bmp;
+ }
private void CreateObject(string type)
{
Random random = new Random();
@@ -34,11 +45,7 @@ namespace ProjectWarmlyShip
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBoxStrategy.Enabled = true;
- Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
- Graphics gr = Graphics.FromImage(bmp);
- _drawningShip.DrawTransport(gr);
- pictureBoxWarmlyShip.Image = bmp;
-
+ Draw();
}
///
/// Кнопка создания теплохода
@@ -83,10 +90,7 @@ namespace ProjectWarmlyShip
}
if (result)
{
- Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
- Graphics gr = Graphics.FromImage(bmp);
- _drawningShip.DrawTransport(gr);
- pictureBoxWarmlyShip.Image = bmp;
+ Draw();
}
}
private void buttonStrategyStep_Click(object sender, EventArgs e)
@@ -116,10 +120,7 @@ namespace ProjectWarmlyShip
}
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
- Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
- Graphics gr = Graphics.FromImage(bmp);
- _drawningShip.DrawTransport(gr);
- pictureBoxWarmlyShip.Image = bmp;
+ Draw();
if (_strategy.GetStatus == StrategyStatus.Finish)
{
comboBoxStrategy.Enabled = true;
@@ -127,5 +128,4 @@ namespace ProjectWarmlyShip
}
}
}
-
}
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/IMoveableObjects.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/IMoveableObjects.cs
index 33f8030..efb09a7 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/IMoveableObjects.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/IMoveableObjects.cs
@@ -2,7 +2,6 @@
public interface IMoveableObjects
{
- //Получение координаты обхекта
ObjectParameters? GetObjectPosition { get; }
///
/// Шаг объекта
diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveableShip.cs b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveableShip.cs
index caaffc7..23ac656 100644
--- a/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveableShip.cs
+++ b/ProjectWarmlyShip/ProjectWarmlyShip/MovementStrategy/MoveableShip.cs
@@ -45,5 +45,4 @@ public class MoveableShip : IMoveableObjects
_ => DirectionType.Unknow,
};
}
-
}
--
2.25.1