From c3152e4c34455ad9b550bb96998f4eb2591acd65 Mon Sep 17 00:00:00 2001 From: Itos Date: Thu, 3 Oct 2024 00:40:53 +0300 Subject: [PATCH] Lab3_DONE --- .../ProjectGasolineTanker/DirectionType.cs | 16 --- .../{ => Drawings}/DrawingGasolineTanker.cs | 23 ++-- .../{ => Drawings}/DrawingTruck.cs | 66 +++++++-- .../Entities/DirectionType.cs | 33 +++++ .../{ => Entities}/EntityGasolineTanker.cs | 12 +- .../{ => Entities}/EntityTruck.cs | 9 +- .../FormGasolineTanker.Designer.cs | 64 +++++---- .../FormGasolineTanker.cs | 57 ++++++-- .../FormTruckCollection.Designer.cs | 128 ++++++++++++++++++ .../FormTruckCollection.cs | 85 ++++++++++++ .../FormTruckCollection.resx | 60 ++++++++ .../Generic/SetGeneric.cs | 106 +++++++++++++++ .../Generic/TruckGenericCollection.cs | 120 ++++++++++++++++ .../{ => MovementStratg}/AbstractStrategy.cs | 31 ++++- .../DrawingObjectTruck.cs | 15 +- .../{ => MovementStratg}/IMoveableObject.cs | 14 +- .../{ => MovementStratg}/MoveToBorder.cs | 6 +- .../{ => MovementStratg}/MoveToCenter.cs | 5 +- .../{ => MovementStratg}/ObjectParameters.cs | 11 +- .../{ => MovementStratg}/Status.cs | 4 +- .../ProjectGasolineTanker/Program.cs | 2 +- 21 files changed, 760 insertions(+), 107 deletions(-) delete mode 100644 GasolineTanker/ProjectGasolineTanker/DirectionType.cs rename GasolineTanker/ProjectGasolineTanker/{ => Drawings}/DrawingGasolineTanker.cs (87%) rename GasolineTanker/ProjectGasolineTanker/{ => Drawings}/DrawingTruck.cs (85%) create mode 100644 GasolineTanker/ProjectGasolineTanker/Entities/DirectionType.cs rename GasolineTanker/ProjectGasolineTanker/{ => Entities}/EntityGasolineTanker.cs (85%) rename GasolineTanker/ProjectGasolineTanker/{ => Entities}/EntityTruck.cs (98%) create mode 100644 GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs create mode 100644 GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs create mode 100644 GasolineTanker/ProjectGasolineTanker/FormTruckCollection.resx create mode 100644 GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs create mode 100644 GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs rename GasolineTanker/ProjectGasolineTanker/{ => MovementStratg}/AbstractStrategy.cs (92%) rename GasolineTanker/ProjectGasolineTanker/{ => MovementStratg}/DrawingObjectTruck.cs (79%) rename GasolineTanker/ProjectGasolineTanker/{ => MovementStratg}/IMoveableObject.cs (72%) rename GasolineTanker/ProjectGasolineTanker/{ => MovementStratg}/MoveToBorder.cs (92%) rename GasolineTanker/ProjectGasolineTanker/{ => MovementStratg}/MoveToCenter.cs (96%) rename GasolineTanker/ProjectGasolineTanker/{ => MovementStratg}/ObjectParameters.cs (93%) rename GasolineTanker/ProjectGasolineTanker/{ => MovementStratg}/Status.cs (80%) diff --git a/GasolineTanker/ProjectGasolineTanker/DirectionType.cs b/GasolineTanker/ProjectGasolineTanker/DirectionType.cs deleted file mode 100644 index 3db36a4..0000000 --- a/GasolineTanker/ProjectGasolineTanker/DirectionType.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectGasolineTanker -{ - public enum DirectionType - { - Up = 1, - Down = 2, - Left = 3, - Right = 4 - } -} \ No newline at end of file diff --git a/GasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs b/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs similarity index 87% rename from GasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs rename to GasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs index 4a6834b..de8e838 100644 --- a/GasolineTanker/ProjectGasolineTanker/DrawingGasolineTanker.cs +++ b/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingGasolineTanker.cs @@ -1,5 +1,4 @@ -using ProjectGasolineTanker.DrawingObjects; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,16 +6,19 @@ using System.Threading.Tasks; using System.Windows.Forms; using ProjectGasolineTanker.Entities; -namespace ProjectGasolineTanker +namespace ProjectGasolineTanker.Drawings { public class DrawingGasolineTanker : DrawingTruck { + + public DrawingGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool wheel, int width, int height) : base(speed, weight, bodyColor, width, height, 130, 70) { if (EntityTruck != null) { EntityTruck = new EntityGasolineTanker(speed, weight, bodyColor, additionalColor, tank, wheel); } + } public override void DrawTransport(Graphics g) { @@ -24,16 +26,18 @@ namespace ProjectGasolineTanker { return; } - Pen pen = new(Color.Black); - Pen additionalPen = new(GasolineTanker.Body); - Brush additionalBrush = new SolidBrush(GasolineTanker.Body); + Pen pen = new(Color.Black); + Pen additionalPen = new(GasolineTanker.Add_Color); + Brush additionalBrush = new SolidBrush(GasolineTanker.Add_Color); base.DrawTransport(g); + if (GasolineTanker.Tank) { g.FillRectangle(additionalBrush, _startPosX + 45, _startPosY + 53, 35, 20); g.DrawLine(pen, _startPosX + 45, _startPosY + 53, _startPosX + 80, _startPosY + 73); g.DrawLine(pen, _startPosX + 80, _startPosY + 53, _startPosX + 45, _startPosY + 73); - } + } + if (GasolineTanker.Wheel) { Brush gr = new SolidBrush(Color.Gray); @@ -41,6 +45,7 @@ namespace ProjectGasolineTanker g.FillEllipse(gr, _startPosX + 87, _startPosY + 57, 18, 18); g.DrawEllipse(pen, _startPosX + 85, _startPosY + 55, 22, 22); } - } + } } -} \ No newline at end of file +} + diff --git a/GasolineTanker/ProjectGasolineTanker/DrawingTruck.cs b/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs similarity index 85% rename from GasolineTanker/ProjectGasolineTanker/DrawingTruck.cs rename to GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs index af132d7..77e16cc 100644 --- a/GasolineTanker/ProjectGasolineTanker/DrawingTruck.cs +++ b/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs @@ -5,24 +5,40 @@ using System.Text; using System.Threading.Tasks; using ProjectGasolineTanker.Entities; +using ProjectGasolineTanker.MovementStratg; -namespace ProjectGasolineTanker.DrawingObjects +namespace ProjectGasolineTanker.Drawings { + public class DrawingTruck { + public IMoveableObject GetMoveableObject => new DrawingObjectTruck(this); + public EntityTruck? EntityTruck { get; protected set; } + private int _pictureWidth; + private int _pictureHeight; + protected int _startPosX; + protected int _startPosY; - protected readonly int _tankerWidth = 130; - protected readonly int _tankerHeight = 70; + + protected readonly int _tankerWidth = 130; + + protected readonly int _tankerHeight = 70; + public int GetPosX => _startPosX; + public int GetPosY => _startPosY; + public int GetWidth => _tankerWidth; + public int GetHeight => _tankerHeight; + public DrawingTruck(int speed, double weight, Color bodyColor, int width, int height) { + if (width < _tankerWidth || height < _tankerHeight) { return; @@ -31,8 +47,10 @@ namespace ProjectGasolineTanker.DrawingObjects _pictureHeight = height; EntityTruck = new EntityTruck(speed, weight, bodyColor); } + protected DrawingTruck(int speed, double weight, Color bodyColor, int width, int height, int tankerWidth, int tankerHeight) { + // TODO: Продумать проверки if (width < _tankerWidth || height < _tankerHeight) { return; @@ -43,6 +61,7 @@ namespace ProjectGasolineTanker.DrawingObjects _tankerHeight = tankerHeight; EntityTruck = new EntityTruck(speed, weight, bodyColor); } + public void SetPosition(int x, int y) { if (x > _pictureWidth || y > _pictureHeight) @@ -52,6 +71,7 @@ namespace ProjectGasolineTanker.DrawingObjects _startPosX = x; _startPosY = y; } + public void MoveTransport(DirectionType direction) { if (!CanMove(direction) || EntityTruck == null) @@ -60,24 +80,28 @@ namespace ProjectGasolineTanker.DrawingObjects } switch (direction) { + //влево case DirectionType.Left: if (_startPosX - EntityTruck.Step > 0) { _startPosX -= (int)EntityTruck.Step; } break; + //вверх case DirectionType.Up: if (_startPosY - EntityTruck.Step > 0) { _startPosY -= (int)EntityTruck.Step; } break; + // вправо case DirectionType.Right: if (_startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth) { _startPosX += (int)EntityTruck.Step; } break; + //вниз case DirectionType.Down: if (_startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight) { @@ -86,37 +110,54 @@ namespace ProjectGasolineTanker.DrawingObjects break; } } + public virtual void DrawTransport(Graphics g) { + Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(EntityTruck.BodyColor); - g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28); - g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 20, 71, 9); - g.DrawRectangle(pen, _startPosX + 29, _startPosY + 11, 71, 28); - g.DrawRectangle(pen, _startPosX + 29, _startPosY + 20, 71, 9); + + g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28); //канистра-бак + g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 20, 71, 9); //полосы + + g.DrawRectangle(pen, _startPosX + 29, _startPosY + 11, 71, 28); //канистра-бак + g.DrawRectangle(pen, _startPosX + 29, _startPosY + 20, 71, 9); //полосы + + Brush additionalBrush1 = new SolidBrush(EntityTruck.BodyColor); + //кабина g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 24, 16); g.FillRectangle(additionalBrush1, _startPosX + 124, _startPosY + 10, 9, 16); g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 33, 16); g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 26, 33, 13); + g.DrawLine(pen, _startPosX + 100, _startPosY + 26, _startPosX + 133, _startPosY + 39); + g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 24, 16); g.DrawRectangle(pen, _startPosX + 124, _startPosY + 10, 9, 16); g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 33, 16); g.DrawRectangle(pen, _startPosX + 100, _startPosY + 26, 33, 13); + Brush additionalBrush2 = new SolidBrush(EntityTruck.BodyColor); + g.FillRectangle(additionalBrush2, _startPosX + 4, _startPosY + 40, 130, 25); g.DrawLine(pen, _startPosX + 4, _startPosY + 65, _startPosX + 25, _startPosY + 40); + + //колёса Brush gr = new SolidBrush(Color.Gray); + g.FillEllipse(additionalBrush, _startPosX + 15, _startPosY + 50, 26, 26); g.FillEllipse(additionalBrush, _startPosX + 110, _startPosY + 55, 22, 22); + g.FillEllipse(gr, _startPosX + 18, _startPosY + 53, 20, 20); g.FillEllipse(gr, _startPosX + 112, _startPosY + 57, 18, 18); + g.DrawEllipse(pen, _startPosX + 15, _startPosY + 50, 26, 26); g.DrawEllipse(pen, _startPosX + 110, _startPosY + 55, 22, 22); } + public bool CanMove(DirectionType direction) { if (EntityTruck == null) @@ -125,12 +166,17 @@ namespace ProjectGasolineTanker.DrawingObjects } return direction switch { + //влево DirectionType.Left => _startPosX - EntityTruck.Step > 0, + //вверх DirectionType.Up => _startPosY - EntityTruck.Step > 0, - DirectionType.Right => _startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth, - DirectionType.Down => _startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight, + // вправо + DirectionType.Right => _startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth,// TODO: Продумать логику + //вниз + DirectionType.Down => _startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight,// TODO: Продумать логику _ => false, }; } } -} \ No newline at end of file +} + diff --git a/GasolineTanker/ProjectGasolineTanker/Entities/DirectionType.cs b/GasolineTanker/ProjectGasolineTanker/Entities/DirectionType.cs new file mode 100644 index 0000000..2df91f0 --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/Entities/DirectionType.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.Entities +{ + /// + /// Направление перемещения + /// + public enum DirectionType + { + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 + + } +} + diff --git a/GasolineTanker/ProjectGasolineTanker/EntityGasolineTanker.cs b/GasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs similarity index 85% rename from GasolineTanker/ProjectGasolineTanker/EntityGasolineTanker.cs rename to GasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs index ee8b67b..ce11941 100644 --- a/GasolineTanker/ProjectGasolineTanker/EntityGasolineTanker.cs +++ b/GasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs @@ -7,16 +7,22 @@ using System.Threading.Tasks; namespace ProjectGasolineTanker.Entities { + public class EntityGasolineTanker : EntityTruck { - public Color Body { get; private set; } + + public Color Add_Color { get; private set; } + public bool Tank { get; private set; } + public bool Wheel { get; private set; } + public EntityGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool wheel) : base(speed, weight, bodyColor) { - Body = additionalColor; + Add_Color = additionalColor; Tank = tank; Wheel = wheel; } } -} \ No newline at end of file +} + diff --git a/GasolineTanker/ProjectGasolineTanker/EntityTruck.cs b/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs similarity index 98% rename from GasolineTanker/ProjectGasolineTanker/EntityTruck.cs rename to GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs index b3a3ec2..9466d19 100644 --- a/GasolineTanker/ProjectGasolineTanker/EntityTruck.cs +++ b/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs @@ -6,17 +6,24 @@ using System.Threading.Tasks; namespace ProjectGasolineTanker.Entities { + public class EntityTruck { + public int Speed { get; private set; } + public double Weight { get; private set; } + public Color BodyColor { get; private set; } + public double Step => (double)Speed * 100 / Weight; + public EntityTruck(int speed, double weight, Color bodyColor) { Speed = speed; Weight = weight; BodyColor = bodyColor; } + } -} \ No newline at end of file +} diff --git a/GasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs b/GasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs index f36ec80..c9d584d 100644 --- a/GasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs +++ b/GasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs @@ -37,6 +37,7 @@ this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); this.buttonStep = new System.Windows.Forms.Button(); this.buttonCreateTruck = new System.Windows.Forms.Button(); + this.buttonSelect = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit(); this.SuspendLayout(); // @@ -44,9 +45,8 @@ // this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0); - this.pictureBoxGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker"; - this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(772, 340); + this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(882, 453); this.pictureBoxGasolineTanker.TabIndex = 5; this.pictureBoxGasolineTanker.TabStop = false; // @@ -54,24 +54,22 @@ // this.buttonCreateGasolineTanker.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCreateGasolineTanker.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.buttonCreateGasolineTanker.Location = new System.Drawing.Point(10, 274); - this.buttonCreateGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateGasolineTanker.Location = new System.Drawing.Point(11, 365); this.buttonCreateGasolineTanker.Name = "buttonCreateGasolineTanker"; - this.buttonCreateGasolineTanker.Size = new System.Drawing.Size(105, 55); + this.buttonCreateGasolineTanker.Size = new System.Drawing.Size(120, 73); this.buttonCreateGasolineTanker.TabIndex = 6; this.buttonCreateGasolineTanker.Text = "Создать газовоз"; this.buttonCreateGasolineTanker.UseVisualStyleBackColor = true; - this.buttonCreateGasolineTanker.Click += new System.EventHandler(this.buttonCreateGasolineTanker_Click); + this.buttonCreateGasolineTanker.Click += new System.EventHandler(this.buttonCreateProjectGasolineTanker_Click); // // buttonUp // this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_вверх; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(710, 283); - this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUp.Location = new System.Drawing.Point(811, 377); this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(26, 22); + this.buttonUp.Size = new System.Drawing.Size(30, 29); this.buttonUp.TabIndex = 7; this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); @@ -81,10 +79,9 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_влево; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(679, 310); - this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonLeft.Location = new System.Drawing.Point(776, 413); this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(26, 22); + this.buttonLeft.Size = new System.Drawing.Size(30, 29); this.buttonLeft.TabIndex = 8; this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click); @@ -94,10 +91,9 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_вниз; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(710, 310); - this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDown.Location = new System.Drawing.Point(811, 413); this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(26, 22); + this.buttonDown.Size = new System.Drawing.Size(30, 29); this.buttonDown.TabIndex = 9; this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); @@ -107,10 +103,9 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_вправо; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(742, 310); - this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRight.Location = new System.Drawing.Point(848, 413); this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(26, 22); + this.buttonRight.Size = new System.Drawing.Size(30, 29); this.buttonRight.TabIndex = 10; this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); @@ -123,19 +118,17 @@ this.comboBoxStrategy.Items.AddRange(new object[] { "В центр", "В правый нижний угол"}); - this.comboBoxStrategy.Location = new System.Drawing.Point(629, 9); - this.comboBoxStrategy.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxStrategy.Location = new System.Drawing.Point(719, 12); this.comboBoxStrategy.Name = "comboBoxStrategy"; - this.comboBoxStrategy.Size = new System.Drawing.Size(133, 23); + this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28); this.comboBoxStrategy.TabIndex = 11; // // buttonStep // this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonStep.Location = new System.Drawing.Point(654, 34); - this.buttonStep.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonStep.Location = new System.Drawing.Point(747, 45); this.buttonStep.Name = "buttonStep"; - this.buttonStep.Size = new System.Drawing.Size(82, 22); + this.buttonStep.Size = new System.Drawing.Size(94, 29); this.buttonStep.TabIndex = 12; this.buttonStep.Text = "Шаг"; this.buttonStep.UseVisualStyleBackColor = true; @@ -144,20 +137,31 @@ // buttonCreateTruck // this.buttonCreateTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreateTruck.Location = new System.Drawing.Point(121, 291); - this.buttonCreateTruck.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateTruck.Location = new System.Drawing.Point(138, 388); this.buttonCreateTruck.Name = "buttonCreateTruck"; - this.buttonCreateTruck.Size = new System.Drawing.Size(105, 38); + this.buttonCreateTruck.Size = new System.Drawing.Size(120, 51); this.buttonCreateTruck.TabIndex = 13; this.buttonCreateTruck.Text = "Создать грузовик"; this.buttonCreateTruck.UseVisualStyleBackColor = true; this.buttonCreateTruck.Click += new System.EventHandler(this.buttonCreateTruck_Click); // + // buttonSelect + // + this.buttonSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonSelect.Location = new System.Drawing.Point(264, 365); + this.buttonSelect.Name = "buttonSelect"; + this.buttonSelect.Size = new System.Drawing.Size(120, 74); + this.buttonSelect.TabIndex = 14; + this.buttonSelect.Text = "Выбрать грузовик"; + this.buttonSelect.UseVisualStyleBackColor = true; + this.buttonSelect.Click += new System.EventHandler(this.ButtonSelectTruck_Click); + // // FormGasolineTanker // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(772, 340); + this.ClientSize = new System.Drawing.Size(882, 453); + this.Controls.Add(this.buttonSelect); this.Controls.Add(this.buttonCreateTruck); this.Controls.Add(this.buttonStep); this.Controls.Add(this.comboBoxStrategy); @@ -167,7 +171,6 @@ this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonCreateGasolineTanker); this.Controls.Add(this.pictureBoxGasolineTanker); - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "FormGasolineTanker"; this.Text = "GasolineTanker"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); @@ -186,5 +189,6 @@ private ComboBox comboBoxStrategy; private Button buttonStep; private Button buttonCreateTruck; + private Button buttonSelect; } } \ No newline at end of file diff --git a/GasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs b/GasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs index d0c7fdd..d2894da 100644 --- a/GasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs +++ b/GasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs @@ -1,16 +1,26 @@ -using ProjectGasolineTanker.DrawingObjects; -using ProjectGasolineTanker.MovementStrategy; +using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Entities; +using ProjectGasolineTanker.MovementStratg; namespace ProjectGasolineTanker { + public partial class FormGasolineTanker : Form { + private DrawingTruck? _drawingTruck; + private AbstractStrategy? _abstractStrategy; + + public DrawingTruck? SelectedTruck { get; private set; } + public FormGasolineTanker() { InitializeComponent(); + _abstractStrategy = null; + SelectedTruck = null; } + private void Draw() { if (_drawingTruck == null) @@ -20,35 +30,52 @@ namespace ProjectGasolineTanker Bitmap bmp = new(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); Graphics gr = Graphics.FromImage(bmp); _drawingTruck.DrawTransport(gr); - pictureBoxGasolineTanker.Image = bmp; + pictureBoxGasolineTanker.Image = bmp; + } - private void buttonCreateGasolineTanker_Click(object sender, EventArgs e) + + private void buttonCreateProjectGasolineTanker_Click(object sender, EventArgs e) { Random random = new(); + Color color = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + Color color1 = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + ColorDialog dialog1 = new(); + if (dialog.ShowDialog() == DialogResult.OK && dialog1.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + color1 = dialog1.Color; + } _drawingTruck = new DrawingGasolineTanker(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)), + color, color1, + true, true, pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); _drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + private void buttonCreateTruck_Click(object sender, EventArgs e) { Random random = new(); + Color color = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } _drawingTruck = new DrawingTruck(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), + color, pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); _drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + private void buttonMove_Click(object sender, EventArgs e) { if (_drawingTruck == null) @@ -73,6 +100,7 @@ namespace ProjectGasolineTanker } Draw(); } + private void buttonStep_Click(object sender, EventArgs e) { if (_drawingTruck == null) @@ -107,5 +135,10 @@ namespace ProjectGasolineTanker _abstractStrategy = null; } } + private void ButtonSelectTruck_Click(object sender, EventArgs e) + { + SelectedTruck = _drawingTruck; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs new file mode 100644 index 0000000..a3042c1 --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs @@ -0,0 +1,128 @@ +namespace ProjectGasolineTanker +{ + partial class FormTruckCollection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.labelInstruments = new System.Windows.Forms.Label(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.maskedTextBoxNumber = new System.Windows.Forms.TextBox(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.SuspendLayout(); + // + // pictureBoxCollection + // + this.pictureBoxCollection.Location = new System.Drawing.Point(2, 1); + this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBoxCollection.Name = "pictureBoxCollection"; + this.pictureBoxCollection.Size = new System.Drawing.Size(803, 376); + this.pictureBoxCollection.TabIndex = 0; + this.pictureBoxCollection.TabStop = false; + // + // labelInstruments + // + this.labelInstruments.AutoSize = true; + this.labelInstruments.Location = new System.Drawing.Point(852, 22); + this.labelInstruments.Name = "labelInstruments"; + this.labelInstruments.Size = new System.Drawing.Size(83, 15); + this.labelInstruments.TabIndex = 1; + this.labelInstruments.Text = "Инструменты"; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(840, 64); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(161, 44); + this.buttonAdd.TabIndex = 2; + this.buttonAdd.Text = "Добавить грузовик"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAddTruck_Click); + // + // maskedTextBoxNumber + // + this.maskedTextBoxNumber.Location = new System.Drawing.Point(874, 140); + this.maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + this.maskedTextBoxNumber.Size = new System.Drawing.Size(110, 23); + this.maskedTextBoxNumber.TabIndex = 3; + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(840, 167); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(165, 45); + this.buttonDelete.TabIndex = 4; + this.buttonDelete.Text = "Удалить грузовик"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonRemoveTruck_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(840, 260); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(165, 45); + this.buttonUpdate.TabIndex = 5; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRefreshCollection_Click); + // + // FormTruckCollection + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1152, 382); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.maskedTextBoxNumber); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.labelInstruments); + this.Controls.Add(this.pictureBoxCollection); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormTruckCollection"; + this.Text = "Грузовик"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxCollection; + private Label labelInstruments; + private Button buttonAdd; + private TextBox maskedTextBoxNumber; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs new file mode 100644 index 0000000..3801af1 --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs @@ -0,0 +1,85 @@ +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; +using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Generic; +using ProjectGasolineTanker.MovementStratg; + +namespace ProjectGasolineTanker +{ + public partial class FormTruckCollection : Form + { + + private readonly TruckGenericCollection _truck; + + public FormTruckCollection() + { + InitializeComponent(); + _truck = new TruckGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + + } + + private void ButtonAddTruck_Click(object sender, EventArgs e) + { + FormGasolineTanker form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_truck + form.SelectedTruck != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _truck.ShowTruck(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + private void ButtonRemoveTruck_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + + int pos = 0; + try + { + pos = Convert.ToInt32(maskedTextBoxNumber.Text) ; + + } + catch + { + MessageBox.Show("Ошибка ввода данных"); + return; + } + + + if (_truck - (_truck.ReturnLength() - pos)) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _truck.ShowTruck(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + + } + + private void ButtonRefreshCollection_Click(object sender, EventArgs + e) + { + pictureBoxCollection.Image = _truck.ShowTruck(); + } + + } +} diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.resx b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs b/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs new file mode 100644 index 0000000..e2551c0 --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.Generic +{ + internal class SetGeneric + where T : class + { + + private readonly T?[] _places; + + public int Count => _places.Length - 1; + public SetGeneric(int count) + { + _places = new T?[count]; + } + + public int Insert(T truck) + { + int pos = Count - 1; + + if (_places[Count] != null) + { + + + for (int i = pos; i > 0; --i) + { + if (_places[i] == null) + { + pos = i; + break; + } + } + + for (int i = pos + 1; i <= Count; ++i) + { + _places[i - 1] = _places[i]; + } + } + + _places[Count] = truck; + return pos; + } + + + public bool Insert(T truck, int position) + { + // TODO проверка позиции + if (position < 0 || position > Count) + { + return false; + } + + if (_places[Count] != null) + { + + int pos = Count; + for (int i = Count; i > 0; --i) + { + + if (_places[i] == null) + { + pos = i; + break; + } + } + + + for (int i = Count; i >= pos; --i) + { + _places[i - 1] = _places[i]; + } + } + + _places[Count] = truck; + return true; + } + + + public bool Remove(int position) + { + + if (position < 0 || position > Count) + { + return false; + } + _places[position] = null; + + return true; + } + + + public T? Get(int position) + { + + if (position < 0 || position > Count) + { + return null; + } + return _places[position]; + } + } +} diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs new file mode 100644 index 0000000..bdb7034 --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.MovementStratg; + +namespace ProjectGasolineTanker.Generic +{ + internal class TruckGenericCollection + where T : DrawingTruck + where U : IMoveableObject + { + private readonly int _pictureWidth; + private readonly int _pictureHeight; + + private readonly int _placeSizeWidth = 200; + private readonly int _placeSizeHeight = 80; + + private readonly SetGeneric _collection; + + + public TruckGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + + _collection = new SetGeneric(width * height); + } + public static int operator +(TruckGenericCollection collect, T? obj) + { + if (obj != null) + { + return collect._collection.Insert(obj); + } + return -1; + } + public static bool operator -(TruckGenericCollection collect, int pos) + { + if (collect._collection.Get(pos) == null) + { + return false; + } + return collect?._collection.Remove(pos) ?? false; + } + + public int ReturnLength() + { + return _collection.Count; + } + + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + + + public Bitmap ShowTruck() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + + + private void DrawBackground(Graphics gr) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { + gr.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + gr.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + } + + private void DrawObjects(Graphics g) + { + + int x = 0; + int y = 0; + int index = -1; + + for (int i = 0; i <= _collection.Count; ++i) + { + + DrawingTruck _truck = _collection.Get(i); + + x = 0; + y = 0; + if (_truck != null) + { + + index = i; + while (index - _pictureWidth / _placeSizeWidth >= 0) + { + y++; + index -= _pictureWidth / _placeSizeWidth; + } + + if (index > 0) + { + x += index; + } + + x = _pictureWidth / _placeSizeWidth - 1 - x; + _truck.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y); + _truck.DrawTransport(g); + } + } + } + } +} \ No newline at end of file diff --git a/GasolineTanker/ProjectGasolineTanker/AbstractStrategy.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs similarity index 92% rename from GasolineTanker/ProjectGasolineTanker/AbstractStrategy.cs rename to GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs index e07c161..0051dca 100644 --- a/GasolineTanker/ProjectGasolineTanker/AbstractStrategy.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs @@ -1,22 +1,27 @@ -using ProjectGasolineTanker.MovementStrategy; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Entities; -using ProjectGasolineTanker.DrawingObjects; - -namespace ProjectGasolineTanker.MovementStrategy +namespace ProjectGasolineTanker.MovementStratg { + 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) @@ -29,6 +34,7 @@ namespace ProjectGasolineTanker.MovementStrategy FieldWidth = width; FieldHeight = height; } + public void MakeStep() { if (_state != Status.InProgress) @@ -42,11 +48,17 @@ namespace ProjectGasolineTanker.MovementStrategy } 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) @@ -55,8 +67,11 @@ namespace ProjectGasolineTanker.MovementStrategy } return _moveableObject?.GetStep; } + protected abstract void MoveToTarget(); + protected abstract bool IsTargetDestinaion(); + private bool MoveTo(DirectionType directionType) { if (_state != Status.InProgress) @@ -71,4 +86,8 @@ namespace ProjectGasolineTanker.MovementStrategy return false; } } -} \ No newline at end of file + + + +} + diff --git a/GasolineTanker/ProjectGasolineTanker/DrawingObjectTruck.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/DrawingObjectTruck.cs similarity index 79% rename from GasolineTanker/ProjectGasolineTanker/DrawingObjectTruck.cs rename to GasolineTanker/ProjectGasolineTanker/MovementStratg/DrawingObjectTruck.cs index 1f52340..6760824 100644 --- a/GasolineTanker/ProjectGasolineTanker/DrawingObjectTruck.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/DrawingObjectTruck.cs @@ -1,15 +1,15 @@ -using ProjectGasolineTanker.MovementStrategy; -using ProjectGasolineTanker; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; +using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Entities; -using ProjectGasolineTanker.DrawingObjects; -namespace ProjectGasolineTanker.MovementStrategy +namespace ProjectGasolineTanker.MovementStratg { + public class DrawingObjectTruck : IMoveableObject { private readonly DrawingTruck? _drawingTruck = null; @@ -25,11 +25,12 @@ namespace ProjectGasolineTanker.MovementStrategy { return null; } - return new ObjectParameters(_drawingTruck.GetPosX,_drawingTruck.GetPosY, _drawingTruck.GetWidth, _drawingTruck.GetHeight); + return new ObjectParameters(_drawingTruck.GetPosX, _drawingTruck.GetPosY, _drawingTruck.GetWidth, _drawingTruck.GetHeight); } } public int GetStep => (int)(_drawingTruck?.EntityTruck?.Step ?? 0); public bool CheckCanMove(DirectionType direction) => _drawingTruck?.CanMove(direction) ?? false; public void MoveObject(DirectionType direction) => _drawingTruck?.MoveTransport(direction); } -} \ No newline at end of file +} + diff --git a/GasolineTanker/ProjectGasolineTanker/IMoveableObject.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs similarity index 72% rename from GasolineTanker/ProjectGasolineTanker/IMoveableObject.cs rename to GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs index f28d991..220e961 100644 --- a/GasolineTanker/ProjectGasolineTanker/IMoveableObject.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs @@ -4,15 +4,23 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using ProjectGasolineTanker.DrawingObjects; +using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Entities; -namespace ProjectGasolineTanker.MovementStrategy +namespace ProjectGasolineTanker.MovementStratg { + public interface IMoveableObject { + ObjectParameters? GetObjectPosition { get; } + int GetStep { get; } + bool CheckCanMove(DirectionType direction); + void MoveObject(DirectionType direction); + + } -} \ No newline at end of file +} diff --git a/GasolineTanker/ProjectGasolineTanker/MoveToBorder.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToBorder.cs similarity index 92% rename from GasolineTanker/ProjectGasolineTanker/MoveToBorder.cs rename to GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToBorder.cs index 0af485a..d1f0129 100644 --- a/GasolineTanker/ProjectGasolineTanker/MoveToBorder.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToBorder.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectGasolineTanker.MovementStrategy +namespace ProjectGasolineTanker.MovementStratg { internal class MoveToBorder : AbstractStrategy { @@ -18,7 +18,7 @@ namespace ProjectGasolineTanker.MovementStrategy return objParams.RightBorder <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder <= FieldHeight && - objParams.DownBorder + GetStep() >= FieldHeight; + objParams.DownBorder + GetStep() >= FieldHeight; } protected override void MoveToTarget() { @@ -54,4 +54,4 @@ namespace ProjectGasolineTanker.MovementStrategy } } } -} \ No newline at end of file +} diff --git a/GasolineTanker/ProjectGasolineTanker/MoveToCenter.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs similarity index 96% rename from GasolineTanker/ProjectGasolineTanker/MoveToCenter.cs rename to GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs index 48605d6..2038b2a 100644 --- a/GasolineTanker/ProjectGasolineTanker/MoveToCenter.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs @@ -4,8 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectGasolineTanker.MovementStrategy +namespace ProjectGasolineTanker.MovementStratg { + public class MoveToCenter : AbstractStrategy { protected override bool IsTargetDestinaion() @@ -54,4 +55,4 @@ namespace ProjectGasolineTanker.MovementStrategy } } } -} \ No newline at end of file +} diff --git a/GasolineTanker/ProjectGasolineTanker/ObjectParameters.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/ObjectParameters.cs similarity index 93% rename from GasolineTanker/ProjectGasolineTanker/ObjectParameters.cs rename to GasolineTanker/ProjectGasolineTanker/MovementStratg/ObjectParameters.cs index f64e34d..7e444ba 100644 --- a/GasolineTanker/ProjectGasolineTanker/ObjectParameters.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/ObjectParameters.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectGasolineTanker.MovementStrategy +namespace ProjectGasolineTanker.MovementStratg { public class ObjectParameters { @@ -12,12 +12,19 @@ namespace ProjectGasolineTanker.MovementStrategy 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; @@ -26,4 +33,4 @@ namespace ProjectGasolineTanker.MovementStrategy _height = height; } } -} \ No newline at end of file +} diff --git a/GasolineTanker/ProjectGasolineTanker/Status.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/Status.cs similarity index 80% rename from GasolineTanker/ProjectGasolineTanker/Status.cs rename to GasolineTanker/ProjectGasolineTanker/MovementStratg/Status.cs index 0fc547f..c0d815e 100644 --- a/GasolineTanker/ProjectGasolineTanker/Status.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/Status.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectGasolineTanker.MovementStrategy +namespace ProjectGasolineTanker.MovementStratg { public enum Status { @@ -12,4 +12,4 @@ namespace ProjectGasolineTanker.MovementStrategy InProgress, Finish } -} \ No newline at end of file +} diff --git a/GasolineTanker/ProjectGasolineTanker/Program.cs b/GasolineTanker/ProjectGasolineTanker/Program.cs index fa1a74f..8a40783 100644 --- a/GasolineTanker/ProjectGasolineTanker/Program.cs +++ b/GasolineTanker/ProjectGasolineTanker/Program.cs @@ -11,7 +11,7 @@ namespace ProjectGasolineTanker // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormGasolineTanker()); + Application.Run(new FormTruckCollection()); } } } \ No newline at end of file