From 36e2fba2359d1dc29eb09313fcc975b1fe1e920a Mon Sep 17 00:00:00 2001 From: spacyboy Date: Wed, 22 Nov 2023 03:19:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D1=84=D0=BE=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RoadTrain/RoadTrain/AbstractStrategy.cs | 71 +++++++++ RoadTrain/RoadTrain/DrawingObjectTrain.cs | 33 ++++ RoadTrain/RoadTrain/DrawingRoadTrain.cs | 142 ++++++++++-------- .../RoadTrain/DrawingRoadTrainWithTank.cs | 49 ++++++ RoadTrain/RoadTrain/EntityRoadTrain.cs | 21 ++- .../RoadTrain/EntityRoadTrainWithTank.cs | 23 +++ RoadTrain/RoadTrain/IMoveableObject.cs | 18 +++ RoadTrain/RoadTrain/MoveToBorder.cs | 57 +++++++ RoadTrain/RoadTrain/MoveToCenter.cs | 56 +++++++ RoadTrain/RoadTrain/ObjectParameters.cs | 29 ++++ RoadTrain/RoadTrain/Program.cs | 2 +- RoadTrain/RoadTrain/Properties/Resources.resx | 11 +- RoadTrain/RoadTrain/RoadTrain.Designer.cs | 130 +++------------- RoadTrain/RoadTrain/RoadTrain.cs | 64 ++------ RoadTrain/RoadTrain/RoadTrain.resx | 50 +++--- RoadTrain/RoadTrain/Status.cs | 15 ++ 16 files changed, 501 insertions(+), 270 deletions(-) create mode 100644 RoadTrain/RoadTrain/AbstractStrategy.cs create mode 100644 RoadTrain/RoadTrain/DrawingObjectTrain.cs create mode 100644 RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs create mode 100644 RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs create mode 100644 RoadTrain/RoadTrain/IMoveableObject.cs create mode 100644 RoadTrain/RoadTrain/MoveToBorder.cs create mode 100644 RoadTrain/RoadTrain/MoveToCenter.cs create mode 100644 RoadTrain/RoadTrain/ObjectParameters.cs create mode 100644 RoadTrain/RoadTrain/Status.cs diff --git a/RoadTrain/RoadTrain/AbstractStrategy.cs b/RoadTrain/RoadTrain/AbstractStrategy.cs new file mode 100644 index 0000000..abeb132 --- /dev/null +++ b/RoadTrain/RoadTrain/AbstractStrategy.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RoadTrain.DrawingObjects; + +namespace RoadTrain.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(); + } + protected bool MoveLeft() => MoveTo(DirectionType.Left); + protected bool MoveRight() => MoveTo(DirectionType.Right); + protected bool MoveUp() => MoveTo(DirectionType.Up); + protected bool MoveDown() => MoveTo(DirectionType.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(); + private bool MoveTo(DirectionType directionType) + { + if (_state != Status.InProgress) + { + return false; + } + if (_moveableObject?.CheckCanMove(directionType) ?? false) + { + _moveableObject.MoveObject(directionType); + return true; + } + return false; + } + } +} diff --git a/RoadTrain/RoadTrain/DrawingObjectTrain.cs b/RoadTrain/RoadTrain/DrawingObjectTrain.cs new file mode 100644 index 0000000..2b1eb18 --- /dev/null +++ b/RoadTrain/RoadTrain/DrawingObjectTrain.cs @@ -0,0 +1,33 @@ +using RoadTrain.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RoadTrain.DrawingObjects; + +namespace RoadTrain.MovementStrategy +{ + public class DrawingObjectTrain : IMoveableObject + { + private readonly DrawingRoadTrain? _drawingRoadTrain = null; + public DrawingObjectTrain(DrawingRoadTrain drawingRoadTrain) + { + _drawingRoadTrain = drawingRoadTrain; + } + public ObjectParameters? GetObjectPosition + { + get + { + if (_drawingRoadTrain == null || _drawingRoadTrain.EntityRoadTrain == null) + { + return null; + } + return new ObjectParameters(_drawingRoadTrain.GetPosX, _drawingRoadTrain.GetPosY, _drawingRoadTrain.GetWidth, _drawingRoadTrain.GetHeight); + } + } + public int GetStep => (int)(_drawingRoadTrain?.EntityRoadTrain?.Step ?? 0); + public bool CheckCanMove(DirectionType direction) => _drawingRoadTrain?.CanMove(direction) ?? false; + public void MoveObject(DirectionType direction) => _drawingRoadTrain?.MoveTransport(direction); + } +} diff --git a/RoadTrain/RoadTrain/DrawingRoadTrain.cs b/RoadTrain/RoadTrain/DrawingRoadTrain.cs index 5c03287..8fa1443 100644 --- a/RoadTrain/RoadTrain/DrawingRoadTrain.cs +++ b/RoadTrain/RoadTrain/DrawingRoadTrain.cs @@ -1,28 +1,48 @@ -using System.Net.NetworkInformation; -using System.Net.Sockets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RoadTrain.Entities; -namespace RoadTrain + +namespace RoadTrain.DrawingObjects { - internal class DrawingRoadTrain + public class DrawingRoadTrain { - public EntityRoadTrain? EntityRoadTrain { get; private set; } + public EntityRoadTrain? EntityRoadTrain { get; protected set; } private int _pictureWidth; private int _pictureHeight; - private int _startPosX; - private int _startPosY; - private readonly int _roadTrainWidth = 200; - private readonly int _roadTrainHeight = 100; - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheel, bool door, bool light, int width, int height) + protected int _startPosX; + protected int _startPosY; + protected readonly int _roadTrainWidth = 200; + protected readonly int _roadTrainHeight = 100; + public int GetPosX => _startPosX; + public int GetPosY => _startPosY; + public int GetWidth => _roadTrainWidth; + public int GetHeight => _roadTrainHeight; + public DrawingRoadTrain(int speed, double weight, Color bodyColor, int width, int height) { - if (_roadTrainWidth < width || _roadTrainHeight < height) + if (width < _roadTrainWidth || height < _roadTrainHeight) { - EntityRoadTrain = new EntityRoadTrain(); - EntityRoadTrain.Init(speed, weight, bodyColor, additionalColor, wheel, door, light); - _pictureWidth = width; - _pictureHeight = height; - return true; + return; } - return false; + _pictureWidth = width; + _pictureHeight = height; + EntityRoadTrain = new EntityRoadTrain(speed, weight, bodyColor); + + } + protected DrawingRoadTrain(int speed, double weight, Color bodyColor, int width, int height, int roadTrainWidth, int roadTrainHeight) + { + if (width < _roadTrainWidth || height < _roadTrainHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + _roadTrainWidth = roadTrainWidth; + _roadTrainHeight = roadTrainHeight; + EntityRoadTrain = new EntityRoadTrain(speed, weight, bodyColor); } public void SetPosition(int x, int y) { @@ -37,74 +57,68 @@ namespace RoadTrain } public void MoveTransport(DirectionType direction) { - if (EntityRoadTrain == null) + if (!CanMove(direction) || EntityRoadTrain == null) { return; } switch (direction) { - //влево case DirectionType.Left: - if (_startPosX - EntityRoadTrain.Step > 0) - { - _startPosX -= (int)EntityRoadTrain.Step; - } + _startPosX -= (int)EntityRoadTrain.Step; break; - //вверх case DirectionType.Up: - if (_startPosY - EntityRoadTrain.Step > 0) - { - _startPosY -= (int)EntityRoadTrain.Step; - } + _startPosY -= (int)EntityRoadTrain.Step; break; - // вправо case DirectionType.Right: - if (_startPosX + EntityRoadTrain.Step < _pictureWidth - _roadTrainWidth) - { - _startPosX += (int)EntityRoadTrain.Step; - } + _startPosX += (int)EntityRoadTrain.Step; break; - //вниз case DirectionType.Down: - if (_startPosY + EntityRoadTrain.Step < _pictureHeight - _roadTrainHeight) - { - _startPosY += (int)EntityRoadTrain.Step; - } + _startPosY += (int)EntityRoadTrain.Step; break; } } - public void DrawTransport(Graphics g) + public bool CanMove(DirectionType direction) + { + if (EntityRoadTrain == null) + { + return false; + } + return direction switch + { + DirectionType.Left => _startPosX - EntityRoadTrain.Step > 0, + DirectionType.Up => _startPosY - EntityRoadTrain.Step > 0, + DirectionType.Right => _startPosX + _roadTrainWidth + EntityRoadTrain.Step < _pictureWidth, + DirectionType.Down => _startPosY + _roadTrainHeight + EntityRoadTrain.Step < _pictureHeight, + _ => false, + }; + } + public virtual void DrawTransport(Graphics g) { if (EntityRoadTrain == null) { return; } - Pen pen = new(Color.Black); - Brush additionalBrush = new - SolidBrush(EntityRoadTrain.AdditionalColor); + Pen pen = new(Color.Black, 2); + Pen anchor = new(Color.Black, 4); + Brush bodyBrush = new SolidBrush(EntityRoadTrain.BodyColor); + Brush whiteBrush = new SolidBrush(Color.White); + + + //машина - g.DrawRectangle(pen, _startPosX, _startPosY + 50, 160, 20); //кузов - g.DrawEllipse(pen, _startPosX + 5, _startPosY + 70, 30, 30); //колесо - g.DrawEllipse(pen, _startPosX + 40, _startPosY + 70, 30, 30); //колесо - g.DrawEllipse(pen, _startPosX + 120, _startPosY + 70, 30, 30); //колесо - g.DrawRectangle(pen, _startPosX + 120, _startPosY + 10, 40, 40); //кабина - g.DrawRectangle(pen, _startPosX + 10, _startPosY, 90, 50); //бак с водой - g.DrawRectangle(pen, _startPosX + 130, _startPosY + 20, 30, 20); //окно - g.DrawLine(pen, _startPosX + 160, _startPosY + 70, _startPosX + 180, _startPosY + 80); //держатель для щетки - g.DrawRectangle(pen, _startPosX + 170, _startPosY + 80, 40, 10); //щетка - //обвесы - if (EntityRoadTrain.Wheel) - { - g.FillEllipse(additionalBrush, _startPosX + 75, _startPosY + 70, 30, 30); //колесо - } - if (EntityRoadTrain.Door) - { - g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 20, 20, 30); //дверь - } - if (EntityRoadTrain.Light) - { - g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY, 10, 10); //мигалка - } + g.DrawRectangle(pen, _startPosX - 20, _startPosY + 50 + 80, 160, 20); + g.FillRectangle(bodyBrush, _startPosX - 20, _startPosY + 50 + 80, 160, 20); + g.DrawEllipse(pen, _startPosX + 5 - 20, _startPosY + 70 + 80, 30, 30); //колесо + g.FillEllipse(bodyBrush, _startPosX + 5 - 20, _startPosY + 70 + 80, 30, 30); + g.DrawEllipse(pen, _startPosX + 40 - 20, _startPosY + 70 + 80, 30, 30); //колесо + g.FillEllipse(bodyBrush, _startPosX + 40 - 20, _startPosY + 70 + 80, 30, 30); + g.DrawEllipse(pen, _startPosX + 120 - 20, _startPosY + 70 + 80, 30, 30); //колесо + g.FillEllipse(bodyBrush, _startPosX + 120 - 20, _startPosY + 70 + 80, 30, 30); + g.DrawRectangle(pen, _startPosX + 120 - 20, _startPosY + 10 + 80, 40, 40); //кабина + g.FillRectangle(bodyBrush, _startPosX + 120 - 20, _startPosY + 10 + 80, 40, 40); + g.DrawRectangle(pen, _startPosX + 130 - 20, _startPosY + 20 + 80, 30, 20); //окно + g.FillRectangle(whiteBrush, _startPosX + 130 - 20, _startPosY + 20 + 80, 30, 20); + } } } \ No newline at end of file diff --git a/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs b/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs new file mode 100644 index 0000000..4101ec0 --- /dev/null +++ b/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RoadTrain.Entities; + +namespace RoadTrain.DrawingObjects +{ + public class DrawingRoadTrainWithTank : DrawingRoadTrain + { + public DrawingRoadTrainWithTank(int speed, double weight, Color bodyColor, Color + additionalColor, bool pipes, bool section, int width, int height) + : base(speed, weight, bodyColor, width, height, 185, 180) + { + if (EntityRoadTrain != null) + { + EntityRoadTrain = new EntityRoadTrainWithTank(speed, weight, bodyColor, additionalColor, pipes, section); + } + } + public override void DrawTransport(Graphics g) + { + if (EntityRoadTrain is not EntityRoadTrainWithTank roadTrain) + { + return; + } + Pen pen = new(Color.Black, 2); + Brush additionalBrush = new SolidBrush(roadTrain.AdditionalColor); + base.DrawTransport(g); + + + //щетка + Brush brGray = new SolidBrush(Color.Gray); + if (roadTrain.Brush) + { + g.DrawLine(pen, _startPosX + 160-20, _startPosY + 70 + 80, _startPosX + 180, _startPosY + 80 + 80); + g.DrawRectangle(pen, _startPosX + 170-20, _startPosY + 80 + 80, 40, 10); //щетка + g.FillRectangle(additionalBrush, _startPosX + 170-20, _startPosY + 80 + 80, 40, 10); + } + //бак + if (roadTrain.Tank) + { + g.DrawRectangle(pen, _startPosX + 10 - 20, _startPosY + 80, 90, 50); //бак с водой + g.FillRectangle(additionalBrush, _startPosX + 10-20, _startPosY + 80, 90, 50); + } + } + } +} diff --git a/RoadTrain/RoadTrain/EntityRoadTrain.cs b/RoadTrain/RoadTrain/EntityRoadTrain.cs index 196715a..e73b415 100644 --- a/RoadTrain/RoadTrain/EntityRoadTrain.cs +++ b/RoadTrain/RoadTrain/EntityRoadTrain.cs @@ -1,25 +1,22 @@ -namespace RoadTrain +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoadTrain.Entities { public class EntityRoadTrain { 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 Wheel { get; private set; } - public bool Door { get; private set; } - public bool Light { get; private set; } public double Step => (double)Speed * 100 / Weight; - public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, bool wheel, bool door, bool light) + public EntityRoadTrain(int speed, double weight, Color bodyColor) { Speed = speed; Weight = weight; BodyColor = bodyColor; - AdditionalColor = additionalColor; - Wheel = wheel; - Door = door; - Light = light; } } -} \ No newline at end of file +} diff --git a/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs b/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs new file mode 100644 index 0000000..0a4f943 --- /dev/null +++ b/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoadTrain.Entities +{ + public class EntityRoadTrainWithTank : EntityRoadTrain + { + public Color AdditionalColor { get; private set; } + public bool Tank { get; private set; } + public bool Brush { get; private set; } + public EntityRoadTrainWithTank(int speed, double weight, Color bodyColor, Color + additionalColor, bool tank, bool brush) + : base (speed, weight, bodyColor) + { + AdditionalColor = additionalColor; + Tank = tank; + Brush = brush; + } + } +} diff --git a/RoadTrain/RoadTrain/IMoveableObject.cs b/RoadTrain/RoadTrain/IMoveableObject.cs new file mode 100644 index 0000000..4cc5d30 --- /dev/null +++ b/RoadTrain/RoadTrain/IMoveableObject.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RoadTrain.DrawingObjects; + + +namespace RoadTrain.MovementStrategy +{ + public interface IMoveableObject + { + ObjectParameters? GetObjectPosition { get; } + int GetStep { get; } + bool CheckCanMove(DirectionType direction); + void MoveObject(DirectionType direction); + } +} diff --git a/RoadTrain/RoadTrain/MoveToBorder.cs b/RoadTrain/RoadTrain/MoveToBorder.cs new file mode 100644 index 0000000..22621b2 --- /dev/null +++ b/RoadTrain/RoadTrain/MoveToBorder.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoadTrain.MovementStrategy +{ + public 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/RoadTrain/RoadTrain/MoveToCenter.cs b/RoadTrain/RoadTrain/MoveToCenter.cs new file mode 100644 index 0000000..1e7be9a --- /dev/null +++ b/RoadTrain/RoadTrain/MoveToCenter.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoadTrain.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/RoadTrain/RoadTrain/ObjectParameters.cs b/RoadTrain/RoadTrain/ObjectParameters.cs new file mode 100644 index 0000000..5691830 --- /dev/null +++ b/RoadTrain/RoadTrain/ObjectParameters.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoadTrain.MovementStrategy +{ + public class ObjectParameters + { + private readonly int _x; + private readonly int _y; + private readonly int _width; + private readonly int _height; + public int LeftBorder => _x; + public int TopBorder => _y; + public int RightBorder => _x + _width; + public int DownBorder => _y + _height; + public int ObjectMiddleHorizontal => _x + _width / 2; + public int ObjectMiddleVertical => _y + _height / 2; + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } + } +} diff --git a/RoadTrain/RoadTrain/Program.cs b/RoadTrain/RoadTrain/Program.cs index b765653..c6803b9 100644 --- a/RoadTrain/RoadTrain/Program.cs +++ b/RoadTrain/RoadTrain/Program.cs @@ -1,4 +1,4 @@ -namespace RoadTrain.A_RoadTrain_Basic +namespace RoadTrain { internal static class Program { diff --git a/RoadTrain/RoadTrain/Properties/Resources.resx b/RoadTrain/RoadTrain/Properties/Resources.resx index 53ec0b4..49b2f0d 100644 --- a/RoadTrain/RoadTrain/Properties/Resources.resx +++ b/RoadTrain/RoadTrain/Properties/Resources.resx @@ -59,8 +59,15 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - + + diff --git a/RoadTrain/RoadTrain/RoadTrain.Designer.cs b/RoadTrain/RoadTrain/RoadTrain.Designer.cs index 96faace..30d106e 100644 --- a/RoadTrain/RoadTrain/RoadTrain.Designer.cs +++ b/RoadTrain/RoadTrain/RoadTrain.Designer.cs @@ -1,8 +1,16 @@ -namespace RoadTrain.A_RoadTrain_Basic +namespace RoadTrain { partial class RoadTrain { + /// + /// Required designer variable. + /// private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) @@ -14,122 +22,18 @@ #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// private void InitializeComponent() { - pictureBoxRoadTrain = new PictureBox(); - buttonCreate = new Button(); - buttonRight = new Button(); - buttonUp = new Button(); - buttonLeft = new Button(); - buttonDown = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).BeginInit(); - SuspendLayout(); - // - // pictureBoxRoadTrain - // - pictureBoxRoadTrain.Dock = DockStyle.Fill; - pictureBoxRoadTrain.Location = new Point(0, 0); - pictureBoxRoadTrain.Margin = new Padding(3, 2, 3, 2); - pictureBoxRoadTrain.Name = "pictureBoxRoadTrain"; - pictureBoxRoadTrain.Size = new Size(700, 338); - pictureBoxRoadTrain.SizeMode = PictureBoxSizeMode.AutoSize; - pictureBoxRoadTrain.TabIndex = 0; - pictureBoxRoadTrain.TabStop = false; - // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(10, 307); - buttonCreate.Margin = new Padding(3, 2, 3, 2); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(82, 22); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; - // - // buttonRight - // - buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonRight.BackgroundImage = Properties.Resources.right; - buttonRight.BackgroundImageLayout = ImageLayout.Zoom; - buttonRight.ForeColor = SystemColors.ControlText; - buttonRight.Location = new Point(663, 306); - buttonRight.Margin = new Padding(3, 2, 3, 2); - buttonRight.Name = "buttonRight"; - buttonRight.Size = new Size(26, 22); - buttonRight.TabIndex = 2; - buttonRight.UseVisualStyleBackColor = true; - buttonRight.Click += ButtonMove_Click; - // - // buttonUp - // - buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonUp.BackgroundImage = Properties.Resources.up; - buttonUp.BackgroundImageLayout = ImageLayout.Zoom; - buttonUp.ForeColor = SystemColors.ControlText; - buttonUp.Location = new Point(632, 280); - buttonUp.Margin = new Padding(3, 2, 3, 2); - buttonUp.Name = "buttonUp"; - buttonUp.Size = new Size(26, 22); - buttonUp.TabIndex = 4; - buttonUp.UseVisualStyleBackColor = true; - buttonUp.Click += ButtonMove_Click; - // - // buttonLeft - // - buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonLeft.BackgroundImage = Properties.Resources.left; - buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; - buttonLeft.ForeColor = SystemColors.ControlText; - buttonLeft.Location = new Point(600, 307); - buttonLeft.Margin = new Padding(3, 2, 3, 2); - buttonLeft.Name = "buttonLeft"; - buttonLeft.Size = new Size(26, 22); - buttonLeft.TabIndex = 5; - buttonLeft.UseVisualStyleBackColor = true; - buttonLeft.Click += ButtonMove_Click; - // - // buttonDown - // - buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonDown.BackgroundImage = Properties.Resources.down; - buttonDown.BackgroundImageLayout = ImageLayout.Zoom; - buttonDown.ForeColor = SystemColors.ControlText; - buttonDown.Location = new Point(632, 307); - buttonDown.Margin = new Padding(3, 2, 3, 2); - buttonDown.Name = "buttonDown"; - buttonDown.Size = new Size(26, 22); - buttonDown.TabIndex = 6; - buttonDown.UseVisualStyleBackColor = true; - buttonDown.Click += ButtonMove_Click; - // - // RoadTrain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(700, 338); - Controls.Add(buttonDown); - Controls.Add(buttonLeft); - Controls.Add(buttonUp); - Controls.Add(buttonRight); - Controls.Add(buttonCreate); - Controls.Add(pictureBoxRoadTrain); - Margin = new Padding(3, 2, 3, 2); - Name = "RoadTrain"; - Text = "RoadTrainForm"; - ((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).EndInit(); - ResumeLayout(false); - PerformLayout(); + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "RoadTrain"; } #endregion - - public PictureBox pictureBoxRoadTrain; - private Button buttonCreate; - private Button buttonRight; - private Button buttonUp; - private Button buttonLeft; - private Button buttonDown; } } \ No newline at end of file diff --git a/RoadTrain/RoadTrain/RoadTrain.cs b/RoadTrain/RoadTrain/RoadTrain.cs index 616da9a..a565c95 100644 --- a/RoadTrain/RoadTrain/RoadTrain.cs +++ b/RoadTrain/RoadTrain/RoadTrain.cs @@ -1,62 +1,20 @@ -namespace RoadTrain.A_RoadTrain_Basic +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RoadTrain { public partial class RoadTrain : Form { - private DrawingRoadTrain? _drawingRoadTrain; public RoadTrain() { InitializeComponent(); } - private void Draw() - { - if (_drawingRoadTrain == null) - { - return; - } - Bitmap bmp = new(pictureBoxRoadTrain.Width, - pictureBoxRoadTrain.Height); - Graphics gr = Graphics.FromImage(bmp); - _drawingRoadTrain.DrawTransport(gr); - pictureBoxRoadTrain.Image = bmp; - } - private void buttonCreate_Click(object sender, EventArgs e) - { - Random random = new(); - _drawingRoadTrain = new DrawingRoadTrain(); - _drawingRoadTrain.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)), - Convert.ToBoolean(random.Next(0, 2)), - pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height); - _drawingRoadTrain.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); - } - private void ButtonMove_Click(object sender, EventArgs e) - { - if (_drawingRoadTrain == null) - { - return; - } - string name = ((Button)sender)?.Name ?? string.Empty; - switch (name) - { - case "buttonUp": - _drawingRoadTrain.MoveTransport(DirectionType.Up); - break; - case "buttonDown": - _drawingRoadTrain.MoveTransport(DirectionType.Down); - break; - case "buttonLeft": - _drawingRoadTrain.MoveTransport(DirectionType.Left); - break; - case "buttonRight": - _drawingRoadTrain.MoveTransport(DirectionType.Right); - break; - } - Draw(); - } } } diff --git a/RoadTrain/RoadTrain/RoadTrain.resx b/RoadTrain/RoadTrain/RoadTrain.resx index af32865..1af7de1 100644 --- a/RoadTrain/RoadTrain/RoadTrain.resx +++ b/RoadTrain/RoadTrain/RoadTrain.resx @@ -1,17 +1,17 @@  - diff --git a/RoadTrain/RoadTrain/Status.cs b/RoadTrain/RoadTrain/Status.cs new file mode 100644 index 0000000..702be08 --- /dev/null +++ b/RoadTrain/RoadTrain/Status.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoadTrain.MovementStrategy +{ + public enum Status + { + NotInit, + InProgress, + Finish + } +}