From 4b6aa63101528da631c42197b511e8d0d1c513f0 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Fri, 6 Oct 2023 16:47:13 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=BB=D0=B0=D0=B12=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=8F.=20=D0=9B=D1=91=D0=B2=D1=83=D1=88?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD=D0=B0=20=D0=90.=D0=90.=20=D0=BF=D0=B8=D0=B1?= =?UTF-8?q?=D0=B4-21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lab1ContainersShip/AbstractStrategy.cs | 139 +++++++++++ .../DrawingContainerShip.cs | 150 ++--------- .../Lab1ContainersShip/DrawingShip.cs | 233 ++++++++++++++++++ .../Lab1ContainersShip/DrawningObjectShip.cs | 36 +++ .../Lab1ContainersShip/EntityContainerShip.cs | 29 +-- .../Lab1ContainersShip/EntityShip.cs | 49 ++++ .../Lab1ContainersShip/Form1.Designer.cs | 69 ++++-- .../Lab1ContainersShip/Form1.cs | 125 ++++++++-- .../Lab1ContainersShip/IMoveableObject.cs | 36 +++ .../Lab1ContainersShip.csproj | 9 + .../Lab1ContainersShip/MoveToBorder.cs | 56 +++++ .../Lab1ContainersShip/MoveToCenter.cs | 58 +++++ .../Lab1ContainersShip/ObjectParameters.cs | 58 +++++ .../Lab1ContainersShip/Status.cs | 19 ++ 14 files changed, 882 insertions(+), 184 deletions(-) create mode 100644 Lab1ContainersShip/Lab1ContainersShip/AbstractStrategy.cs create mode 100644 Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs create mode 100644 Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs create mode 100644 Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs create mode 100644 Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs create mode 100644 Lab1ContainersShip/Lab1ContainersShip/MoveToBorder.cs create mode 100644 Lab1ContainersShip/Lab1ContainersShip/MoveToCenter.cs create mode 100644 Lab1ContainersShip/Lab1ContainersShip/ObjectParameters.cs create mode 100644 Lab1ContainersShip/Lab1ContainersShip/Status.cs diff --git a/Lab1ContainersShip/Lab1ContainersShip/AbstractStrategy.cs b/Lab1ContainersShip/Lab1ContainersShip/AbstractStrategy.cs new file mode 100644 index 0000000..eb4a5e2 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/AbstractStrategy.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Lab1ContainersShip.DrawingObjects; + + +namespace Lab1ContainersShip.MovementStrategy +{ + public abstract class AbstractStrategy + { + /// + /// Перемещаемый объект + /// + private IMoveableObject _moveableObject; + /// + /// Статус перемещения + /// + private Status _state = Status.NotInit; + /// + /// Ширина поля + /// + protected int FieldWidth { get; private set; } + /// + /// Высота поля + /// + protected int FieldHeight { get; private set; } + /// + /// Статус перемещения + /// + public Status GetStatus() { return _state; } + /// + /// Установка данных + /// + /// Перемещаемый объект + /// Ширина поля + /// Высота поля + public void SetData(IMoveableObject moveableObject, int width, int + height) + { + if (moveableObject == null) + { + _state = Status.NotInit; + return; + } + _state = Status.InProgress; + _moveableObject = moveableObject; + FieldWidth = width; + FieldHeight = height; + } + /// + /// Шаг перемещения + /// + public void MakeStep() + { + if (_state != Status.InProgress) + { + return; + } + if (IsTargetDestinaion()) + { + _state = Status.Finish; + return; + } + MoveToTarget(); + } + /// + /// Перемещение влево + /// + /// Результат перемещения (true - удалось переместиться, false - + //неудача) + protected bool MoveLeft() => MoveTo(Direction.Left); + /// + /// Перемещение вправо + /// + /// Результат перемещения (true - удалось переместиться, + //false - неудача) + protected bool MoveRight() => MoveTo(Direction.Right); + /// + /// Перемещение вверх + /// + /// Результат перемещения (true - удалось переместиться, + //false - неудача) + protected bool MoveUp() => MoveTo(Direction.Up); + /// + /// Перемещение вниз + /// + /// Результат перемещения (true - удалось переместиться, + //false - неудача) + protected bool MoveDown() => MoveTo(Direction.Down); + /// + /// Параметры объекта + /// + protected ObjectParameters GetObjectParameters => + _moveableObject?.GetObjectPosition; + /// + /// Шаг объекта + /// + /// + protected int? GetStep() + { + if (_state != Status.InProgress) + { + return null; + } + return _moveableObject?.GetStep; + } + /// + /// Перемещение к цели + /// + protected abstract void MoveToTarget(); + /// + /// Достигнута ли цель + /// + /// + protected abstract bool IsTargetDestinaion(); + /// + /// Попытка перемещения в требуемом направлении + /// + /// Направление + /// Результат попытки (true - удалось переместиться, false - + //неудача) + private bool MoveTo(Direction direction) + { + if (_state != Status.InProgress) + { + return false; + } + if (_moveableObject?.CheckCanMove(direction) ?? false) + { + _moveableObject.MoveObject(direction); + return true; + } + return false; + } + + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs index 1313ff8..af1ebf8 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs @@ -2,151 +2,41 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; +using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; +using Lab1ContainersShip.Entities; -namespace Lab1ContainersShip +namespace Lab1ContainersShip.DrawingObjects { - public class DrawingContainerShip + internal class DrawingContainerShip : DrawingShip { - /// - /// Класс-сущность - /// - public EntityContainerShip EntityContainerShip { get; private set; } - /// - /// Ширина окна - /// - private int _pictureWidth; - /// - /// Высота окна - /// - private int _pictureHeight; - /// - /// Левая координата прорисовки автомобиля - /// - private int _startPosX; - /// - /// Верхняя кооридната прорисовки автомобиля - /// - private int _startPosY; - /// - /// Ширина прорисовки автомобиля - /// - private readonly int _shipWidth = 110; - /// - /// Высота прорисовки автомобиля - /// - private readonly int _shipHeight = 65; - - public bool Init(int speed, double weight, Color bodyColor, Color -additionalColor, bool crane, bool container, int width, int height) - { - // TODO: Продумать проверки - _pictureWidth = width; - _pictureHeight = height; - if (_pictureWidth < _shipWidth || _pictureHeight < _shipHeight) + public DrawingContainerShip(int speed, double weight, Color bodyColor, Color +additionalColor, bool crane, bool containers, int width, int height) : + base(speed, weight, bodyColor,width, height, 110, 65) { + if (EntityShip != null) { - return false; + EntityShip = new EntityContainerShip(speed, weight, bodyColor, + additionalColor, crane, containers); } - EntityContainerShip = new EntityContainerShip(); - EntityContainerShip.Init(speed, weight, bodyColor, additionalColor, - crane, container); - - return true; } - /*public bool Init(EntityContainerShip entcon, int wid, int hei) + public override void DrawShip(Graphics g) { - _pictureWidth = wid; - _pictureHeight = hei; - if (_pictureWidth < _shipWidth || _pictureHeight < _shipHeight) + /*if (EntityShip is not EntityContainerShip containerShip) { - return false; - } - EntityContainerShip = entcon; - return true; - - }*/ - - - public void SetPosition(int x, int y) - { - // TODO: Изменение x, y - _startPosX = Math.Min(x, _pictureWidth - _shipWidth); - _startPosY = Math.Min(y, _pictureHeight - _shipHeight); - } - public void MoveTransport(Direction direction) - { - if (EntityContainerShip == null) + return; + }*/ + if(EntityShip == null) { return; } - switch (direction) - { - //влево - case Direction.Left: - if (_startPosX - EntityContainerShip.Step > 0) - { - _startPosX -= (int)EntityContainerShip.Step; - } - break; - //вверх - case Direction.Up: - if (_startPosY - EntityContainerShip.Step > 0) - { - _startPosY -= (int)EntityContainerShip.Step; - } - break; - // вправо - case Direction.Right: - // TODO: Продумать логику - if (_startPosX + EntityContainerShip.Step + _shipWidth < _pictureWidth) - { - _startPosX += (int)EntityContainerShip.Step; - } - break; - //вниз - case Direction.Down: - // TODO: Продумать логику - if (_startPosY + EntityContainerShip.Step + _shipHeight< _pictureHeight) - { - _startPosY += (int)EntityContainerShip.Step; - } - break; - } - } - public void DrawShip(Graphics g) - { - if (EntityContainerShip == null) - { + if(!(EntityShip is EntityContainerShip)) { return; } Pen pen = new Pen(Color.Black); - Brush adbrush = new SolidBrush(EntityContainerShip.AdditionalColor); - Brush brBlue = new SolidBrush(Color.Blue); - // заполнение борта - g.FillPolygon(brBlue, new PointF[] - { - new PointF(_startPosX, _startPosY+45), - new PointF(_startPosX+20, _startPosY+65), - new PointF(_startPosX+90, _startPosY+65), - new PointF(_startPosX+110, _startPosY+45), - new PointF(_startPosX, _startPosY+45) - }); - //борт корабля контур - g.DrawLines(pen, new Point[] { - new Point(_startPosX, _startPosY+45), - new Point(_startPosX+20, _startPosY+65), - new Point(_startPosX+90, _startPosY+65), - new Point(_startPosX+110, _startPosY+45), - new Point(_startPosX, _startPosY+45)}); - - //рисунок на борту - g.DrawLine(pen, _startPosX + 23, _startPosY + 60, _startPosX + 27, _startPosY + 60); - g.DrawLine(pen, _startPosX + 25, _startPosY + 50, _startPosX + 25, _startPosY + 60); - g.DrawLine(pen, _startPosX + 20, _startPosY + 55, _startPosX + 30, _startPosY + 55); - - //контейнеры - if (EntityContainerShip.Conteiners) + Brush adbrush = new SolidBrush((EntityShip as EntityContainerShip).AdditionalColor); + base.DrawShip(g); + if ((EntityShip as EntityContainerShip).Conteiners) { g.FillRectangle(adbrush, _startPosX + 30, _startPosY + 35, 35, 10); g.FillRectangle(adbrush, _startPosX + 65, _startPosY + 35, 20, 10); @@ -163,7 +53,7 @@ additionalColor, bool crane, bool container, int width, int height) g.DrawRectangle(pen, _startPosX + 45, _startPosY + 30, 40, 5); } //кран - if (EntityContainerShip.Crane) + if ((EntityShip as EntityContainerShip).Crane) { g.FillRectangle(adbrush, _startPosX + 23, _startPosY, 5, 45); g.FillRectangle(adbrush, _startPosX + 27, _startPosY + 10, 20, 3); diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs new file mode 100644 index 0000000..ab668d8 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs @@ -0,0 +1,233 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Lab1ContainersShip.Entities; + +namespace Lab1ContainersShip.DrawingObjects +{ + public class DrawingShip + { + /// + /// Класс-сущность + /// + public EntityShip EntityShip { get; protected set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата прорисовки автомобиля + /// + protected int _startPosX; + /// + /// Верхняя кооридната прорисовки автомобиля + /// + protected int _startPosY; + /// + /// Ширина прорисовки автомобиля + /// + private readonly int _shipWidth = 110; + /// + /// Высота прорисовки автомобиля + /// + private readonly int _shipHeight = 65; + /// + /// Координата X объекта + /// + public int GetPosX => _startPosX; + /// + /// Координата Y объекта + /// + public int GetPosY => _startPosY; + /// + /// Ширина объекта + /// + public int GetWidth => _shipWidth; + /// + /// Высота объекта + /// + public int GetHeight => _shipHeight; + public bool CanMove(Direction direction) + { + if(EntityShip == null) return false; + switch(direction) + { + case Direction.Left: + return _startPosX - EntityShip.Step > 0; + case Direction.Right: + return _startPosX + _shipWidth + EntityShip.Step < _pictureWidth; + case Direction.Up: + return _startPosY - EntityShip.Step > 0; + case Direction.Down: + return _startPosY + _shipHeight+ EntityShip.Step < _pictureHeight; + default: + return false; + } + } + + /*public bool Init(int speed, double weight, Color bodyColor, Color +additionalColor, bool crane, bool container, int width, int height) + { + // TODO: Продумать проверки + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth < _shipWidth || _pictureHeight < _shipHeight) + { + return false; + } + EntityShip = new EntityShip(); + EntityShip.Init(speed, weight, bodyColor, additionalColor, + crane, container); + + return true; + }*/ + public DrawingShip(int speed, double weight, Color bodyColor, int width, int height) + { + if(width < _shipWidth || height < _shipHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + EntityShip = new EntityShip(speed, weight, bodyColor); + } + protected DrawingShip(int speed, double weight, Color bodyColor, int width, int height, int shipWidth, int shipHeight) + { + if (width < _shipWidth || height < _shipHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + _shipHeight = shipHeight; + _shipWidth = shipWidth; + EntityShip = new EntityShip(speed, weight, bodyColor); + } + /*public bool Init(EntityContainerShip entcon, int wid, int hei) + { + _pictureWidth = wid; + _pictureHeight = hei; + if (_pictureWidth < _shipWidth || _pictureHeight < _shipHeight) + { + return false; + } + EntityContainerShip = entcon; + return true; + + }*/ + + + public void SetPosition(int x, int y) + { + // TODO: Изменение x, y + _startPosX = Math.Min(x, _pictureWidth - _shipWidth); + _startPosY = Math.Min(y, _pictureHeight - _shipHeight); + } + public void MoveTransport(Direction direction) + { + if (!CanMove(direction) || EntityShip == null) + { + return; + } + switch (direction) + { + //влево + case Direction.Left: + if (_startPosX - EntityShip.Step > 0) + { + _startPosX -= (int)EntityShip.Step; + } + break; + //вверх + case Direction.Up: + if (_startPosY - EntityShip.Step > 0) + { + _startPosY -= (int)EntityShip.Step; + } + break; + // вправо + case Direction.Right: + // TODO: Продумать логику + if (_startPosX + EntityShip.Step + _shipWidth < _pictureWidth) + { + _startPosX += (int)EntityShip.Step; + } + break; + //вниз + case Direction.Down: + // TODO: Продумать логику + if (_startPosY + EntityShip.Step + _shipHeight< _pictureHeight) + { + _startPosY += (int)EntityShip.Step; + } + break; + } + } + public virtual void DrawShip(Graphics g) + { + if (EntityShip == null) + { + return; + } + Pen pen = new Pen(Color.Black); + //Brush adbrush = new SolidBrush(EntityShip.AdditionalColor); + Brush brBlue = new SolidBrush(Color.Blue); + // заполнение борта + g.FillPolygon(brBlue, new PointF[] + { + new PointF(_startPosX, _startPosY+45), + new PointF(_startPosX+20, _startPosY+65), + new PointF(_startPosX+90, _startPosY+65), + new PointF(_startPosX+110, _startPosY+45), + new PointF(_startPosX, _startPosY+45) + }); + //борт корабля контур + g.DrawLines(pen, new Point[] { + new Point(_startPosX, _startPosY+45), + new Point(_startPosX+20, _startPosY+65), + new Point(_startPosX+90, _startPosY+65), + new Point(_startPosX+110, _startPosY+45), + new Point(_startPosX, _startPosY+45)}); + + //рисунок на борту + g.DrawLine(pen, _startPosX + 23, _startPosY + 60, _startPosX + 27, _startPosY + 60); + g.DrawLine(pen, _startPosX + 25, _startPosY + 50, _startPosX + 25, _startPosY + 60); + g.DrawLine(pen, _startPosX + 20, _startPosY + 55, _startPosX + 30, _startPosY + 55); + + //контейнеры + /*if (EntityShip.Conteiners) + { + g.FillRectangle(adbrush, _startPosX + 30, _startPosY + 35, 35, 10); + g.FillRectangle(adbrush, _startPosX + 65, _startPosY + 35, 20, 10); + g.FillRectangle(adbrush, _startPosX + 85, _startPosY + 30, 15, 15); + g.FillRectangle(adbrush, _startPosX + 30, _startPosY + 25, 15, 10); + g.FillRectangle(adbrush, _startPosX + 45, _startPosY + 25, 55, 5); + g.FillRectangle(adbrush, _startPosX + 45, _startPosY + 30, 40, 5); + + g.DrawRectangle(pen, _startPosX + 30, _startPosY + 35, 35, 10); + g.DrawRectangle(pen, _startPosX + 65, _startPosY + 35, 20, 10); + g.DrawRectangle(pen, _startPosX + 85, _startPosY + 30, 15, 15); + g.DrawRectangle(pen, _startPosX + 30, _startPosY + 25, 15, 10); + g.DrawRectangle(pen, _startPosX + 45, _startPosY + 25, 55, 5); + g.DrawRectangle(pen, _startPosX + 45, _startPosY + 30, 40, 5); + } + //кран + if (EntityShip.Crane) + { + g.FillRectangle(adbrush, _startPosX + 23, _startPosY, 5, 45); + g.FillRectangle(adbrush, _startPosX + 27, _startPosY + 10, 20, 3); + g.DrawRectangle(pen, _startPosX + 23, _startPosY, 5, 45); + g.DrawRectangle(pen, _startPosX + 27, _startPosY + 10, 20, 3); + g.DrawLine(pen, _startPosX + 27, _startPosY, _startPosX + 47, _startPosY + 10); + g.DrawLine(pen, _startPosX + 47, _startPosY + 13, _startPosX + 47, _startPosY + 25); + }*/ + } + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs new file mode 100644 index 0000000..6cd7276 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Lab1ContainersShip.DrawingObjects; + +namespace Lab1ContainersShip.MovementStrategy +{ + public class DrawningObjectShip : IMoveableObject + { + private readonly DrawingShip _drawingShip = null; + public DrawningObjectShip(DrawingShip drawingShip) + { + _drawingShip = drawingShip; + } + public ObjectParameters GetObjectPosition + { + get + { + if (_drawingShip == null || _drawingShip.EntityShip == + null) + { + return null; + } + return new ObjectParameters(_drawingShip.GetPosX, + _drawingShip.GetPosY, _drawingShip.GetWidth, _drawingShip.GetHeight); + } + } + public int GetStep => (int)(_drawingShip?.EntityShip.Step ?? 0); + public bool CheckCanMove(Direction direction) => + _drawingShip?.CanMove(direction) ?? false; + public void MoveObject(Direction direction) => + _drawingShip?.MoveTransport(direction); + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs b/Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs index 21fee7c..3d9dde6 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/EntityContainerShip.cs @@ -5,28 +5,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Lab1ContainersShip +namespace Lab1ContainersShip.Entities { - public class EntityContainerShip + internal class EntityContainerShip : EntityShip { - /// - /// Скорость - /// - public int Speed { get; private set; } - /// - /// Вес - /// - public double Weight { get; private set; } - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - /// - /// Дополнительный цвет (для опциональных элементов) - /// public Color AdditionalColor { get; private set; } - - /// /// Признак (опция) наличия крана /// @@ -35,13 +18,9 @@ namespace Lab1ContainersShip /// Признак (опция) наличия контейнеров /// public bool Conteiners { get; private set; } - public double Step => (double)Speed * 100 / Weight; - public void Init(int speed, double weight, Color bodyColor, Color -additionalColor, bool crane, bool containers) + public EntityContainerShip(int speed, double weight, Color bodyColor, Color additionalColor, + bool crane, bool containers ) : base (speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; Crane = crane; Conteiners = containers; diff --git a/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs b/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs new file mode 100644 index 0000000..cd16399 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lab1ContainersShip.Entities +{ + public class EntityShip + { + /// + /// Скорость + /// + 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 Crane { get; private set; } + /// + /// Признак (опция) наличия контейнеров + /// + //public bool Conteiners { get; private set; } + public double Step => (double)Speed * 100 / Weight; + public EntityShip(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + //AdditionalColor = additionalColor; + //Crane = crane; + //Conteiners = containers; + } + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/Form1.Designer.cs b/Lab1ContainersShip/Lab1ContainersShip/Form1.Designer.cs index e4820ff..9b828dc 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/Form1.Designer.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/Form1.Designer.cs @@ -28,26 +28,18 @@ /// private void InitializeComponent() { - this.buttonCreate = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); + this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); + this.buttonStep = new System.Windows.Forms.Button(); + this.buttonCreateContainerShip = new System.Windows.Forms.Button(); + this.buttonCreateShip = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // - // buttonCreate - // - this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreate.Location = new System.Drawing.Point(12, 426); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(75, 23); - this.buttonCreate.TabIndex = 1; - this.buttonCreate.Text = "создать"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); - // // buttonUp // this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); @@ -69,7 +61,6 @@ this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; - this.pictureBox1.Click += new System.EventHandler(this.buttonMove_Click); // // buttonRight // @@ -107,16 +98,61 @@ this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); // + // comboBoxStrategy + // + this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxStrategy.FormattingEnabled = true; + this.comboBoxStrategy.Items.AddRange(new object[] { + "MoveToCenter", + "MoveToRight-Down"}); + this.comboBoxStrategy.Location = new System.Drawing.Point(751, 12); + this.comboBoxStrategy.Name = "comboBoxStrategy"; + this.comboBoxStrategy.Size = new System.Drawing.Size(121, 21); + this.comboBoxStrategy.TabIndex = 6; + // + // buttonStep + // + this.buttonStep.Location = new System.Drawing.Point(797, 39); + this.buttonStep.Name = "buttonStep"; + this.buttonStep.Size = new System.Drawing.Size(75, 23); + this.buttonStep.TabIndex = 7; + this.buttonStep.Text = "шаг"; + this.buttonStep.UseVisualStyleBackColor = true; + this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click); + // + // buttonCreateContainerShip + // + this.buttonCreateContainerShip.Location = new System.Drawing.Point(12, 411); + this.buttonCreateContainerShip.Name = "buttonCreateContainerShip"; + this.buttonCreateContainerShip.Size = new System.Drawing.Size(97, 38); + this.buttonCreateContainerShip.TabIndex = 8; + this.buttonCreateContainerShip.Text = "создать контейнеровоз"; + this.buttonCreateContainerShip.UseVisualStyleBackColor = true; + this.buttonCreateContainerShip.Click += new System.EventHandler(this.buttonCreateContainerShip_Click); + // + // buttonCreateShip + // + this.buttonCreateShip.Location = new System.Drawing.Point(115, 411); + this.buttonCreateShip.Name = "buttonCreateShip"; + this.buttonCreateShip.Size = new System.Drawing.Size(94, 38); + this.buttonCreateShip.TabIndex = 9; + this.buttonCreateShip.Text = "создать кораблик"; + this.buttonCreateShip.UseVisualStyleBackColor = true; + this.buttonCreateShip.Click += new System.EventHandler(this.buttonCreateShip_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(884, 461); + this.Controls.Add(this.buttonCreateShip); + this.Controls.Add(this.buttonCreateContainerShip); + this.Controls.Add(this.buttonStep); + this.Controls.Add(this.comboBoxStrategy); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonCreate); this.Controls.Add(this.pictureBox1); this.Name = "Form1"; this.Text = "контейнеровоз"; @@ -129,11 +165,14 @@ #endregion private System.Windows.Forms.PictureBox pictureBox1; - private System.Windows.Forms.Button buttonCreate; private System.Windows.Forms.Button buttonUp; private System.Windows.Forms.Button buttonRight; private System.Windows.Forms.Button buttonLeft; private System.Windows.Forms.Button buttonDown; + private System.Windows.Forms.ComboBox comboBoxStrategy; + private System.Windows.Forms.Button buttonStep; + private System.Windows.Forms.Button buttonCreateContainerShip; + private System.Windows.Forms.Button buttonCreateShip; } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/Form1.cs b/Lab1ContainersShip/Lab1ContainersShip/Form1.cs index a8be313..787fb19 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/Form1.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/Form1.cs @@ -7,13 +7,21 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Lab1ContainersShip.DrawingObjects; +using Lab1ContainersShip.MovementStrategy; namespace Lab1ContainersShip { public partial class Form1 : Form { - private DrawingContainerShip _drawningShip; - + private DrawingShip _drawingShip; + + /// + /// Стратегия перемещения + /// + private AbstractStrategy _abstractStrategy; + + public Form1() { InitializeComponent(); @@ -31,23 +39,31 @@ namespace Lab1ContainersShip /// private void Draw() { - if (_drawningShip == null) + + if (_drawingShip == null) { return; } Bitmap bmp = new Bitmap (pictureBox1.Width, pictureBox1.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningShip.DrawShip(gr); + if(_drawingShip is DrawingShip) + { + (_drawingShip as DrawingShip).DrawShip(gr); + } + else + { + _drawingShip.DrawShip(gr); + } pictureBox1.Image = bmp; } - private void buttonCreate_Click(object sender, EventArgs e) + /*private void buttonCreate_Click(object sender, EventArgs e) { Random random = new Random(); - _drawningShip = new DrawingContainerShip(); - EntityContainerShip _entitycont = new EntityContainerShip(); + _drawningShip = new DrawingShip(); + EntityShip _entitycont = new EntityShip();*/ /*_entitycont.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), @@ -56,7 +72,7 @@ namespace Lab1ContainersShip random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));*/ - _drawningShip.Init(random.Next(100, 300), + /*_drawningShip.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), @@ -69,10 +85,10 @@ namespace Lab1ContainersShip _drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); - } + }*/ private void buttonMove_Click(object sender, EventArgs e) { - if (_drawningShip == null) + if (_drawingShip == null) { return; } @@ -80,19 +96,100 @@ namespace Lab1ContainersShip switch (name) { case "buttonUp": - _drawningShip.MoveTransport(Direction.Up); + _drawingShip.MoveTransport(Direction.Up); break; case "buttonDown": - _drawningShip.MoveTransport(Direction.Down); + _drawingShip.MoveTransport(Direction.Down); break; case "buttonLeft": - _drawningShip.MoveTransport(Direction.Left); + _drawingShip.MoveTransport(Direction.Left); break; case "buttonRight": - _drawningShip.MoveTransport(Direction.Right); + _drawingShip.MoveTransport(Direction.Right); break; } Draw(); } + + private void buttonStep_Click(object sender, EventArgs e) + { + if (_drawingShip == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + /*_abstractStrategy = comboBoxStrategy.SelectedIndex + switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + };*/ + switch (comboBoxStrategy.SelectedIndex) + { + case 0: + _abstractStrategy = new MoveToCenter(); + break; + case 1: + _abstractStrategy = new MoveToBorder(); + break; + default: + _abstractStrategy = null; + break; + } + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.SetData(new + DrawningObjectShip(_drawingShip), pictureBox1.Width, + pictureBox1.Height); + comboBoxStrategy.Enabled = false; + } + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.MakeStep(); + Draw(); + if (_abstractStrategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.Enabled = true; + _abstractStrategy = null; + } + + } + + private void buttonCreateContainerShip_Click(object sender, EventArgs e) + { + Random random = new Random(); + _drawingShip = new DrawingContainerShip(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)), + pictureBox1.Width, pictureBox1.Height); + _drawingShip.SetPosition(random.Next(10, 100), random.Next(10, + 100)); + Draw(); + } + + private void buttonCreateShip_Click(object sender, EventArgs e) + { + Random random = new Random(); + _drawingShip = new DrawingShip(random.Next(100, 300), + random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), + pictureBox1.Width, pictureBox1.Height); + _drawingShip.SetPosition(random.Next(10, 100), random.Next(10, + 100)); + Draw(); + + } } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs b/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs new file mode 100644 index 0000000..80123fa --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Lab1ContainersShip.DrawingObjects; + +namespace Lab1ContainersShip.MovementStrategy +{ + /// + /// Интерфейс для работы с перемещаемым объектом + /// + public interface IMoveableObject + { + /// + /// Получение координаты X объекта + /// + ObjectParameters GetObjectPosition { get; } + /// + /// Шаг объекта + /// + int GetStep { get; } + /// + /// Проверка, можно ли переместиться по нужному направлению + /// + /// + /// + bool CheckCanMove(Direction direction); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + void MoveObject(Direction direction); + + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj index 4afc3bc..9456ae0 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj +++ b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj @@ -46,17 +46,26 @@ + + + + Form Form1.cs + + + + + Form1.cs diff --git a/Lab1ContainersShip/Lab1ContainersShip/MoveToBorder.cs b/Lab1ContainersShip/Lab1ContainersShip/MoveToBorder.cs new file mode 100644 index 0000000..d2b5ffe --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/MoveToBorder.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lab1ContainersShip.MovementStrategy +{ + internal class MoveToBorder : AbstractStrategy + { + protected override bool IsTargetDestinaion() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.RightBorder <= FieldWidth && + objParams.RightBorder + GetStep() >= FieldWidth && + objParams.DownBorder <= FieldHeight && + objParams.DownBorder + GetStep() >= FieldHeight; + } + protected override void MoveToTarget() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + var diffX = objParams.RightBorder - FieldWidth; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + var diffY = objParams.DownBorder - FieldHeight; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/MoveToCenter.cs b/Lab1ContainersShip/Lab1ContainersShip/MoveToCenter.cs new file mode 100644 index 0000000..7ca2678 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/MoveToCenter.cs @@ -0,0 +1,58 @@ +using Lab1ContainersShip.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lab1ContainersShip.MovementStrategy +{ + public class MoveToCenter : AbstractStrategy + { + protected override bool IsTargetDestinaion() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && + objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && + objParams.ObjectMiddleVertical <= FieldHeight / 2 && + objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2; + } + protected override void MoveToTarget() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } + + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/ObjectParameters.cs b/Lab1ContainersShip/Lab1ContainersShip/ObjectParameters.cs new file mode 100644 index 0000000..32db3d4 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/ObjectParameters.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lab1ContainersShip.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; + /// + /// Конструктор + /// + /// Координата X + /// Координата Y + /// Ширина + /// Высота + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } + + } +} diff --git a/Lab1ContainersShip/Lab1ContainersShip/Status.cs b/Lab1ContainersShip/Lab1ContainersShip/Status.cs new file mode 100644 index 0000000..08e84f2 --- /dev/null +++ b/Lab1ContainersShip/Lab1ContainersShip/Status.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lab1ContainersShip.MovementStrategy +{ + /// + /// Статус выполнения операции перемещения + /// + public enum Status + { + NotInit, + InProgress, + Finish + + } +} -- 2.25.1 From 1641fc1883cf0f82febde749865735c421fa6636 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Fri, 6 Oct 2023 17:29:40 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=BB=D0=B0=D0=B12.=D0=B8=D0=B7=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingContainerShip.cs | 5 +- .../Lab1ContainersShip/DrawingShip.cs | 61 ++----------------- .../Lab1ContainersShip/EntityShip.cs | 4 +- .../Lab1ContainersShip/Form1.cs | 50 +-------------- 4 files changed, 9 insertions(+), 111 deletions(-) diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs index af1ebf8..bbfee78 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawingContainerShip.cs @@ -22,10 +22,7 @@ additionalColor, bool crane, bool containers, int width, int height) : } public override void DrawShip(Graphics g) { - /*if (EntityShip is not EntityContainerShip containerShip) - { - return; - }*/ + if(EntityShip == null) { return; diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs index ab668d8..a080e88 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs @@ -10,9 +10,7 @@ namespace Lab1ContainersShip.DrawingObjects { public class DrawingShip { - /// - /// Класс-сущность - /// + public EntityShip EntityShip { get; protected set; } /// /// Ширина окна @@ -72,22 +70,7 @@ namespace Lab1ContainersShip.DrawingObjects } } - /*public bool Init(int speed, double weight, Color bodyColor, Color -additionalColor, bool crane, bool container, int width, int height) - { - // TODO: Продумать проверки - _pictureWidth = width; - _pictureHeight = height; - if (_pictureWidth < _shipWidth || _pictureHeight < _shipHeight) - { - return false; - } - EntityShip = new EntityShip(); - EntityShip.Init(speed, weight, bodyColor, additionalColor, - crane, container); - - return true; - }*/ + public DrawingShip(int speed, double weight, Color bodyColor, int width, int height) { if(width < _shipWidth || height < _shipHeight) @@ -110,18 +93,7 @@ additionalColor, bool crane, bool container, int width, int height) _shipWidth = shipWidth; EntityShip = new EntityShip(speed, weight, bodyColor); } - /*public bool Init(EntityContainerShip entcon, int wid, int hei) - { - _pictureWidth = wid; - _pictureHeight = hei; - if (_pictureWidth < _shipWidth || _pictureHeight < _shipHeight) - { - return false; - } - EntityContainerShip = entcon; - return true; - - }*/ + public void SetPosition(int x, int y) @@ -202,32 +174,7 @@ additionalColor, bool crane, bool container, int width, int height) g.DrawLine(pen, _startPosX + 20, _startPosY + 55, _startPosX + 30, _startPosY + 55); //контейнеры - /*if (EntityShip.Conteiners) - { - g.FillRectangle(adbrush, _startPosX + 30, _startPosY + 35, 35, 10); - g.FillRectangle(adbrush, _startPosX + 65, _startPosY + 35, 20, 10); - g.FillRectangle(adbrush, _startPosX + 85, _startPosY + 30, 15, 15); - g.FillRectangle(adbrush, _startPosX + 30, _startPosY + 25, 15, 10); - g.FillRectangle(adbrush, _startPosX + 45, _startPosY + 25, 55, 5); - g.FillRectangle(adbrush, _startPosX + 45, _startPosY + 30, 40, 5); - - g.DrawRectangle(pen, _startPosX + 30, _startPosY + 35, 35, 10); - g.DrawRectangle(pen, _startPosX + 65, _startPosY + 35, 20, 10); - g.DrawRectangle(pen, _startPosX + 85, _startPosY + 30, 15, 15); - g.DrawRectangle(pen, _startPosX + 30, _startPosY + 25, 15, 10); - g.DrawRectangle(pen, _startPosX + 45, _startPosY + 25, 55, 5); - g.DrawRectangle(pen, _startPosX + 45, _startPosY + 30, 40, 5); - } - //кран - if (EntityShip.Crane) - { - g.FillRectangle(adbrush, _startPosX + 23, _startPosY, 5, 45); - g.FillRectangle(adbrush, _startPosX + 27, _startPosY + 10, 20, 3); - g.DrawRectangle(pen, _startPosX + 23, _startPosY, 5, 45); - g.DrawRectangle(pen, _startPosX + 27, _startPosY + 10, 20, 3); - g.DrawLine(pen, _startPosX + 27, _startPosY, _startPosX + 47, _startPosY + 10); - g.DrawLine(pen, _startPosX + 47, _startPosY + 13, _startPosX + 47, _startPosY + 25); - }*/ + } } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs b/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs index cd16399..c3cc52e 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs @@ -41,9 +41,7 @@ namespace Lab1ContainersShip.Entities Speed = speed; Weight = weight; BodyColor = bodyColor; - //AdditionalColor = additionalColor; - //Crane = crane; - //Conteiners = containers; + } } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/Form1.cs b/Lab1ContainersShip/Lab1ContainersShip/Form1.cs index 787fb19..184991b 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/Form1.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/Form1.cs @@ -16,9 +16,7 @@ namespace Lab1ContainersShip { private DrawingShip _drawingShip; - /// - /// Стратегия перемещения - /// + private AbstractStrategy _abstractStrategy; @@ -26,17 +24,7 @@ namespace Lab1ContainersShip { InitializeComponent(); } - /// - /// Поле-объект для прорисовки объекта - /// - /// - /// Инициализация формы - /// - - /// - /// Метод прорисовки машины - /// private void Draw() { @@ -59,33 +47,7 @@ namespace Lab1ContainersShip } - /*private void buttonCreate_Click(object sender, EventArgs e) - { - Random random = new Random(); - _drawningShip = new DrawingShip(); - EntityShip _entitycont = new EntityShip();*/ - /*_entitycont.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)));*/ - /*_drawningShip.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)), - pictureBox1.Width, pictureBox1.Height); - //_drawningShip.Init(_entitycont, pictureBox1.Width, pictureBox1.Height); - _drawningShip.SetPosition(random.Next(10, 100), - random.Next(10, 100)); - Draw(); - }*/ + private void buttonMove_Click(object sender, EventArgs e) { if (_drawingShip == null) @@ -119,13 +81,7 @@ namespace Lab1ContainersShip } if (comboBoxStrategy.Enabled) { - /*_abstractStrategy = comboBoxStrategy.SelectedIndex - switch - { - 0 => new MoveToCenter(), - 1 => new MoveToBorder(), - _ => null, - };*/ + switch (comboBoxStrategy.SelectedIndex) { case 0: -- 2.25.1 From 2b2a373f1aa8310b90f25f70c8cfb285d56d7bbd Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Fri, 6 Oct 2023 20:40:01 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=B8=D1=82=D0=BE=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...Form1.Designer.cs => FormContainerShip.Designer.cs} | 0 .../{Form1.cs => FormContainerShip.cs} | 0 .../{Form1.resx => FormContainerShip.resx} | 0 .../Lab1ContainersShip/Lab1ContainersShip.csproj | 10 +++++----- Lab1ContainersShip/Lab1ContainersShip/Program.cs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename Lab1ContainersShip/Lab1ContainersShip/{Form1.Designer.cs => FormContainerShip.Designer.cs} (100%) rename Lab1ContainersShip/Lab1ContainersShip/{Form1.cs => FormContainerShip.cs} (100%) rename Lab1ContainersShip/Lab1ContainersShip/{Form1.resx => FormContainerShip.resx} (100%) diff --git a/Lab1ContainersShip/Lab1ContainersShip/Form1.Designer.cs b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs similarity index 100% rename from Lab1ContainersShip/Lab1ContainersShip/Form1.Designer.cs rename to Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs diff --git a/Lab1ContainersShip/Lab1ContainersShip/Form1.cs b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs similarity index 100% rename from Lab1ContainersShip/Lab1ContainersShip/Form1.cs rename to Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs diff --git a/Lab1ContainersShip/Lab1ContainersShip/Form1.resx b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.resx similarity index 100% rename from Lab1ContainersShip/Lab1ContainersShip/Form1.resx rename to Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.resx diff --git a/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj index 9456ae0..1a1e0d6 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj +++ b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj @@ -53,11 +53,11 @@ - + Form - - Form1.cs + + FormContainerShip.cs @@ -66,8 +66,8 @@ - - Form1.cs + + FormContainerShip.cs ResXFileCodeGenerator diff --git a/Lab1ContainersShip/Lab1ContainersShip/Program.cs b/Lab1ContainersShip/Lab1ContainersShip/Program.cs index c4c1a15..e6271c4 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/Program.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/Program.cs @@ -16,7 +16,7 @@ namespace Lab1ContainersShip { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + Application.Run(new FormContainerShip()); } } } -- 2.25.1 From ec4543b521162795022e51e4e452d333a407f9d9 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Fri, 6 Oct 2023 20:40:43 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=B8=D1=82=D0=BE=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lab1ContainersShip/FormContainerShip.Designer.cs | 2 +- Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs index 9b828dc..767edb8 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs @@ -1,6 +1,6 @@ namespace Lab1ContainersShip { - partial class Form1 + partial class FormContainerShip { /// /// Обязательная переменная конструктора. diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs index 184991b..1c4c918 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs @@ -12,7 +12,7 @@ using Lab1ContainersShip.MovementStrategy; namespace Lab1ContainersShip { - public partial class Form1 : Form + public partial class FormContainerShip : Form { private DrawingShip _drawingShip; @@ -20,7 +20,7 @@ namespace Lab1ContainersShip private AbstractStrategy _abstractStrategy; - public Form1() + public FormContainerShip() { InitializeComponent(); } -- 2.25.1 From 92cdbb3813c79100007f08c7fcb502d831b96bef Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Tue, 10 Oct 2023 12:10:05 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D1=81=D0=B4=D0=B0=D1=87=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs | 3 ++- Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs | 4 ++++ Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs index a080e88..3eec57f 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs @@ -151,8 +151,9 @@ namespace Lab1ContainersShip.DrawingObjects Pen pen = new Pen(Color.Black); //Brush adbrush = new SolidBrush(EntityShip.AdditionalColor); Brush brBlue = new SolidBrush(Color.Blue); + Brush brBody = new SolidBrush(EntityShip.BodyColor); // заполнение борта - g.FillPolygon(brBlue, new PointF[] + g.FillPolygon(brBody, new PointF[] { new PointF(_startPosX, _startPosY+45), new PointF(_startPosX+20, _startPosY+65), diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs index 6cd7276..a936e3a 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs @@ -32,5 +32,9 @@ namespace Lab1ContainersShip.MovementStrategy _drawingShip?.CanMove(direction) ?? false; public void MoveObject(Direction direction) => _drawingShip?.MoveTransport(direction); + public void DopMeth(Direction direction) + { + Console.WriteLine("метод работает" + direction); + } } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs b/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs index 80123fa..13e9fda 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs @@ -31,6 +31,7 @@ namespace Lab1ContainersShip.MovementStrategy /// /// Направление void MoveObject(Direction direction); + void DopMeth(Direction direction); } } -- 2.25.1 From 72b2d823c71d7d938b36262aeef910434fdcd81f Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Tue, 10 Oct 2023 12:10:43 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D1=81=D0=B4=D0=B0=D1=87=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs | 5 +---- Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs index a936e3a..ab6de85 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawningObjectShip.cs @@ -32,9 +32,6 @@ namespace Lab1ContainersShip.MovementStrategy _drawingShip?.CanMove(direction) ?? false; public void MoveObject(Direction direction) => _drawingShip?.MoveTransport(direction); - public void DopMeth(Direction direction) - { - Console.WriteLine("метод работает" + direction); - } + } } diff --git a/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs b/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs index 13e9fda..3522b86 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/IMoveableObject.cs @@ -31,7 +31,7 @@ namespace Lab1ContainersShip.MovementStrategy /// /// Направление void MoveObject(Direction direction); - void DopMeth(Direction direction); + } } -- 2.25.1 From 811e02b7bd2a5f18c0c38dff55ff400cda48cc9a Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Fri, 20 Oct 2023 17:22:41 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs | 3 +-- Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs index 3eec57f..aa1e6b8 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs @@ -149,8 +149,7 @@ namespace Lab1ContainersShip.DrawingObjects return; } Pen pen = new Pen(Color.Black); - //Brush adbrush = new SolidBrush(EntityShip.AdditionalColor); - Brush brBlue = new SolidBrush(Color.Blue); + Brush brBody = new SolidBrush(EntityShip.BodyColor); // заполнение борта g.FillPolygon(brBody, new PointF[] diff --git a/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs b/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs index c3cc52e..1410765 100644 --- a/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs +++ b/Lab1ContainersShip/Lab1ContainersShip/EntityShip.cs @@ -24,17 +24,16 @@ namespace Lab1ContainersShip.Entities /// /// Дополнительный цвет (для опциональных элементов) /// - //public Color AdditionalColor { get; private set; } - + /// /// Признак (опция) наличия крана /// - //public bool Crane { get; private set; } + /// /// Признак (опция) наличия контейнеров /// - //public bool Conteiners { get; private set; } + public double Step => (double)Speed * 100 / Weight; public EntityShip(int speed, double weight, Color bodyColor) { -- 2.25.1