From fdeb174e9033eee03b91858dd35234d2d0b63883 Mon Sep 17 00:00:00 2001 From: ShuryginDima Date: Sun, 10 Mar 2024 16:04:36 +0300 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 +- .../DrawningPlane.cs} | 113 +++++++++--------- .../Drawnings/DrawningSeaplane.cs | 55 +++++++++ .../ProjectSeaplane/Entities/EntityPlane.cs | 49 ++++++++ .../{ => Entities}/EntitySeaplane.cs | 30 +---- .../ProjectSeaplane/FormSeaplane.Designer.cs | 18 ++- .../ProjectSeaplane/FormSeaplane.cs | 77 +++++++----- 7 files changed, 228 insertions(+), 116 deletions(-) rename ProjectSeaplane/ProjectSeaplane/{ => Drawnings}/DirectionType.cs (90%) rename ProjectSeaplane/ProjectSeaplane/{DrawningSeaplane.cs => Drawnings/DrawningPlane.cs} (70%) create mode 100644 ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningSeaplane.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs rename ProjectSeaplane/ProjectSeaplane/{ => Entities}/EntitySeaplane.cs (66%) diff --git a/ProjectSeaplane/ProjectSeaplane/DirectionType.cs b/ProjectSeaplane/ProjectSeaplane/Drawnings/DirectionType.cs similarity index 90% rename from ProjectSeaplane/ProjectSeaplane/DirectionType.cs rename to ProjectSeaplane/ProjectSeaplane/Drawnings/DirectionType.cs index ef50542..274b265 100644 --- a/ProjectSeaplane/ProjectSeaplane/DirectionType.cs +++ b/ProjectSeaplane/ProjectSeaplane/Drawnings/DirectionType.cs @@ -1,4 +1,4 @@ -namespace ProjectSeaplane; +namespace ProjectSeaplane.Drawnings; /// /// Направление перемещения /// diff --git a/ProjectSeaplane/ProjectSeaplane/DrawningSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningPlane.cs similarity index 70% rename from ProjectSeaplane/ProjectSeaplane/DrawningSeaplane.cs rename to ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningPlane.cs index fddee39..850f600 100644 --- a/ProjectSeaplane/ProjectSeaplane/DrawningSeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningPlane.cs @@ -1,13 +1,18 @@ -namespace ProjectSeaplane; -/// -/// Класс, отвечающий за прорисовку и перемещение объекта-сущности -/// -public class DrawningSeaplane +using ProjectSeaplane.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectSeaplane.Drawnings; + +public class DrawningPlane { /// /// Класс-сущность /// - public EntitySeaplane? EntitySeaplane { get; private set; } + public EntityPlane? EntityPlane { get; protected set; } /// /// Ширина окна @@ -22,42 +27,56 @@ public class DrawningSeaplane /// /// Левая координата прорисовки гидросамолёта /// - private int? _startPosX; + protected int? _startPosX; /// /// Верхняя кооридната прорисовки гидросамолёта /// - private int? _startPosY; + protected int? _startPosY; /// /// Ширина прорисовки гидросамолёта /// - private readonly int _drawningSeaplaneWidth = 130; + private readonly int _drawningPlaneWidth = 130; /// /// Высота прорисовки гидросамолёта /// - private readonly int _drawningSeaplaneHeight = 50; + private readonly int _drawningPlaneHeight = 45; /// - /// Инициализация свойств + /// Пустой конструктор /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия поплавков - /// Признак наличия лодки - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat) + private DrawningPlane() { - EntitySeaplane = new EntitySeaplane(); - EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, floats, boat); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawningPlane(int speed, double weight, Color bodyColor) : this() + { + EntityPlane = new EntityPlane(speed, weight, bodyColor); + } + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки гидросамолёта + /// Высота прорисовки гидросамолёта + protected DrawningPlane(int _drawningPlaneWidth, int _drawningPlaneHeight) : this() + { + _drawningPlaneWidth = drawningPlaneWidth; + _pictureHeight = drawningPlaneHeight; + } + /// /// Установка границ поля /// @@ -66,7 +85,7 @@ public class DrawningSeaplane /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах public bool SetPictureSize(int width, int height) { - + if (height < _drawningSeaplaneHeight || width < _drawningSeaplaneWidth) { @@ -121,7 +140,7 @@ public class DrawningSeaplane /// true - перемещене выполнено, false - перемещение невозможно public bool MoveTransport(DirectionType direction) { - if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } @@ -130,31 +149,31 @@ public class DrawningSeaplane { //влево case DirectionType.Left: - if (_startPosX.Value - EntitySeaplane.Step > 0) + if (_startPosX.Value - EntityPlane.Step > 0) { - _startPosX -= (int)EntitySeaplane.Step; + _startPosX -= (int)EntityPlane.Step; } return true; //вверх case DirectionType.Up: - if (_startPosY.Value - EntitySeaplane.Step > 0) + if (_startPosY.Value - EntityPlane.Step > 0) { - _startPosY -= (int)EntitySeaplane.Step; + _startPosY -= (int)EntityPlane.Step; } return true; // вправо case DirectionType.Right: - if (_startPosX.Value + _drawningSeaplaneWidth + EntitySeaplane.Step < _pictureWidth) + if (_startPosX.Value + _drawningSeaplaneWidth + EntityPlane.Step < _pictureWidth) { - _startPosX += (int)EntitySeaplane.Step; + _startPosX += (int)EntityPlane.Step; } return true; //вниз case DirectionType.Down: - if (_startPosY.Value + _drawningSeaplaneHeight + EntitySeaplane.Step < _pictureHeight) + if (_startPosY.Value + _drawningSeaplaneHeight + EntityPlane.Step < _pictureHeight) { - _startPosY += (int)EntitySeaplane.Step; + _startPosY += (int)EntityPlane.Step; } return true; default: @@ -165,19 +184,16 @@ public class DrawningSeaplane /// Прорисовка объекта /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { - if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black, 2); - Brush additionalBrush = new SolidBrush(EntitySeaplane.AdditionalColor); - - //Отрисовка основных частей самолёта - Brush br = new SolidBrush(EntitySeaplane.BodyColor); + Brush br = new SolidBrush(EntityPlane.BodyColor); g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 20, 20); g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 20, 20); Point point1 = new Point(_startPosX.Value + 10, _startPosY.Value); @@ -192,7 +208,7 @@ public class DrawningSeaplane g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 20, _startPosX.Value + 40, _startPosY.Value + 20); g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 40); g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 30, _startPosX.Value + 130, _startPosY.Value + 30); - + //Крылья g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 20, 25, 5); g.FillEllipse(br, _startPosX.Value, _startPosY.Value + 20, 25, 5); @@ -212,26 +228,5 @@ public class DrawningSeaplane g.FillEllipse(br, _startPosX.Value + 35, _startPosY.Value + 45, 5, 5); g.FillEllipse(br, _startPosX.Value + 42, _startPosY.Value + 45, 5, 5); g.FillEllipse(br, _startPosX.Value + 87, _startPosY.Value + 45, 5, 5); - - - //Надувнвя лодка - if (EntitySeaplane.Boat) - { - g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10); - g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10); - - } - - //Поплавки - if (EntitySeaplane.Floats) - { - g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15); - g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15); - g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15); - g.FillRectangle(additionalBrush, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15); - g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10); - g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10); - - } } -} +} \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningSeaplane.cs new file mode 100644 index 0000000..7a32c92 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningSeaplane.cs @@ -0,0 +1,55 @@ +using ProjectSeaplane.Entities; +using System.Drawing; + +namespace ProjectSeaplane.Drawnings; +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawningSeaplane : DrawningPlane +{ + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия поплавков + /// Признак наличия лодки + public DrawningSeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat) : base(130, 50) + { + EntityPlane = new EntitySeaplane(speed, weight, bodyColor, additionalColor, floats, boat); + } + + public override void DrawTransport(Graphics g) + { + if (EntityPlane == null || EntityPlane is not EntitySeaplane seaplane || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black, 2); + Brush additionalBrush = new SolidBrush(seaplane.AdditionalColor); + + base.DrawTransport(g); + + //Надувнвя лодка + if (seaplane.Boat) + { + g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 15, 30, 10); + + } + + //Поплавки + if (seaplane.Floats) + { + g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 30, 4, 15); + g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 66, _startPosY.Value + 30, 4, 15); + g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 40, 70, 10); + } + } +} diff --git a/ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs b/ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs new file mode 100644 index 0000000..3e3dac9 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectSeaplane.Entities; + +/// +/// Класс-сущность "Самолёт" +/// + +public class EntityPlane +{ + /// + /// Скорость + /// + 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 EntityPlane(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } +} diff --git a/ProjectSeaplane/ProjectSeaplane/EntitySeaplane.cs b/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs similarity index 66% rename from ProjectSeaplane/ProjectSeaplane/EntitySeaplane.cs rename to ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs index 625ccfc..113ec5b 100644 --- a/ProjectSeaplane/ProjectSeaplane/EntitySeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs @@ -1,24 +1,9 @@ -namespace ProjectSeaplane; +namespace ProjectSeaplane.Entities; /// /// Класс-сущность "Гидросамолёт" /// -public class EntitySeaplane +public class EntitySeaplane : EntityPlane { - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - /// /// Дополнительный цвет (для опциональных элементов) /// @@ -35,11 +20,6 @@ public class EntitySeaplane /// public bool Boat { get; private set; } - /// - /// Шаг перемещения гидросамолёта - /// - public double Step => Speed * 100 / Weight; - /// /// Инициализация полей объекта-класса гидросамолёта /// @@ -49,12 +29,8 @@ public class EntitySeaplane /// Дополнительный цвет /// Признак наличия поплавков /// Признак наличия лодки - public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, bool floats, bool boat) + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; Floats = floats; Boat = boat; diff --git a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs index fde1660..59c5859 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs @@ -34,6 +34,7 @@ buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); + buttonCreatePlane = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit(); SuspendLayout(); // @@ -51,9 +52,9 @@ buttonCreateSeaplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateSeaplane.Location = new Point(12, 465); buttonCreateSeaplane.Name = "buttonCreateSeaplane"; - buttonCreateSeaplane.Size = new Size(75, 23); + buttonCreateSeaplane.Size = new Size(196, 23); buttonCreateSeaplane.TabIndex = 1; - buttonCreateSeaplane.Text = "Создать"; + buttonCreateSeaplane.Text = "Создать гидросамолёт"; buttonCreateSeaplane.UseVisualStyleBackColor = true; buttonCreateSeaplane.Click += ButtonCreateSeaplane_Click; // @@ -105,11 +106,23 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // + // buttonCreatePlane + // + buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreatePlane.Location = new Point(214, 465); + buttonCreatePlane.Name = "buttonCreatePlane"; + buttonCreatePlane.Size = new Size(196, 23); + buttonCreatePlane.TabIndex = 6; + buttonCreatePlane.Text = "Создать самолёт"; + buttonCreatePlane.UseVisualStyleBackColor = true; + buttonCreatePlane.Click += buttonCreatePlane_Click; + // // FormSeaplane // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(900, 500); + Controls.Add(buttonCreatePlane); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); @@ -130,5 +143,6 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; + private Button buttonCreatePlane; } } \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs index 8781929..cd79f6d 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs @@ -1,4 +1,6 @@ -namespace ProjectSeaplane; +using ProjectSeaplane.Drawnings; + +namespace ProjectSeaplane; /// /// Форма работы с объектом "Спортивный автомобиль" /// @@ -7,7 +9,7 @@ public partial class FormSeaplane : Form /// /// Поле-объект для прорисовки объекта /// - private DrawningSeaplane? _drawningSeaplane; + private DrawningPlane? _drawningPlane; /// /// Конструктор формы /// @@ -20,33 +22,58 @@ public partial class FormSeaplane : Form /// private void Draw() { - if (_drawningSeaplane == null) + if (_drawningPlane == null) { return; } Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningSeaplane.DrawTransport(gr); + _drawningPlane.DrawTransport(gr); pictureBoxSeaplane.Image = bmp; } + /// - /// Обработка нажатия кнопки "Создать" + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + Random random = new(); + switch (type) + { + case nameof(DrawningPlane): + _drawningPlane = new DrawningPlane(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(DrawningSeaplane): + _drawningPlane = new DrawningSeaplane(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; + } + _drawningPlane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); + _drawningPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + + + /// + /// Обработка нажатия кнопки "Создать гидросамолёт" /// /// /// - private void ButtonCreateSeaplane_Click(object sender, EventArgs e) - { - Random random = new(); - _drawningSeaplane = new DrawningSeaplane(); - - _drawningSeaplane.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))); - _drawningSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); - _drawningSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); - } + private void ButtonCreateSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSeaplane)); + + /// + /// Обработка нажатия кнопки "Создать самолёт" + /// + /// + /// + private void buttonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane)); + /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// @@ -54,7 +81,7 @@ public partial class FormSeaplane : Form /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningSeaplane == null) + if (_drawningPlane == null) { return; } @@ -63,20 +90,16 @@ public partial class FormSeaplane : Form switch (name) { case "buttonUp": - result = - _drawningSeaplane.MoveTransport(DirectionType.Up); + result = _drawningPlane.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = - _drawningSeaplane.MoveTransport(DirectionType.Down); + result = _drawningPlane.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = - _drawningSeaplane.MoveTransport(DirectionType.Left); + result = _drawningPlane.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = - _drawningSeaplane.MoveTransport(DirectionType.Right); + result = _drawningPlane.MoveTransport(DirectionType.Right); break; } if (result) -- 2.25.1 From c2ae9d68b408f1df11282b718a2a469ec27b9890 Mon Sep 17 00:00:00 2001 From: ShuryginDima Date: Mon, 11 Mar 2024 21:10:39 +0300 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=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Drawnings/DirectionType.cs | 5 + .../Drawnings/DrawningPlane.cs | 58 +++++--- .../Drawnings/DrawningSeaplane.cs | 1 - .../ProjectSeaplane/Entities/EntityPlane.cs | 11 +- .../Entities/EntitySeaplane.cs | 4 + .../ProjectSeaplane/FormSeaplane.Designer.cs | 28 +++- .../ProjectSeaplane/FormSeaplane.cs | 55 ++++++- .../MovementStrategy/AbstractStrategy.cs | 138 ++++++++++++++++++ .../MovementStrategy/IMoveableObject.cs | 24 +++ .../MovementStrategy/MoveToBorder.cs | 51 +++++++ .../MovementStrategy/MoveToCenter.cs | 50 +++++++ .../MovementStrategy/MoveablePlane.cs | 61 ++++++++ .../MovementStrategy/MovementDirection.cs | 32 ++++ .../MovementStrategy/ObjectParameters.cs | 72 +++++++++ .../MovementStrategy/StrategyStatus.cs | 22 +++ 15 files changed, 577 insertions(+), 35 deletions(-) create mode 100644 ProjectSeaplane/ProjectSeaplane/MovementStrategy/AbstractStrategy.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/MovementStrategy/IMoveableObject.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToBorder.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToCenter.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveablePlane.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/MovementStrategy/MovementDirection.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/MovementStrategy/ObjectParameters.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/MovementStrategy/StrategyStatus.cs diff --git a/ProjectSeaplane/ProjectSeaplane/Drawnings/DirectionType.cs b/ProjectSeaplane/ProjectSeaplane/Drawnings/DirectionType.cs index 274b265..81916f2 100644 --- a/ProjectSeaplane/ProjectSeaplane/Drawnings/DirectionType.cs +++ b/ProjectSeaplane/ProjectSeaplane/Drawnings/DirectionType.cs @@ -4,6 +4,11 @@ /// public enum DirectionType { + /// + /// Неизвестное направление + /// + Unknow = -1, + /// /// Вверх /// diff --git a/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningPlane.cs b/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningPlane.cs index 850f600..adb5ead 100644 --- a/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningPlane.cs +++ b/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningPlane.cs @@ -1,12 +1,10 @@ using ProjectSeaplane.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ProjectSeaplane.Drawnings; +/// +/// Класс, отвечающий за прорисовку и перемещение базового объекта-сущности +/// public class DrawningPlane { /// @@ -25,25 +23,42 @@ public class DrawningPlane private int? _pictureHeight; /// - /// Левая координата прорисовки гидросамолёта + /// Левая координата прорисовки самолёта /// protected int? _startPosX; /// - /// Верхняя кооридната прорисовки гидросамолёта + /// Верхняя кооридната прорисовки самолёта /// protected int? _startPosY; /// - /// Ширина прорисовки гидросамолёта + /// Ширина прорисовки самолёта /// private readonly int _drawningPlaneWidth = 130; /// - /// Высота прорисовки гидросамолёта + /// Высота прорисовки самолёта /// private readonly int _drawningPlaneHeight = 45; + /// + /// Координата X объекта + /// + public int? GetPosX => _startPosX; + /// + /// Координата Y объекта + /// + public int? GetPosY => _startPosY; + /// + /// Ширина объекта + /// + public int GetWidth => _drawningPlaneWidth; + /// + /// Высота объекта + /// + public int GetHeight => _drawningPlaneHeight; + /// /// Пустой конструктор /// @@ -71,10 +86,10 @@ public class DrawningPlane /// /// Ширина прорисовки гидросамолёта /// Высота прорисовки гидросамолёта - protected DrawningPlane(int _drawningPlaneWidth, int _drawningPlaneHeight) : this() + protected DrawningPlane(int drawningPlaneWidth, int drawningPlaneHeight) : this() { _drawningPlaneWidth = drawningPlaneWidth; - _pictureHeight = drawningPlaneHeight; + _drawningPlaneHeight = drawningPlaneHeight; } /// @@ -86,18 +101,16 @@ public class DrawningPlane public bool SetPictureSize(int width, int height) { - - if (height < _drawningSeaplaneHeight || width < _drawningSeaplaneWidth) + if (height < _drawningPlaneHeight || width < _drawningPlaneWidth) { return false; } - _pictureWidth = width; _pictureHeight = height; - if (_startPosX.HasValue && _drawningSeaplaneWidth + _startPosX > width) _startPosX = _pictureWidth - _drawningSeaplaneWidth; - if (_startPosY.HasValue && _drawningSeaplaneHeight + _startPosY > height) _startPosY = _pictureHeight - _drawningSeaplaneHeight; + if (_startPosX.HasValue && _drawningPlaneWidth + _startPosX > width) _startPosX = _pictureWidth - _drawningPlaneWidth; + if (_startPosY.HasValue && _drawningPlaneHeight + _startPosY > height) _startPosY = _pictureHeight - _drawningPlaneHeight; return true; } @@ -116,17 +129,17 @@ public class DrawningPlane { x = 0; } - if (x + _drawningSeaplaneWidth > _pictureWidth.Value) + if (x + _drawningPlaneWidth > _pictureWidth.Value) { - x = _pictureWidth.Value - _drawningSeaplaneWidth; + x = _pictureWidth.Value - _drawningPlaneWidth; } if (y < 0) { y = 0; } - if (y + _drawningSeaplaneHeight > _pictureHeight.Value) + if (y + _drawningPlaneHeight > _pictureHeight.Value) { - y = _pictureHeight.Value - _drawningSeaplaneHeight; + y = _pictureHeight.Value - _drawningPlaneHeight; } _startPosX = x; @@ -163,7 +176,7 @@ public class DrawningPlane return true; // вправо case DirectionType.Right: - if (_startPosX.Value + _drawningSeaplaneWidth + EntityPlane.Step < _pictureWidth) + if (_startPosX.Value + _drawningPlaneWidth + EntityPlane.Step < _pictureWidth) { _startPosX += (int)EntityPlane.Step; } @@ -171,7 +184,7 @@ public class DrawningPlane //вниз case DirectionType.Down: - if (_startPosY.Value + _drawningSeaplaneHeight + EntityPlane.Step < _pictureHeight) + if (_startPosY.Value + _drawningPlaneHeight + EntityPlane.Step < _pictureHeight) { _startPosY += (int)EntityPlane.Step; } @@ -180,6 +193,7 @@ public class DrawningPlane return false; } } + /// /// Прорисовка объекта /// diff --git a/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningSeaplane.cs index 7a32c92..68f7500 100644 --- a/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningSeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/Drawnings/DrawningSeaplane.cs @@ -1,5 +1,4 @@ using ProjectSeaplane.Entities; -using System.Drawing; namespace ProjectSeaplane.Drawnings; /// diff --git a/ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs b/ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs index 3e3dac9..f8fc121 100644 --- a/ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs +++ b/ProjectSeaplane/ProjectSeaplane/Entities/EntityPlane.cs @@ -1,17 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.NetworkInformation; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectSeaplane.Entities; +namespace ProjectSeaplane.Entities; /// /// Класс-сущность "Самолёт" /// - public class EntityPlane { /// diff --git a/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs b/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs index 113ec5b..de0ade8 100644 --- a/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs @@ -4,6 +4,10 @@ /// public class EntitySeaplane : EntityPlane { + public EntitySeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat) : base(speed, weight, bodyColor) + { + } + /// /// Дополнительный цвет (для опциональных элементов) /// diff --git a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs index 59c5859..e8589d4 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.Designer.cs @@ -35,6 +35,8 @@ buttonDown = new Button(); buttonRight = new Button(); buttonCreatePlane = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit(); SuspendLayout(); // @@ -115,13 +117,35 @@ buttonCreatePlane.TabIndex = 6; buttonCreatePlane.Text = "Создать самолёт"; buttonCreatePlane.UseVisualStyleBackColor = true; - buttonCreatePlane.Click += buttonCreatePlane_Click; + buttonCreatePlane.Click += ButtonCreatePlane_Click; + // + // comboBoxStrategy + // + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" }); + comboBoxStrategy.Location = new Point(763, 12); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(121, 23); + comboBoxStrategy.TabIndex = 7; + // + // buttonStrategyStep + // + buttonStrategyStep.Location = new Point(808, 41); + buttonStrategyStep.Name = "buttonStrategyStep"; + buttonStrategyStep.Size = new Size(75, 23); + buttonStrategyStep.TabIndex = 8; + buttonStrategyStep.Text = "Шаг"; + buttonStrategyStep.UseVisualStyleBackColor = true; + buttonStrategyStep.Click += ButtonStrategyStep_Click; // // FormSeaplane // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(900, 500); + Controls.Add(buttonStrategyStep); + Controls.Add(comboBoxStrategy); Controls.Add(buttonCreatePlane); Controls.Add(buttonRight); Controls.Add(buttonDown); @@ -144,5 +168,7 @@ private Button buttonDown; private Button buttonRight; private Button buttonCreatePlane; + private ComboBox comboBoxStrategy; + private Button buttonStrategyStep; } } \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs index cd79f6d..566db95 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplane.cs @@ -1,4 +1,5 @@ using ProjectSeaplane.Drawnings; +using ProjectSeaplane.MovementStrategy; namespace ProjectSeaplane; /// @@ -10,13 +11,21 @@ public partial class FormSeaplane : Form /// Поле-объект для прорисовки объекта /// private DrawningPlane? _drawningPlane; + + /// + /// Стратегия перемещения + /// + private AbstractStrategy? _strategy; + /// /// Конструктор формы /// public FormSeaplane() { InitializeComponent(); + _strategy = null; } + /// /// Метод прорисовки машины /// @@ -56,6 +65,9 @@ public partial class FormSeaplane : Form } _drawningPlane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); _drawningPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); + _strategy = null; + comboBoxStrategy.Enabled = true; + Draw(); } @@ -72,7 +84,7 @@ public partial class FormSeaplane : Form /// /// /// - private void buttonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane)); + private void ButtonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane)); /// /// Перемещение объекта по форме (нажатие кнопок навигации) @@ -107,4 +119,45 @@ public partial class FormSeaplane : Form Draw(); } } + + /// + /// Обработка нажатия кнопки "Шаг" + /// + /// + /// + private void ButtonStrategyStep_Click(object sender, EventArgs e) + { + if (_drawningPlane == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _strategy = comboBoxStrategy.SelectedIndex switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_strategy == null) + { + return; + } + _strategy.SetData(new MoveablePlane(_drawningPlane), pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); + } + if (_strategy == null) + { + return; + } + + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); + Draw(); + + if (_strategy.GetStatus() == StrategyStatus.Finish) + { + comboBoxStrategy.Enabled = true; + _strategy = null; + } + } } diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/AbstractStrategy.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/AbstractStrategy.cs new file mode 100644 index 0000000..2750643 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/AbstractStrategy.cs @@ -0,0 +1,138 @@ +namespace ProjectSeaplane.MovementStrategy; + +/// +/// Класс перемещения объекта +/// +public abstract class AbstractStrategy +{ + /// + /// Перемещаемый объект + /// + private IMoveableObject? _moveableObject; + + /// + /// Статус перемещения + /// + private StrategyStatus _state = StrategyStatus.NotInit; + + /// + /// Ширина поля + /// + protected int FieldWidth { get; private set; } + + /// + /// Высота поля + /// + protected int FieldHeight { get; private set; } + + /// + /// Статус перемещения + /// + public StrategyStatus GetStatus() { return _state; } + + /// + /// Установка данных + /// + /// Перемещаемый объект + /// Ширина поля + /// Высота поля + public void SetData(IMoveableObject moveableObject, int width, int height) + { + if (moveableObject == null) + { + _state = StrategyStatus.NotInit; + return; + } + + _state = StrategyStatus.InProgress; + _moveableObject = moveableObject; + 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; + } +} \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/IMoveableObject.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/IMoveableObject.cs new file mode 100644 index 0000000..2e61bb1 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/IMoveableObject.cs @@ -0,0 +1,24 @@ +namespace ProjectSeaplane.MovementStrategy; + +/// +/// Интерфейс для работы с перемещаемым объектом +/// +public interface IMoveableObject +{ + /// + /// Получение координаты объекта + /// + ObjectParameters? GetObjectPosition { get; } + + /// + /// Шаг объекта + /// + int GetStep { get; } + + /// + /// Попытка переместить объект в указанном направлении + /// + /// Направление + /// true - объект перемещен, false - перемещение невозможно + bool TryMoveObject(MovementDirection direction); +} diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToBorder.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToBorder.cs new file mode 100644 index 0000000..2b3c748 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToBorder.cs @@ -0,0 +1,51 @@ +namespace ProjectSeaplane.MovementStrategy; + +/// +/// Стратегия перемещения объекта в угол экрана +/// + +public class MoveToBorder : AbstractStrategy +{ + protected override bool IsTargetDestinaion() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight; + } + + protected override void MoveToTarget() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + int diffX = objParams.RightBorder - FieldWidth; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + int diffY = objParams.DownBorder - FieldHeight; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } +} \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToCenter.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToCenter.cs new file mode 100644 index 0000000..12012c2 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveToCenter.cs @@ -0,0 +1,50 @@ +namespace ProjectSeaplane.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(); + } + } + } +} \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveablePlane.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveablePlane.cs new file mode 100644 index 0000000..e9852e1 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MoveablePlane.cs @@ -0,0 +1,61 @@ +using ProjectSeaplane.Drawnings; + +namespace ProjectSeaplane.MovementStrategy; + +/// +/// Класс-реализация IMoveableObject с использованием DrawningPlane +/// +public class MoveablePlane : IMoveableObject +{ + /// + /// Поле-объект класса DrawningPlane или его наследника + /// + private readonly DrawningPlane? _plane = null; + + /// + /// Конструктор + /// + /// Объект класса DrawningPlane + public MoveablePlane(DrawningPlane plane) + { + _plane = plane; + } + public ObjectParameters? GetObjectPosition + { + get + { + if (_plane == null || _plane.EntityPlane == null || !_plane.GetPosX.HasValue || !_plane.GetPosY.HasValue) + { + return null; + } + return new ObjectParameters(_plane.GetPosX.Value, _plane.GetPosY.Value, _plane.GetWidth, _plane.GetHeight); + } + } + public int GetStep => (int)(_plane?.EntityPlane?.Step ?? 0); + public bool TryMoveObject(MovementDirection direction) + { + if (_plane == null || _plane.EntityPlane == null) + { + return false; + } + return _plane.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, + }; + } + +} \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MovementDirection.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MovementDirection.cs new file mode 100644 index 0000000..07ff2e8 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/MovementDirection.cs @@ -0,0 +1,32 @@ +namespace ProjectSeaplane.MovementStrategy; + +/// +/// Направление перемещения +/// +public enum MovementDirection +{ + /// + /// Неизвестное направление + /// + Unknow = -1, + + /// + /// Вверх + /// + Up = 1, + + /// + /// Вниз + /// + Down = 2, + + /// + /// Влево + /// + Left = 3, + + /// + /// Вправо + /// + Right = 4 +} diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/ObjectParameters.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..ba982d9 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,72 @@ +namespace ProjectSeaplane.MovementStrategy; + +/// +/// Параметры-координаты объекта +/// +public class ObjectParameters +{ + /// + /// Координата X + /// + private readonly int _x; + + /// + /// Координата Y + /// + 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; + + /// + /// Конструктор + /// + /// Координата X + /// Координата Y + /// Ширина объекта + /// Высота объекта + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } +} \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/MovementStrategy/StrategyStatus.cs b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/StrategyStatus.cs new file mode 100644 index 0000000..020c989 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/MovementStrategy/StrategyStatus.cs @@ -0,0 +1,22 @@ +namespace ProjectSeaplane.MovementStrategy; + +/// +/// Статус выполнения операции перемещения +/// +public enum StrategyStatus +{ + /// + /// Все готово к началу + /// + NotInit, + + /// + /// Выполняется + /// + InProgress, + + /// + /// Завершено + /// + Finish +} -- 2.25.1 From bc3d9cac6b784b9dc58eab01997d7880407bfa0d Mon Sep 17 00:00:00 2001 From: ShuryginDima Date: Wed, 13 Mar 2024 17:43:14 +0300 Subject: [PATCH 3/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=BF=D1=80=D0=B0=D0=B2=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs b/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs index de0ade8..e97ba9c 100644 --- a/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs @@ -4,10 +4,6 @@ /// public class EntitySeaplane : EntityPlane { - public EntitySeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat) : base(speed, weight, bodyColor) - { - } - /// /// Дополнительный цвет (для опциональных элементов) /// @@ -33,7 +29,7 @@ public class EntitySeaplane : EntityPlane /// Дополнительный цвет /// Признак наличия поплавков /// Признак наличия лодки - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat) + public EntitySeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool boat) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; Floats = floats; -- 2.25.1