From 3bd364d6abbe06d165eb1ff7e420ef8274a9854b Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Wed, 11 Oct 2023 10:05:42 +0400 Subject: [PATCH 1/3] lab2 --- MonorailProject/MonorailProject.sln | 25 +++ MonorailProject/MonorailProject/Direction.cs | 16 ++ .../DrawningObjects/DrawningMonorail.cs | 156 +++++++++++++++ .../DrawningObjects/DrawningSecondMonorail.cs | 99 ++++++++++ .../Entities/EntityMonorail.cs | 22 +++ .../Entities/EntitySecondMonorail.cs | 23 +++ .../MonorailProject/Form1.Designer.cs | 183 ++++++++++++++++++ MonorailProject/MonorailProject/Form1.cs | 113 +++++++++++ MonorailProject/MonorailProject/Form1.resx | 120 ++++++++++++ .../MonorailProject/MonorailProject.csproj | 26 +++ .../MovementStrategy/AbstractStrategy.cs | 73 +++++++ .../DrawningObjectMonorail.cs | 37 ++++ .../MovementStrategy/IMoveableObject.cs | 17 ++ .../MovementStrategy/MoveToBorder.cs | 56 ++++++ .../MovementStrategy/MoveToCenter.cs | 56 ++++++ .../MovementStrategy/ObjectParameters.cs | 30 +++ .../MovementStrategy/Status.cs | 16 ++ MonorailProject/MonorailProject/Program.cs | 17 ++ .../Properties/Resources.Designer.cs | 103 ++++++++++ .../MonorailProject/Properties/Resources.resx | 133 +++++++++++++ .../MonorailProject/Resources/down-arrow.png | Bin 0 -> 281 bytes .../MonorailProject/Resources/left-arrow.png | Bin 0 -> 265 bytes .../MonorailProject/Resources/right-arrow.png | Bin 0 -> 224 bytes .../MonorailProject/Resources/upper-arrow.png | Bin 0 -> 264 bytes 24 files changed, 1321 insertions(+) create mode 100644 MonorailProject/MonorailProject.sln create mode 100644 MonorailProject/MonorailProject/Direction.cs create mode 100644 MonorailProject/MonorailProject/DrawningObjects/DrawningMonorail.cs create mode 100644 MonorailProject/MonorailProject/DrawningObjects/DrawningSecondMonorail.cs create mode 100644 MonorailProject/MonorailProject/Entities/EntityMonorail.cs create mode 100644 MonorailProject/MonorailProject/Entities/EntitySecondMonorail.cs create mode 100644 MonorailProject/MonorailProject/Form1.Designer.cs create mode 100644 MonorailProject/MonorailProject/Form1.cs create mode 100644 MonorailProject/MonorailProject/Form1.resx create mode 100644 MonorailProject/MonorailProject/MonorailProject.csproj create mode 100644 MonorailProject/MonorailProject/MovementStrategy/AbstractStrategy.cs create mode 100644 MonorailProject/MonorailProject/MovementStrategy/DrawningObjectMonorail.cs create mode 100644 MonorailProject/MonorailProject/MovementStrategy/IMoveableObject.cs create mode 100644 MonorailProject/MonorailProject/MovementStrategy/MoveToBorder.cs create mode 100644 MonorailProject/MonorailProject/MovementStrategy/MoveToCenter.cs create mode 100644 MonorailProject/MonorailProject/MovementStrategy/ObjectParameters.cs create mode 100644 MonorailProject/MonorailProject/MovementStrategy/Status.cs create mode 100644 MonorailProject/MonorailProject/Program.cs create mode 100644 MonorailProject/MonorailProject/Properties/Resources.Designer.cs create mode 100644 MonorailProject/MonorailProject/Properties/Resources.resx create mode 100644 MonorailProject/MonorailProject/Resources/down-arrow.png create mode 100644 MonorailProject/MonorailProject/Resources/left-arrow.png create mode 100644 MonorailProject/MonorailProject/Resources/right-arrow.png create mode 100644 MonorailProject/MonorailProject/Resources/upper-arrow.png diff --git a/MonorailProject/MonorailProject.sln b/MonorailProject/MonorailProject.sln new file mode 100644 index 0000000..45d9d58 --- /dev/null +++ b/MonorailProject/MonorailProject.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33801.468 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonorailProject", "MonorailProject\MonorailProject.csproj", "{9FCA3318-633F-404A-B465-6DF510961ED2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9FCA3318-633F-404A-B465-6DF510961ED2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9FCA3318-633F-404A-B465-6DF510961ED2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9FCA3318-633F-404A-B465-6DF510961ED2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9FCA3318-633F-404A-B465-6DF510961ED2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E490344E-18A5-4A0A-A607-857B4986CFC5} + EndGlobalSection +EndGlobal diff --git a/MonorailProject/MonorailProject/Direction.cs b/MonorailProject/MonorailProject/Direction.cs new file mode 100644 index 0000000..c11bd2a --- /dev/null +++ b/MonorailProject/MonorailProject/Direction.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MonorailProject +{ + public enum DirectionType + { + Up = 1, + Down = 2, + Left = 3, + Right = 4 + } +} diff --git a/MonorailProject/MonorailProject/DrawningObjects/DrawningMonorail.cs b/MonorailProject/MonorailProject/DrawningObjects/DrawningMonorail.cs new file mode 100644 index 0000000..0ee1b21 --- /dev/null +++ b/MonorailProject/MonorailProject/DrawningObjects/DrawningMonorail.cs @@ -0,0 +1,156 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MonorailProject.Entities; + +namespace MonorailProject.DrawningObjects +{ + public class DrawningMonorail + { + public EntityMonorail? EntityMonorail { get; protected set; } + private int _pictureWidth; + private int _pictureHeight; + protected int _startPosX; + protected int _startPosY; + protected int _relWidth = 150; + protected readonly int _relHeight = 46; + public DrawningMonorail(int speed, double weight, Color bodyColor, int width, int height) + { + if (0 + _relWidth >= width || 0 + _relHeight >= height) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + EntityMonorail = new EntityMonorail(speed, weight, bodyColor); + } + protected DrawningMonorail(int speed, double weight, Color bodyColor, int width, + int height, int carWidth, int carHeight) + { + if (0 + _relWidth >= width || 0 + _relHeight >= height) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + _relWidth = carWidth; + _relHeight = carHeight; + EntityMonorail = new EntityMonorail(speed, weight, bodyColor); + } + public void SetPosition(int x, int y) + { + if (x < 0 || x > _pictureWidth - _relWidth) + { + x = 0; + } + if (y < 0 || y > _pictureHeight - _relHeight) + { + y = 0; + } + _startPosX = x; + _startPosY = y; + } + public void MoveTransport(DirectionType direction) + { + if (!CanMove(direction) || EntityMonorail == null) + { + return; + } + switch (direction) + { + case DirectionType.Left: + _startPosX -= (int)EntityMonorail.Step; + break; + case DirectionType.Right: + _startPosX += (int)EntityMonorail.Step; + break; + case DirectionType.Up: + _startPosY -= (int)EntityMonorail.Step; + break; + case DirectionType.Down: + _startPosY += (int)EntityMonorail.Step; + break; + } + } + public int GetPosX => _startPosX; + public int GetPosY => _startPosY; + public int GetWidth => _relWidth; + public int GetHeight => _relHeight; + public bool CanMove(DirectionType direction) + { + if (EntityMonorail == null) + { + return false; + } + return direction switch + { + DirectionType.Left => _startPosX - EntityMonorail.Step > 0, + DirectionType.Up => _startPosY - EntityMonorail.Step > 0, + DirectionType.Right => _startPosX + EntityMonorail.Step < _pictureWidth - _relWidth, + DirectionType.Down => _startPosY + EntityMonorail.Step < _pictureHeight - _relHeight + }; + } + + + public virtual void DrawTransport(Graphics g) + { + if (EntityMonorail == null) + { + return; + } + _relWidth = 150; + Pen pen = new(Color.Black, 2); + Brush bodyBrush = new SolidBrush(EntityMonorail.BodyColor); + //колёса + + g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 50, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 110, _startPosY + 35, 15, 15); + g.DrawRectangle(pen, _startPosX + 22, _startPosY + 36, 40, 8); + g.DrawRectangle(pen, _startPosX + 82, _startPosY + 36, 40, 8); + g.DrawEllipse(pen, _startPosX + 3, _startPosY + 37, 30, 8); + g.DrawEllipse(pen, _startPosX + 110, _startPosY + 37, 29, 8); + + Brush brBlack = new SolidBrush(Color.Black); + g.FillRectangle(brBlack, _startPosX + 22, _startPosY + 36, 40, 8); + g.FillRectangle(brBlack, _startPosX + 82, _startPosY + 36, 40, 8); + g.FillEllipse(brBlack, _startPosX + 3, _startPosY + 37, 30, 8); + g.FillEllipse(brBlack, _startPosX + 110, _startPosY + 37, 29, 8); + + Brush brWhite = new SolidBrush(Color.White); + g.FillEllipse(brWhite, _startPosX + 20, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 50, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 80, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 110, _startPosY + 35, 15, 15); + + //Кабина + + g.DrawRectangle(pen, _startPosX + 10, _startPosY + 20, 120, 16); + g.FillRectangle(bodyBrush, _startPosX + 10, _startPosY + 20, 120, 16); + Point p1 = new Point(_startPosX + 10, _startPosY + 20); + Point p2 = new Point(_startPosX + 130, _startPosY + 20); + Point p3 = new Point(_startPosX + 130, _startPosY + 5); + Point p4 = new Point(_startPosX + 13, _startPosY + 5); + + g.DrawPolygon(pen, new Point[] { p1, p2, p3, p4 }); + g.FillPolygon(bodyBrush, new Point[] { p1, p2, p3, p4 }); + + + //дверь + g.FillRectangle(brWhite, _startPosX + 49, _startPosY + 9, 12, 22); + g.DrawRectangle(pen, _startPosX + 49, _startPosY + 9, 12, 22); + + //Окна и прочее + + Pen penBlue = new Pen(Color.Cyan, 2); + g.DrawRectangle(penBlue, _startPosX + 20, _startPosY + 8, 10, 10); + g.DrawRectangle(penBlue, _startPosX + 35, _startPosY + 8, 10, 10); + g.DrawRectangle(penBlue, _startPosX + 117, _startPosY + 8, 10, 10); + + g.DrawRectangle(pen, _startPosX + 132, _startPosY + 10, 2, 22); + } + } +} diff --git a/MonorailProject/MonorailProject/DrawningObjects/DrawningSecondMonorail.cs b/MonorailProject/MonorailProject/DrawningObjects/DrawningSecondMonorail.cs new file mode 100644 index 0000000..beda8a0 --- /dev/null +++ b/MonorailProject/MonorailProject/DrawningObjects/DrawningSecondMonorail.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MonorailProject.Entities; + +namespace MonorailProject.DrawningObjects +{ + public class DrawningSecondMonorail : DrawningMonorail + { + public DrawningSecondMonorail(int speed, double weight, Color bodyColor, Color +additionalColor, bool monorails, bool secondCabin, int width, int height) : + base(speed, weight, bodyColor, width, height, 110, 60) + { + if(EntityMonorail != null) + { + EntityMonorail = new EntitySecondMonorail(speed, weight, bodyColor, additionalColor, monorails, secondCabin); + } + } + public override void DrawTransport(Graphics g) + { + base.DrawTransport(g); + + if (EntityMonorail is not EntitySecondMonorail secondMonorail) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(secondMonorail.AdditionalColor); + Brush brBlack = new SolidBrush(Color.Black); + Brush brWhite = new SolidBrush(Color.White); + Pen penBlue = new Pen(Color.Cyan, 2); + + if (secondMonorail.Monorails) + { + g.DrawRectangle(pen, _startPosX, _startPosY + 50, 140, 10); + g.FillRectangle(brBlack, _startPosX, _startPosY + 50, 140, 10); + + g.FillRectangle(brWhite, _startPosX + 5, _startPosY + 53, 130, 5); + } + + if (secondMonorail.SecondCabin) + { + _relWidth = 290; + //низ + g.DrawEllipse(pen, _startPosX + 160, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 190, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 220, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 250, _startPosY + 35, 15, 15); + g.DrawRectangle(pen, _startPosX + 162, _startPosY + 36, 40, 8); + g.DrawRectangle(pen, _startPosX + 222, _startPosY + 36, 40, 8); + g.DrawEllipse(pen, _startPosX + 143, _startPosY + 37, 30, 8); + g.DrawEllipse(pen, _startPosX + 250, _startPosY + 37, 29, 8); + + g.FillRectangle(brBlack, _startPosX + 162, _startPosY + 36, 40, 8); + g.FillRectangle(brBlack, _startPosX + 222, _startPosY + 36, 40, 8); + g.FillEllipse(brBlack, _startPosX + 143, _startPosY + 37, 30, 8); + g.FillEllipse(brBlack, _startPosX + 250, _startPosY + 37, 29, 8); + + g.FillEllipse(brWhite, _startPosX + 160, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 190, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 220, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 250, _startPosY + 35, 15, 15); + + if (secondMonorail.Monorails) + { + g.DrawRectangle(pen, _startPosX + 140, _startPosY + 50, 145, 10); + g.FillRectangle(brBlack, _startPosX + 140, _startPosY + 50, 145, 10); + + g.FillRectangle(brWhite, _startPosX + 135, _startPosY + 53, 145, 5); + } + + //Кабина + g.DrawRectangle(pen, _startPosX + 150, _startPosY + 20, 120, 16); + g.FillRectangle(additionalBrush, _startPosX + 150, _startPosY + 20, 120, 16); + Point p5 = new Point(_startPosX + 150, _startPosY + 20); + Point p6 = new Point(_startPosX + 270, _startPosY + 20); + Point p7 = new Point(_startPosX + 267, _startPosY + 5); + Point p8 = new Point(_startPosX + 150, _startPosY + 5); + + g.DrawPolygon(pen, new Point[] { p5, p6, p7, p8 }); + g.FillPolygon(additionalBrush, new Point[] { p5, p6, p7, p8 }); + + //дверь + g.FillRectangle(brWhite, _startPosX + 189, _startPosY + 9, 12, 22); + g.DrawRectangle(pen, _startPosX + 189, _startPosY + 9, 12, 22); + + //Окна и прочее + g.DrawRectangle(penBlue, _startPosX + 160, _startPosY + 8, 10, 10); + g.DrawRectangle(penBlue, _startPosX + 175, _startPosY + 8, 10, 10); + g.DrawRectangle(penBlue, _startPosX + 257, _startPosY + 8, 10, 10); + + g.DrawRectangle(pen, _startPosX + 272, _startPosY + 10, 2, 22); + } + } + } +} diff --git a/MonorailProject/MonorailProject/Entities/EntityMonorail.cs b/MonorailProject/MonorailProject/Entities/EntityMonorail.cs new file mode 100644 index 0000000..3e16ca7 --- /dev/null +++ b/MonorailProject/MonorailProject/Entities/EntityMonorail.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MonorailProject.Entities +{ + public class EntityMonorail + { + 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 EntityMonorail(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } + } +} diff --git a/MonorailProject/MonorailProject/Entities/EntitySecondMonorail.cs b/MonorailProject/MonorailProject/Entities/EntitySecondMonorail.cs new file mode 100644 index 0000000..4678353 --- /dev/null +++ b/MonorailProject/MonorailProject/Entities/EntitySecondMonorail.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; + +namespace MonorailProject.Entities +{ + public class EntitySecondMonorail : EntityMonorail + { + public Color AdditionalColor { get; private set; } + public bool Monorails { get; private set; } + public bool SecondCabin { get; private set; } + public EntitySecondMonorail(int speed, double weight, Color bodyColor, + Color additionalColor, bool monorails, bool secondCabin) : base(speed, weight, bodyColor) + { + AdditionalColor = additionalColor; + Monorails = monorails; + SecondCabin = secondCabin; + } + } +} diff --git a/MonorailProject/MonorailProject/Form1.Designer.cs b/MonorailProject/MonorailProject/Form1.Designer.cs new file mode 100644 index 0000000..2ba3400 --- /dev/null +++ b/MonorailProject/MonorailProject/Form1.Designer.cs @@ -0,0 +1,183 @@ +namespace MonorailProject +{ + partial class Form1 + { + /// + /// 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() + { + pictureBoxMonorail = new PictureBox(); + buttonLeft = new Button(); + buttonDown = new Button(); + buttonRight = new Button(); + buttonUp = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStep = new Button(); + ButtonCreateSecondMonorail = new Button(); + ButtonCreateMonorail = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit(); + SuspendLayout(); + // + // pictureBoxMonorail + // + pictureBoxMonorail.Dock = DockStyle.Fill; + pictureBoxMonorail.Location = new Point(0, 0); + pictureBoxMonorail.Name = "pictureBoxMonorail"; + pictureBoxMonorail.Size = new Size(800, 450); + pictureBoxMonorail.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxMonorail.TabIndex = 2; + pictureBoxMonorail.TabStop = false; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackColor = SystemColors.Info; + buttonLeft.BackgroundImage = Properties.Resources.left_arrow; + buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; + buttonLeft.Location = new Point(656, 398); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(40, 40); + buttonLeft.TabIndex = 14; + buttonLeft.UseVisualStyleBackColor = false; + buttonLeft.Click += ButtonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackColor = SystemColors.Info; + buttonDown.BackgroundImage = Properties.Resources.down_arrow; + buttonDown.BackgroundImageLayout = ImageLayout.Zoom; + buttonDown.Location = new Point(702, 398); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(40, 40); + buttonDown.TabIndex = 13; + buttonDown.UseVisualStyleBackColor = false; + buttonDown.Click += ButtonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackColor = SystemColors.Info; + buttonRight.BackgroundImage = Properties.Resources.right_arrow; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.Location = new Point(748, 398); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(40, 40); + buttonRight.TabIndex = 12; + buttonRight.UseVisualStyleBackColor = false; + buttonRight.Click += ButtonMove_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackColor = SystemColors.Info; + buttonUp.BackgroundImage = Properties.Resources.upper_arrow; + buttonUp.BackgroundImageLayout = ImageLayout.Zoom; + buttonUp.Location = new Point(702, 352); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(40, 40); + buttonUp.TabIndex = 11; + buttonUp.UseVisualStyleBackColor = false; + buttonUp.Click += ButtonMove_Click; + // + // comboBoxStrategy + // + comboBoxStrategy.BackColor = SystemColors.Info; + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "0", "1" }); + comboBoxStrategy.Location = new Point(637, 12); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(151, 28); + comboBoxStrategy.TabIndex = 15; + // + // buttonStep + // + buttonStep.BackColor = SystemColors.Info; + buttonStep.Location = new Point(694, 46); + buttonStep.Name = "buttonStep"; + buttonStep.Size = new Size(94, 29); + buttonStep.TabIndex = 16; + buttonStep.Text = "Шаг"; + buttonStep.UseVisualStyleBackColor = false; + buttonStep.Click += ButtonStep_Click; + // + // ButtonCreateSecondMonorail + // + ButtonCreateSecondMonorail.BackColor = SystemColors.Info; + ButtonCreateSecondMonorail.Location = new Point(205, 397); + ButtonCreateSecondMonorail.Name = "ButtonCreateSecondMonorail"; + ButtonCreateSecondMonorail.Size = new Size(239, 41); + ButtonCreateSecondMonorail.TabIndex = 17; + ButtonCreateSecondMonorail.Text = "Создать два Монорельса"; + ButtonCreateSecondMonorail.UseVisualStyleBackColor = false; + ButtonCreateSecondMonorail.Click += ButtonCreateSecondMonorail_Click; + // + // ButtonCreateMonorail + // + ButtonCreateMonorail.BackColor = SystemColors.Info; + ButtonCreateMonorail.Location = new Point(12, 397); + ButtonCreateMonorail.Name = "ButtonCreateMonorail"; + ButtonCreateMonorail.Size = new Size(175, 41); + ButtonCreateMonorail.TabIndex = 18; + ButtonCreateMonorail.Text = "Создать Монорельс"; + ButtonCreateMonorail.UseVisualStyleBackColor = false; + ButtonCreateMonorail.Click += ButtonCreateMonorail_Click; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = SystemColors.ControlDarkDark; + ClientSize = new Size(800, 450); + Controls.Add(ButtonCreateMonorail); + Controls.Add(ButtonCreateSecondMonorail); + Controls.Add(buttonStep); + Controls.Add(comboBoxStrategy); + Controls.Add(buttonLeft); + Controls.Add(buttonDown); + Controls.Add(buttonRight); + Controls.Add(buttonUp); + Controls.Add(pictureBoxMonorail); + Name = "Form1"; + Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxMonorail; + private Button buttonLeft; + private Button buttonDown; + private Button buttonRight; + private Button buttonUp; + private ComboBox comboBoxStrategy; + private Button buttonStep; + private Button ButtonCreateSecondMonorail; + private Button ButtonCreateMonorail; + } +} \ No newline at end of file diff --git a/MonorailProject/MonorailProject/Form1.cs b/MonorailProject/MonorailProject/Form1.cs new file mode 100644 index 0000000..99dd38f --- /dev/null +++ b/MonorailProject/MonorailProject/Form1.cs @@ -0,0 +1,113 @@ +using MonorailProject.DrawningObjects; +using MonorailProject.MovementStrategy; +namespace MonorailProject +{ + public partial class Form1 : Form + { + private DrawningMonorail? _drawningMonorail; + private AbstractStrategy? _abstractStrategy; + public Form1() + { + InitializeComponent(); + } + private void Draw() + { + if (_drawningMonorail == null) + { + return; + } + + Bitmap bmp = new(pictureBoxMonorail.Width, + pictureBoxMonorail.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningMonorail.DrawTransport(gr); + pictureBoxMonorail.Image = bmp; + } + private void ButtonCreateSecondMonorail_Click(object sender, EventArgs e) + { + Random random = new(); + + _drawningMonorail = new DrawningSecondMonorail(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)), + true, true, + pictureBoxMonorail.Width, pictureBoxMonorail.Height); + _drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, + 100)); + Draw(); + } + private void ButtonCreateMonorail_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningMonorail = new DrawningMonorail(random.Next(100, 300), + random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), pictureBoxMonorail.Width, pictureBoxMonorail.Height); + _drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningMonorail == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawningMonorail.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawningMonorail.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawningMonorail.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawningMonorail.MoveTransport(DirectionType.Right); + break; + } + Draw(); + } + private void ButtonStep_Click(object sender, EventArgs e) + { + if (_drawningMonorail == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _abstractStrategy = comboBoxStrategy.SelectedIndex + switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.SetData(new + DrawningObjectMonorail(_drawningMonorail), pictureBoxMonorail.Width, + pictureBoxMonorail.Height); + //comboBoxStrategy.Enabled = false; + } + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.MakeStep(); + Draw(); + if (_abstractStrategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.Enabled = true; + _abstractStrategy = null; + } + + } + } +} \ No newline at end of file diff --git a/MonorailProject/MonorailProject/Form1.resx b/MonorailProject/MonorailProject/Form1.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/MonorailProject/MonorailProject/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/MonorailProject/MonorailProject/MonorailProject.csproj b/MonorailProject/MonorailProject/MonorailProject.csproj new file mode 100644 index 0000000..13ee123 --- /dev/null +++ b/MonorailProject/MonorailProject/MonorailProject.csproj @@ -0,0 +1,26 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/MonorailProject/MonorailProject/MovementStrategy/AbstractStrategy.cs b/MonorailProject/MonorailProject/MovementStrategy/AbstractStrategy.cs new file mode 100644 index 0000000..1ff1d8e --- /dev/null +++ b/MonorailProject/MonorailProject/MovementStrategy/AbstractStrategy.cs @@ -0,0 +1,73 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MonorailProject.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/MonorailProject/MonorailProject/MovementStrategy/DrawningObjectMonorail.cs b/MonorailProject/MonorailProject/MovementStrategy/DrawningObjectMonorail.cs new file mode 100644 index 0000000..860c68a --- /dev/null +++ b/MonorailProject/MonorailProject/MovementStrategy/DrawningObjectMonorail.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MonorailProject.DrawningObjects; + +namespace MonorailProject.MovementStrategy +{ + public class DrawningObjectMonorail : IMoveableObject + { + private readonly DrawningMonorail? _drawningMonorail = null; + public DrawningObjectMonorail(DrawningMonorail drawningMonorail) + { + _drawningMonorail = drawningMonorail; + } + public ObjectParameters? GetObjectPosition + { + get + { + if (_drawningMonorail == null || _drawningMonorail.EntityMonorail == + null) + { + return null; + } + return new ObjectParameters(_drawningMonorail.GetPosX, + _drawningMonorail.GetPosY, _drawningMonorail.GetWidth, _drawningMonorail.GetHeight); + } + } + public int GetStep => (int)(_drawningMonorail?.EntityMonorail?.Step ?? 0); + public bool CheckCanMove(DirectionType direction) => + _drawningMonorail?.CanMove(direction) ?? false; + public void MoveObject(DirectionType direction) => + _drawningMonorail?.MoveTransport(direction); + } + +} diff --git a/MonorailProject/MonorailProject/MovementStrategy/IMoveableObject.cs b/MonorailProject/MonorailProject/MovementStrategy/IMoveableObject.cs new file mode 100644 index 0000000..faa67a4 --- /dev/null +++ b/MonorailProject/MonorailProject/MovementStrategy/IMoveableObject.cs @@ -0,0 +1,17 @@ +using MonorailProject.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MonorailProject.MovementStrategy +{ + public interface IMoveableObject + { + ObjectParameters? GetObjectPosition { get; } + int GetStep { get; } + bool CheckCanMove(DirectionType direction); + void MoveObject(DirectionType direction); + } +} diff --git a/MonorailProject/MonorailProject/MovementStrategy/MoveToBorder.cs b/MonorailProject/MonorailProject/MovementStrategy/MoveToBorder.cs new file mode 100644 index 0000000..0b0998c --- /dev/null +++ b/MonorailProject/MonorailProject/MovementStrategy/MoveToBorder.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MonorailProject.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/MonorailProject/MonorailProject/MovementStrategy/MoveToCenter.cs b/MonorailProject/MonorailProject/MovementStrategy/MoveToCenter.cs new file mode 100644 index 0000000..857c1a1 --- /dev/null +++ b/MonorailProject/MonorailProject/MovementStrategy/MoveToCenter.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MonorailProject.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/MonorailProject/MonorailProject/MovementStrategy/ObjectParameters.cs b/MonorailProject/MonorailProject/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..224012b --- /dev/null +++ b/MonorailProject/MonorailProject/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MonorailProject.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/MonorailProject/MonorailProject/MovementStrategy/Status.cs b/MonorailProject/MonorailProject/MovementStrategy/Status.cs new file mode 100644 index 0000000..190029c --- /dev/null +++ b/MonorailProject/MonorailProject/MovementStrategy/Status.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MonorailProject.MovementStrategy +{ + public enum Status + { + NotInit, + InProgress, + Finish + } + +} diff --git a/MonorailProject/MonorailProject/Program.cs b/MonorailProject/MonorailProject/Program.cs new file mode 100644 index 0000000..a0a7472 --- /dev/null +++ b/MonorailProject/MonorailProject/Program.cs @@ -0,0 +1,17 @@ +namespace MonorailProject +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/MonorailProject/MonorailProject/Properties/Resources.Designer.cs b/MonorailProject/MonorailProject/Properties/Resources.Designer.cs new file mode 100644 index 0000000..1d7c9f9 --- /dev/null +++ b/MonorailProject/MonorailProject/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace MonorailProject.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MonorailProject.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap down_arrow { + get { + object obj = ResourceManager.GetObject("down-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap left_arrow { + get { + object obj = ResourceManager.GetObject("left-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap right_arrow { + get { + object obj = ResourceManager.GetObject("right-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap upper_arrow { + get { + object obj = ResourceManager.GetObject("upper-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/MonorailProject/MonorailProject/Properties/Resources.resx b/MonorailProject/MonorailProject/Properties/Resources.resx new file mode 100644 index 0000000..44bb4fe --- /dev/null +++ b/MonorailProject/MonorailProject/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\Resources\down-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\right-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\upper-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\left-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/MonorailProject/MonorailProject/Resources/down-arrow.png b/MonorailProject/MonorailProject/Resources/down-arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..9d67143363585e3432a1c1d203ab1b9c01976c50 GIT binary patch literal 281 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oArNM~bhqvgQ1G;; zi(^Q|oVQcGxehr9xZG!PJ=iKPkv~* zc9Kx^`?K)}4&8QsA++)Z=NaeL@TnCH#^;@Tgv2kJgjw7>ZYuCH(qz)4*DH2Ru$Mb* cz?1ZWvE`jXwNtr}CD2<8p00i_>zopr0H3RI6#xJL literal 0 HcmV?d00001 diff --git a/MonorailProject/MonorailProject/Resources/left-arrow.png b/MonorailProject/MonorailProject/Resources/left-arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..046470dd1579e2ce99e38e48677f93b995460f47 GIT binary patch literal 265 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oArNM~bhqvgP;j@W zi(^Q|oVU|#xtJVz+~TLPvK|zU=>9%IR50azvg(S67o|20$2W@PT-(3ZQ}D>v**$AM z9~3wt^4`$XaKfZXmnNm`XLx_4;d#{Y1DqBNvH2B@Ar5QPm(+f2is!A77T$Nb@L`vJ z!N<1uwhtDSGR)zvNq*OSE>?;q>{)3O*9}3RhUml3c6<6X?w%M??e!!o{lH-l9p`3y z&ohn7Cq`t%+o+y0?@ZL`y>m)cVfjVm7Hdm6Pg#bRdv?g zo_d7i&cBX%-Up_*C#c3a-842yRoo=xRhZ?*{Ndc)p1PG@KZIFQcRaRubCl_?gn{+W T1E1yqUB}?*>gTe~DWM4frWsJb literal 0 HcmV?d00001 diff --git a/MonorailProject/MonorailProject/Resources/upper-arrow.png b/MonorailProject/MonorailProject/Resources/upper-arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..0bc323d4a84a7434e950a34a05d6b0cd4e0a1c26 GIT binary patch literal 264 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oArNM~bhqvgP;i&0 zi(^Q|oVQbbxegf!xW#)r9MrC8xaTY)c*L7CcFT3a^G|}xyX^1!D7K_1`USOA8kl%4 zuawtak|5Fc@p(wlfHmbNxVQmhc^IrFsVWmFgSL${tdEQr8i?PC!r5 z-mCYs_=f9zf$C58UcX%ZI{$%y&F{@MtaofZ#Vy%)J(#?rbq3?~4jUeUwjGSzQ!Gv{ z%T?&_jecpHJ#SL+0#A Date: Fri, 20 Oct 2023 19:59:36 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9E=D1=82=D0=BA=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MonorailProject/MonorailProject.sln | 25 --- MonorailProject/MonorailProject/Direction.cs | 16 -- .../DrawningObjects/DrawningMonorail.cs | 156 --------------- .../DrawningObjects/DrawningSecondMonorail.cs | 99 ---------- .../Entities/EntityMonorail.cs | 22 --- .../Entities/EntitySecondMonorail.cs | 23 --- .../MonorailProject/Form1.Designer.cs | 183 ------------------ MonorailProject/MonorailProject/Form1.cs | 113 ----------- MonorailProject/MonorailProject/Form1.resx | 120 ------------ .../MonorailProject/MonorailProject.csproj | 26 --- .../MovementStrategy/AbstractStrategy.cs | 73 ------- .../DrawningObjectMonorail.cs | 37 ---- .../MovementStrategy/IMoveableObject.cs | 17 -- .../MovementStrategy/MoveToBorder.cs | 56 ------ .../MovementStrategy/MoveToCenter.cs | 56 ------ .../MovementStrategy/ObjectParameters.cs | 30 --- .../MovementStrategy/Status.cs | 16 -- MonorailProject/MonorailProject/Program.cs | 17 -- .../Properties/Resources.Designer.cs | 103 ---------- .../MonorailProject/Properties/Resources.resx | 133 ------------- .../MonorailProject/Resources/down-arrow.png | Bin 281 -> 0 bytes .../MonorailProject/Resources/left-arrow.png | Bin 265 -> 0 bytes .../MonorailProject/Resources/right-arrow.png | Bin 224 -> 0 bytes .../MonorailProject/Resources/upper-arrow.png | Bin 264 -> 0 bytes 24 files changed, 1321 deletions(-) delete mode 100644 MonorailProject/MonorailProject.sln delete mode 100644 MonorailProject/MonorailProject/Direction.cs delete mode 100644 MonorailProject/MonorailProject/DrawningObjects/DrawningMonorail.cs delete mode 100644 MonorailProject/MonorailProject/DrawningObjects/DrawningSecondMonorail.cs delete mode 100644 MonorailProject/MonorailProject/Entities/EntityMonorail.cs delete mode 100644 MonorailProject/MonorailProject/Entities/EntitySecondMonorail.cs delete mode 100644 MonorailProject/MonorailProject/Form1.Designer.cs delete mode 100644 MonorailProject/MonorailProject/Form1.cs delete mode 100644 MonorailProject/MonorailProject/Form1.resx delete mode 100644 MonorailProject/MonorailProject/MonorailProject.csproj delete mode 100644 MonorailProject/MonorailProject/MovementStrategy/AbstractStrategy.cs delete mode 100644 MonorailProject/MonorailProject/MovementStrategy/DrawningObjectMonorail.cs delete mode 100644 MonorailProject/MonorailProject/MovementStrategy/IMoveableObject.cs delete mode 100644 MonorailProject/MonorailProject/MovementStrategy/MoveToBorder.cs delete mode 100644 MonorailProject/MonorailProject/MovementStrategy/MoveToCenter.cs delete mode 100644 MonorailProject/MonorailProject/MovementStrategy/ObjectParameters.cs delete mode 100644 MonorailProject/MonorailProject/MovementStrategy/Status.cs delete mode 100644 MonorailProject/MonorailProject/Program.cs delete mode 100644 MonorailProject/MonorailProject/Properties/Resources.Designer.cs delete mode 100644 MonorailProject/MonorailProject/Properties/Resources.resx delete mode 100644 MonorailProject/MonorailProject/Resources/down-arrow.png delete mode 100644 MonorailProject/MonorailProject/Resources/left-arrow.png delete mode 100644 MonorailProject/MonorailProject/Resources/right-arrow.png delete mode 100644 MonorailProject/MonorailProject/Resources/upper-arrow.png diff --git a/MonorailProject/MonorailProject.sln b/MonorailProject/MonorailProject.sln deleted file mode 100644 index 45d9d58..0000000 --- a/MonorailProject/MonorailProject.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.6.33801.468 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonorailProject", "MonorailProject\MonorailProject.csproj", "{9FCA3318-633F-404A-B465-6DF510961ED2}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9FCA3318-633F-404A-B465-6DF510961ED2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9FCA3318-633F-404A-B465-6DF510961ED2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9FCA3318-633F-404A-B465-6DF510961ED2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9FCA3318-633F-404A-B465-6DF510961ED2}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {E490344E-18A5-4A0A-A607-857B4986CFC5} - EndGlobalSection -EndGlobal diff --git a/MonorailProject/MonorailProject/Direction.cs b/MonorailProject/MonorailProject/Direction.cs deleted file mode 100644 index c11bd2a..0000000 --- a/MonorailProject/MonorailProject/Direction.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonorailProject -{ - public enum DirectionType - { - Up = 1, - Down = 2, - Left = 3, - Right = 4 - } -} diff --git a/MonorailProject/MonorailProject/DrawningObjects/DrawningMonorail.cs b/MonorailProject/MonorailProject/DrawningObjects/DrawningMonorail.cs deleted file mode 100644 index 0ee1b21..0000000 --- a/MonorailProject/MonorailProject/DrawningObjects/DrawningMonorail.cs +++ /dev/null @@ -1,156 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MonorailProject.Entities; - -namespace MonorailProject.DrawningObjects -{ - public class DrawningMonorail - { - public EntityMonorail? EntityMonorail { get; protected set; } - private int _pictureWidth; - private int _pictureHeight; - protected int _startPosX; - protected int _startPosY; - protected int _relWidth = 150; - protected readonly int _relHeight = 46; - public DrawningMonorail(int speed, double weight, Color bodyColor, int width, int height) - { - if (0 + _relWidth >= width || 0 + _relHeight >= height) - { - return; - } - _pictureWidth = width; - _pictureHeight = height; - EntityMonorail = new EntityMonorail(speed, weight, bodyColor); - } - protected DrawningMonorail(int speed, double weight, Color bodyColor, int width, - int height, int carWidth, int carHeight) - { - if (0 + _relWidth >= width || 0 + _relHeight >= height) - { - return; - } - _pictureWidth = width; - _pictureHeight = height; - _relWidth = carWidth; - _relHeight = carHeight; - EntityMonorail = new EntityMonorail(speed, weight, bodyColor); - } - public void SetPosition(int x, int y) - { - if (x < 0 || x > _pictureWidth - _relWidth) - { - x = 0; - } - if (y < 0 || y > _pictureHeight - _relHeight) - { - y = 0; - } - _startPosX = x; - _startPosY = y; - } - public void MoveTransport(DirectionType direction) - { - if (!CanMove(direction) || EntityMonorail == null) - { - return; - } - switch (direction) - { - case DirectionType.Left: - _startPosX -= (int)EntityMonorail.Step; - break; - case DirectionType.Right: - _startPosX += (int)EntityMonorail.Step; - break; - case DirectionType.Up: - _startPosY -= (int)EntityMonorail.Step; - break; - case DirectionType.Down: - _startPosY += (int)EntityMonorail.Step; - break; - } - } - public int GetPosX => _startPosX; - public int GetPosY => _startPosY; - public int GetWidth => _relWidth; - public int GetHeight => _relHeight; - public bool CanMove(DirectionType direction) - { - if (EntityMonorail == null) - { - return false; - } - return direction switch - { - DirectionType.Left => _startPosX - EntityMonorail.Step > 0, - DirectionType.Up => _startPosY - EntityMonorail.Step > 0, - DirectionType.Right => _startPosX + EntityMonorail.Step < _pictureWidth - _relWidth, - DirectionType.Down => _startPosY + EntityMonorail.Step < _pictureHeight - _relHeight - }; - } - - - public virtual void DrawTransport(Graphics g) - { - if (EntityMonorail == null) - { - return; - } - _relWidth = 150; - Pen pen = new(Color.Black, 2); - Brush bodyBrush = new SolidBrush(EntityMonorail.BodyColor); - //колёса - - g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 50, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 110, _startPosY + 35, 15, 15); - g.DrawRectangle(pen, _startPosX + 22, _startPosY + 36, 40, 8); - g.DrawRectangle(pen, _startPosX + 82, _startPosY + 36, 40, 8); - g.DrawEllipse(pen, _startPosX + 3, _startPosY + 37, 30, 8); - g.DrawEllipse(pen, _startPosX + 110, _startPosY + 37, 29, 8); - - Brush brBlack = new SolidBrush(Color.Black); - g.FillRectangle(brBlack, _startPosX + 22, _startPosY + 36, 40, 8); - g.FillRectangle(brBlack, _startPosX + 82, _startPosY + 36, 40, 8); - g.FillEllipse(brBlack, _startPosX + 3, _startPosY + 37, 30, 8); - g.FillEllipse(brBlack, _startPosX + 110, _startPosY + 37, 29, 8); - - Brush brWhite = new SolidBrush(Color.White); - g.FillEllipse(brWhite, _startPosX + 20, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 50, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 80, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 110, _startPosY + 35, 15, 15); - - //Кабина - - g.DrawRectangle(pen, _startPosX + 10, _startPosY + 20, 120, 16); - g.FillRectangle(bodyBrush, _startPosX + 10, _startPosY + 20, 120, 16); - Point p1 = new Point(_startPosX + 10, _startPosY + 20); - Point p2 = new Point(_startPosX + 130, _startPosY + 20); - Point p3 = new Point(_startPosX + 130, _startPosY + 5); - Point p4 = new Point(_startPosX + 13, _startPosY + 5); - - g.DrawPolygon(pen, new Point[] { p1, p2, p3, p4 }); - g.FillPolygon(bodyBrush, new Point[] { p1, p2, p3, p4 }); - - - //дверь - g.FillRectangle(brWhite, _startPosX + 49, _startPosY + 9, 12, 22); - g.DrawRectangle(pen, _startPosX + 49, _startPosY + 9, 12, 22); - - //Окна и прочее - - Pen penBlue = new Pen(Color.Cyan, 2); - g.DrawRectangle(penBlue, _startPosX + 20, _startPosY + 8, 10, 10); - g.DrawRectangle(penBlue, _startPosX + 35, _startPosY + 8, 10, 10); - g.DrawRectangle(penBlue, _startPosX + 117, _startPosY + 8, 10, 10); - - g.DrawRectangle(pen, _startPosX + 132, _startPosY + 10, 2, 22); - } - } -} diff --git a/MonorailProject/MonorailProject/DrawningObjects/DrawningSecondMonorail.cs b/MonorailProject/MonorailProject/DrawningObjects/DrawningSecondMonorail.cs deleted file mode 100644 index beda8a0..0000000 --- a/MonorailProject/MonorailProject/DrawningObjects/DrawningSecondMonorail.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MonorailProject.Entities; - -namespace MonorailProject.DrawningObjects -{ - public class DrawningSecondMonorail : DrawningMonorail - { - public DrawningSecondMonorail(int speed, double weight, Color bodyColor, Color -additionalColor, bool monorails, bool secondCabin, int width, int height) : - base(speed, weight, bodyColor, width, height, 110, 60) - { - if(EntityMonorail != null) - { - EntityMonorail = new EntitySecondMonorail(speed, weight, bodyColor, additionalColor, monorails, secondCabin); - } - } - public override void DrawTransport(Graphics g) - { - base.DrawTransport(g); - - if (EntityMonorail is not EntitySecondMonorail secondMonorail) - { - return; - } - - Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(secondMonorail.AdditionalColor); - Brush brBlack = new SolidBrush(Color.Black); - Brush brWhite = new SolidBrush(Color.White); - Pen penBlue = new Pen(Color.Cyan, 2); - - if (secondMonorail.Monorails) - { - g.DrawRectangle(pen, _startPosX, _startPosY + 50, 140, 10); - g.FillRectangle(brBlack, _startPosX, _startPosY + 50, 140, 10); - - g.FillRectangle(brWhite, _startPosX + 5, _startPosY + 53, 130, 5); - } - - if (secondMonorail.SecondCabin) - { - _relWidth = 290; - //низ - g.DrawEllipse(pen, _startPosX + 160, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 190, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 220, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 250, _startPosY + 35, 15, 15); - g.DrawRectangle(pen, _startPosX + 162, _startPosY + 36, 40, 8); - g.DrawRectangle(pen, _startPosX + 222, _startPosY + 36, 40, 8); - g.DrawEllipse(pen, _startPosX + 143, _startPosY + 37, 30, 8); - g.DrawEllipse(pen, _startPosX + 250, _startPosY + 37, 29, 8); - - g.FillRectangle(brBlack, _startPosX + 162, _startPosY + 36, 40, 8); - g.FillRectangle(brBlack, _startPosX + 222, _startPosY + 36, 40, 8); - g.FillEllipse(brBlack, _startPosX + 143, _startPosY + 37, 30, 8); - g.FillEllipse(brBlack, _startPosX + 250, _startPosY + 37, 29, 8); - - g.FillEllipse(brWhite, _startPosX + 160, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 190, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 220, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 250, _startPosY + 35, 15, 15); - - if (secondMonorail.Monorails) - { - g.DrawRectangle(pen, _startPosX + 140, _startPosY + 50, 145, 10); - g.FillRectangle(brBlack, _startPosX + 140, _startPosY + 50, 145, 10); - - g.FillRectangle(brWhite, _startPosX + 135, _startPosY + 53, 145, 5); - } - - //Кабина - g.DrawRectangle(pen, _startPosX + 150, _startPosY + 20, 120, 16); - g.FillRectangle(additionalBrush, _startPosX + 150, _startPosY + 20, 120, 16); - Point p5 = new Point(_startPosX + 150, _startPosY + 20); - Point p6 = new Point(_startPosX + 270, _startPosY + 20); - Point p7 = new Point(_startPosX + 267, _startPosY + 5); - Point p8 = new Point(_startPosX + 150, _startPosY + 5); - - g.DrawPolygon(pen, new Point[] { p5, p6, p7, p8 }); - g.FillPolygon(additionalBrush, new Point[] { p5, p6, p7, p8 }); - - //дверь - g.FillRectangle(brWhite, _startPosX + 189, _startPosY + 9, 12, 22); - g.DrawRectangle(pen, _startPosX + 189, _startPosY + 9, 12, 22); - - //Окна и прочее - g.DrawRectangle(penBlue, _startPosX + 160, _startPosY + 8, 10, 10); - g.DrawRectangle(penBlue, _startPosX + 175, _startPosY + 8, 10, 10); - g.DrawRectangle(penBlue, _startPosX + 257, _startPosY + 8, 10, 10); - - g.DrawRectangle(pen, _startPosX + 272, _startPosY + 10, 2, 22); - } - } - } -} diff --git a/MonorailProject/MonorailProject/Entities/EntityMonorail.cs b/MonorailProject/MonorailProject/Entities/EntityMonorail.cs deleted file mode 100644 index 3e16ca7..0000000 --- a/MonorailProject/MonorailProject/Entities/EntityMonorail.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonorailProject.Entities -{ - public class EntityMonorail - { - 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 EntityMonorail(int speed, double weight, Color bodyColor) - { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; - } - } -} diff --git a/MonorailProject/MonorailProject/Entities/EntitySecondMonorail.cs b/MonorailProject/MonorailProject/Entities/EntitySecondMonorail.cs deleted file mode 100644 index 4678353..0000000 --- a/MonorailProject/MonorailProject/Entities/EntitySecondMonorail.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.NetworkInformation; -using System.Text; -using System.Threading.Tasks; - -namespace MonorailProject.Entities -{ - public class EntitySecondMonorail : EntityMonorail - { - public Color AdditionalColor { get; private set; } - public bool Monorails { get; private set; } - public bool SecondCabin { get; private set; } - public EntitySecondMonorail(int speed, double weight, Color bodyColor, - Color additionalColor, bool monorails, bool secondCabin) : base(speed, weight, bodyColor) - { - AdditionalColor = additionalColor; - Monorails = monorails; - SecondCabin = secondCabin; - } - } -} diff --git a/MonorailProject/MonorailProject/Form1.Designer.cs b/MonorailProject/MonorailProject/Form1.Designer.cs deleted file mode 100644 index 2ba3400..0000000 --- a/MonorailProject/MonorailProject/Form1.Designer.cs +++ /dev/null @@ -1,183 +0,0 @@ -namespace MonorailProject -{ - partial class Form1 - { - /// - /// 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() - { - pictureBoxMonorail = new PictureBox(); - buttonLeft = new Button(); - buttonDown = new Button(); - buttonRight = new Button(); - buttonUp = new Button(); - comboBoxStrategy = new ComboBox(); - buttonStep = new Button(); - ButtonCreateSecondMonorail = new Button(); - ButtonCreateMonorail = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit(); - SuspendLayout(); - // - // pictureBoxMonorail - // - pictureBoxMonorail.Dock = DockStyle.Fill; - pictureBoxMonorail.Location = new Point(0, 0); - pictureBoxMonorail.Name = "pictureBoxMonorail"; - pictureBoxMonorail.Size = new Size(800, 450); - pictureBoxMonorail.SizeMode = PictureBoxSizeMode.AutoSize; - pictureBoxMonorail.TabIndex = 2; - pictureBoxMonorail.TabStop = false; - // - // buttonLeft - // - buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonLeft.BackColor = SystemColors.Info; - buttonLeft.BackgroundImage = Properties.Resources.left_arrow; - buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; - buttonLeft.Location = new Point(656, 398); - buttonLeft.Name = "buttonLeft"; - buttonLeft.Size = new Size(40, 40); - buttonLeft.TabIndex = 14; - buttonLeft.UseVisualStyleBackColor = false; - buttonLeft.Click += ButtonMove_Click; - // - // buttonDown - // - buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonDown.BackColor = SystemColors.Info; - buttonDown.BackgroundImage = Properties.Resources.down_arrow; - buttonDown.BackgroundImageLayout = ImageLayout.Zoom; - buttonDown.Location = new Point(702, 398); - buttonDown.Name = "buttonDown"; - buttonDown.Size = new Size(40, 40); - buttonDown.TabIndex = 13; - buttonDown.UseVisualStyleBackColor = false; - buttonDown.Click += ButtonMove_Click; - // - // buttonRight - // - buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonRight.BackColor = SystemColors.Info; - buttonRight.BackgroundImage = Properties.Resources.right_arrow; - buttonRight.BackgroundImageLayout = ImageLayout.Zoom; - buttonRight.Location = new Point(748, 398); - buttonRight.Name = "buttonRight"; - buttonRight.Size = new Size(40, 40); - buttonRight.TabIndex = 12; - buttonRight.UseVisualStyleBackColor = false; - buttonRight.Click += ButtonMove_Click; - // - // buttonUp - // - buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonUp.BackColor = SystemColors.Info; - buttonUp.BackgroundImage = Properties.Resources.upper_arrow; - buttonUp.BackgroundImageLayout = ImageLayout.Zoom; - buttonUp.Location = new Point(702, 352); - buttonUp.Name = "buttonUp"; - buttonUp.Size = new Size(40, 40); - buttonUp.TabIndex = 11; - buttonUp.UseVisualStyleBackColor = false; - buttonUp.Click += ButtonMove_Click; - // - // comboBoxStrategy - // - comboBoxStrategy.BackColor = SystemColors.Info; - comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxStrategy.FormattingEnabled = true; - comboBoxStrategy.Items.AddRange(new object[] { "0", "1" }); - comboBoxStrategy.Location = new Point(637, 12); - comboBoxStrategy.Name = "comboBoxStrategy"; - comboBoxStrategy.Size = new Size(151, 28); - comboBoxStrategy.TabIndex = 15; - // - // buttonStep - // - buttonStep.BackColor = SystemColors.Info; - buttonStep.Location = new Point(694, 46); - buttonStep.Name = "buttonStep"; - buttonStep.Size = new Size(94, 29); - buttonStep.TabIndex = 16; - buttonStep.Text = "Шаг"; - buttonStep.UseVisualStyleBackColor = false; - buttonStep.Click += ButtonStep_Click; - // - // ButtonCreateSecondMonorail - // - ButtonCreateSecondMonorail.BackColor = SystemColors.Info; - ButtonCreateSecondMonorail.Location = new Point(205, 397); - ButtonCreateSecondMonorail.Name = "ButtonCreateSecondMonorail"; - ButtonCreateSecondMonorail.Size = new Size(239, 41); - ButtonCreateSecondMonorail.TabIndex = 17; - ButtonCreateSecondMonorail.Text = "Создать два Монорельса"; - ButtonCreateSecondMonorail.UseVisualStyleBackColor = false; - ButtonCreateSecondMonorail.Click += ButtonCreateSecondMonorail_Click; - // - // ButtonCreateMonorail - // - ButtonCreateMonorail.BackColor = SystemColors.Info; - ButtonCreateMonorail.Location = new Point(12, 397); - ButtonCreateMonorail.Name = "ButtonCreateMonorail"; - ButtonCreateMonorail.Size = new Size(175, 41); - ButtonCreateMonorail.TabIndex = 18; - ButtonCreateMonorail.Text = "Создать Монорельс"; - ButtonCreateMonorail.UseVisualStyleBackColor = false; - ButtonCreateMonorail.Click += ButtonCreateMonorail_Click; - // - // Form1 - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - BackColor = SystemColors.ControlDarkDark; - ClientSize = new Size(800, 450); - Controls.Add(ButtonCreateMonorail); - Controls.Add(ButtonCreateSecondMonorail); - Controls.Add(buttonStep); - Controls.Add(comboBoxStrategy); - Controls.Add(buttonLeft); - Controls.Add(buttonDown); - Controls.Add(buttonRight); - Controls.Add(buttonUp); - Controls.Add(pictureBoxMonorail); - Name = "Form1"; - Text = "Form1"; - ((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).EndInit(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private PictureBox pictureBoxMonorail; - private Button buttonLeft; - private Button buttonDown; - private Button buttonRight; - private Button buttonUp; - private ComboBox comboBoxStrategy; - private Button buttonStep; - private Button ButtonCreateSecondMonorail; - private Button ButtonCreateMonorail; - } -} \ No newline at end of file diff --git a/MonorailProject/MonorailProject/Form1.cs b/MonorailProject/MonorailProject/Form1.cs deleted file mode 100644 index 99dd38f..0000000 --- a/MonorailProject/MonorailProject/Form1.cs +++ /dev/null @@ -1,113 +0,0 @@ -using MonorailProject.DrawningObjects; -using MonorailProject.MovementStrategy; -namespace MonorailProject -{ - public partial class Form1 : Form - { - private DrawningMonorail? _drawningMonorail; - private AbstractStrategy? _abstractStrategy; - public Form1() - { - InitializeComponent(); - } - private void Draw() - { - if (_drawningMonorail == null) - { - return; - } - - Bitmap bmp = new(pictureBoxMonorail.Width, - pictureBoxMonorail.Height); - Graphics gr = Graphics.FromImage(bmp); - _drawningMonorail.DrawTransport(gr); - pictureBoxMonorail.Image = bmp; - } - private void ButtonCreateSecondMonorail_Click(object sender, EventArgs e) - { - Random random = new(); - - _drawningMonorail = new DrawningSecondMonorail(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)), - true, true, - pictureBoxMonorail.Width, pictureBoxMonorail.Height); - _drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, - 100)); - Draw(); - } - private void ButtonCreateMonorail_Click(object sender, EventArgs e) - { - Random random = new(); - _drawningMonorail = new DrawningMonorail(random.Next(100, 300), - random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), pictureBoxMonorail.Width, pictureBoxMonorail.Height); - _drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); - } - private void ButtonMove_Click(object sender, EventArgs e) - { - if (_drawningMonorail == null) - { - return; - } - string name = ((Button)sender)?.Name ?? string.Empty; - switch (name) - { - case "buttonUp": - _drawningMonorail.MoveTransport(DirectionType.Up); - break; - case "buttonDown": - _drawningMonorail.MoveTransport(DirectionType.Down); - break; - case "buttonLeft": - _drawningMonorail.MoveTransport(DirectionType.Left); - break; - case "buttonRight": - _drawningMonorail.MoveTransport(DirectionType.Right); - break; - } - Draw(); - } - private void ButtonStep_Click(object sender, EventArgs e) - { - if (_drawningMonorail == null) - { - return; - } - if (comboBoxStrategy.Enabled) - { - _abstractStrategy = comboBoxStrategy.SelectedIndex - switch - { - 0 => new MoveToCenter(), - 1 => new MoveToBorder(), - _ => null, - }; - if (_abstractStrategy == null) - { - return; - } - _abstractStrategy.SetData(new - DrawningObjectMonorail(_drawningMonorail), pictureBoxMonorail.Width, - pictureBoxMonorail.Height); - //comboBoxStrategy.Enabled = false; - } - if (_abstractStrategy == null) - { - return; - } - _abstractStrategy.MakeStep(); - Draw(); - if (_abstractStrategy.GetStatus() == Status.Finish) - { - comboBoxStrategy.Enabled = true; - _abstractStrategy = null; - } - - } - } -} \ No newline at end of file diff --git a/MonorailProject/MonorailProject/Form1.resx b/MonorailProject/MonorailProject/Form1.resx deleted file mode 100644 index a395bff..0000000 --- a/MonorailProject/MonorailProject/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/MonorailProject/MonorailProject/MonorailProject.csproj b/MonorailProject/MonorailProject/MonorailProject.csproj deleted file mode 100644 index 13ee123..0000000 --- a/MonorailProject/MonorailProject/MonorailProject.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - - - True - True - Resources.resx - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - \ No newline at end of file diff --git a/MonorailProject/MonorailProject/MovementStrategy/AbstractStrategy.cs b/MonorailProject/MonorailProject/MovementStrategy/AbstractStrategy.cs deleted file mode 100644 index 1ff1d8e..0000000 --- a/MonorailProject/MonorailProject/MovementStrategy/AbstractStrategy.cs +++ /dev/null @@ -1,73 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonorailProject.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/MonorailProject/MonorailProject/MovementStrategy/DrawningObjectMonorail.cs b/MonorailProject/MonorailProject/MovementStrategy/DrawningObjectMonorail.cs deleted file mode 100644 index 860c68a..0000000 --- a/MonorailProject/MonorailProject/MovementStrategy/DrawningObjectMonorail.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MonorailProject.DrawningObjects; - -namespace MonorailProject.MovementStrategy -{ - public class DrawningObjectMonorail : IMoveableObject - { - private readonly DrawningMonorail? _drawningMonorail = null; - public DrawningObjectMonorail(DrawningMonorail drawningMonorail) - { - _drawningMonorail = drawningMonorail; - } - public ObjectParameters? GetObjectPosition - { - get - { - if (_drawningMonorail == null || _drawningMonorail.EntityMonorail == - null) - { - return null; - } - return new ObjectParameters(_drawningMonorail.GetPosX, - _drawningMonorail.GetPosY, _drawningMonorail.GetWidth, _drawningMonorail.GetHeight); - } - } - public int GetStep => (int)(_drawningMonorail?.EntityMonorail?.Step ?? 0); - public bool CheckCanMove(DirectionType direction) => - _drawningMonorail?.CanMove(direction) ?? false; - public void MoveObject(DirectionType direction) => - _drawningMonorail?.MoveTransport(direction); - } - -} diff --git a/MonorailProject/MonorailProject/MovementStrategy/IMoveableObject.cs b/MonorailProject/MonorailProject/MovementStrategy/IMoveableObject.cs deleted file mode 100644 index faa67a4..0000000 --- a/MonorailProject/MonorailProject/MovementStrategy/IMoveableObject.cs +++ /dev/null @@ -1,17 +0,0 @@ -using MonorailProject.MovementStrategy; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonorailProject.MovementStrategy -{ - public interface IMoveableObject - { - ObjectParameters? GetObjectPosition { get; } - int GetStep { get; } - bool CheckCanMove(DirectionType direction); - void MoveObject(DirectionType direction); - } -} diff --git a/MonorailProject/MonorailProject/MovementStrategy/MoveToBorder.cs b/MonorailProject/MonorailProject/MovementStrategy/MoveToBorder.cs deleted file mode 100644 index 0b0998c..0000000 --- a/MonorailProject/MonorailProject/MovementStrategy/MoveToBorder.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonorailProject.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/MonorailProject/MonorailProject/MovementStrategy/MoveToCenter.cs b/MonorailProject/MonorailProject/MovementStrategy/MoveToCenter.cs deleted file mode 100644 index 857c1a1..0000000 --- a/MonorailProject/MonorailProject/MovementStrategy/MoveToCenter.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonorailProject.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/MonorailProject/MonorailProject/MovementStrategy/ObjectParameters.cs b/MonorailProject/MonorailProject/MovementStrategy/ObjectParameters.cs deleted file mode 100644 index 224012b..0000000 --- a/MonorailProject/MonorailProject/MovementStrategy/ObjectParameters.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonorailProject.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/MonorailProject/MonorailProject/MovementStrategy/Status.cs b/MonorailProject/MonorailProject/MovementStrategy/Status.cs deleted file mode 100644 index 190029c..0000000 --- a/MonorailProject/MonorailProject/MovementStrategy/Status.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonorailProject.MovementStrategy -{ - public enum Status - { - NotInit, - InProgress, - Finish - } - -} diff --git a/MonorailProject/MonorailProject/Program.cs b/MonorailProject/MonorailProject/Program.cs deleted file mode 100644 index a0a7472..0000000 --- a/MonorailProject/MonorailProject/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace MonorailProject -{ - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); - } - } -} \ No newline at end of file diff --git a/MonorailProject/MonorailProject/Properties/Resources.Designer.cs b/MonorailProject/MonorailProject/Properties/Resources.Designer.cs deleted file mode 100644 index 1d7c9f9..0000000 --- a/MonorailProject/MonorailProject/Properties/Resources.Designer.cs +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Этот код создан программой. -// Исполняемая версия:4.0.30319.42000 -// -// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае -// повторной генерации кода. -// -//------------------------------------------------------------------------------ - -namespace MonorailProject.Properties { - using System; - - - /// - /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. - /// - // Этот класс создан автоматически классом StronglyTypedResourceBuilder - // с помощью такого средства, как ResGen или Visual Studio. - // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen - // с параметром /str или перестройте свой проект VS. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MonorailProject.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Перезаписывает свойство CurrentUICulture текущего потока для всех - /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Поиск локализованного ресурса типа System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap down_arrow { - get { - object obj = ResourceManager.GetObject("down-arrow", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Поиск локализованного ресурса типа System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap left_arrow { - get { - object obj = ResourceManager.GetObject("left-arrow", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Поиск локализованного ресурса типа System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap right_arrow { - get { - object obj = ResourceManager.GetObject("right-arrow", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Поиск локализованного ресурса типа System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap upper_arrow { - get { - object obj = ResourceManager.GetObject("upper-arrow", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - } -} diff --git a/MonorailProject/MonorailProject/Properties/Resources.resx b/MonorailProject/MonorailProject/Properties/Resources.resx deleted file mode 100644 index 44bb4fe..0000000 --- a/MonorailProject/MonorailProject/Properties/Resources.resx +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - - ..\Resources\down-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\right-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\upper-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\left-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - \ No newline at end of file diff --git a/MonorailProject/MonorailProject/Resources/down-arrow.png b/MonorailProject/MonorailProject/Resources/down-arrow.png deleted file mode 100644 index 9d67143363585e3432a1c1d203ab1b9c01976c50..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 281 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oArNM~bhqvgQ1G;; zi(^Q|oVQcGxehr9xZG!PJ=iKPkv~* zc9Kx^`?K)}4&8QsA++)Z=NaeL@TnCH#^;@Tgv2kJgjw7>ZYuCH(qz)4*DH2Ru$Mb* cz?1ZWvE`jXwNtr}CD2<8p00i_>zopr0H3RI6#xJL diff --git a/MonorailProject/MonorailProject/Resources/left-arrow.png b/MonorailProject/MonorailProject/Resources/left-arrow.png deleted file mode 100644 index 046470dd1579e2ce99e38e48677f93b995460f47..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 265 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oArNM~bhqvgP;j@W zi(^Q|oVU|#xtJVz+~TLPvK|zU=>9%IR50azvg(S67o|20$2W@PT-(3ZQ}D>v**$AM z9~3wt^4`$XaKfZXmnNm`XLx_4;d#{Y1DqBNvH2B@Ar5QPm(+f2is!A77T$Nb@L`vJ z!N<1uwhtDSGR)zvNq*OSE>?;q>{)3O*9}3RhUml3c6<6X?w%M??e!!o{lH-l9p`3y z&ohn7Cq`t%+o+y0?@ZL`y>m)cVfjVm7Hdm6Pg#bRdv?g zo_d7i&cBX%-Up_*C#c3a-842yRoo=xRhZ?*{Ndc)p1PG@KZIFQcRaRubCl_?gn{+W T1E1yqUB}?*>gTe~DWM4frWsJb diff --git a/MonorailProject/MonorailProject/Resources/upper-arrow.png b/MonorailProject/MonorailProject/Resources/upper-arrow.png deleted file mode 100644 index 0bc323d4a84a7434e950a34a05d6b0cd4e0a1c26..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 264 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oArNM~bhqvgP;i&0 zi(^Q|oVQbbxegf!xW#)r9MrC8xaTY)c*L7CcFT3a^G|}xyX^1!D7K_1`USOA8kl%4 zuawtak|5Fc@p(wlfHmbNxVQmhc^IrFsVWmFgSL${tdEQr8i?PC!r5 z-mCYs_=f9zf$C58UcX%ZI{$%y&F{@MtaofZ#Vy%)J(#?rbq3?~4jUeUwjGSzQ!Gv{ z%T?&_jecpHJ#SL+0#A Date: Fri, 20 Oct 2023 21:00:08 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=20=E2=84=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Monorail/Monorail/DrawningMonorail.cs | 204 ------------------ .../DrawningObjects/DrawningMonorail.cs | 156 ++++++++++++++ .../DrawningObjects/DrawningSecondMonorail.cs | 100 +++++++++ Monorail/Monorail/Entities/EntityMonorail.cs | 22 ++ .../Monorail/Entities/EntitySecondMonorail.cs | 22 ++ Monorail/Monorail/Entity.cs | 29 --- Monorail/Monorail/Form1.Designer.cs | 93 +++++--- Monorail/Monorail/Form1.cs | 78 +++++-- .../MovementStrategy/AbstractStrategy.cs | 72 +++++++ .../DrawningObjectMonorail.cs | 36 ++++ .../MovementStrategy/IMoveableObject.cs | 16 ++ .../Monorail/MovementStrategy/MoveToBorder.cs | 56 +++++ .../Monorail/MovementStrategy/MoveToCenter.cs | 56 +++++ .../MovementStrategy/ObjectParameters.cs | 29 +++ Monorail/Monorail/MovementStrategy/Status.cs | 15 ++ 15 files changed, 712 insertions(+), 272 deletions(-) delete mode 100644 Monorail/Monorail/DrawningMonorail.cs create mode 100644 Monorail/Monorail/DrawningObjects/DrawningMonorail.cs create mode 100644 Monorail/Monorail/DrawningObjects/DrawningSecondMonorail.cs create mode 100644 Monorail/Monorail/Entities/EntityMonorail.cs create mode 100644 Monorail/Monorail/Entities/EntitySecondMonorail.cs delete mode 100644 Monorail/Monorail/Entity.cs create mode 100644 Monorail/Monorail/MovementStrategy/AbstractStrategy.cs create mode 100644 Monorail/Monorail/MovementStrategy/DrawningObjectMonorail.cs create mode 100644 Monorail/Monorail/MovementStrategy/IMoveableObject.cs create mode 100644 Monorail/Monorail/MovementStrategy/MoveToBorder.cs create mode 100644 Monorail/Monorail/MovementStrategy/MoveToCenter.cs create mode 100644 Monorail/Monorail/MovementStrategy/ObjectParameters.cs create mode 100644 Monorail/Monorail/MovementStrategy/Status.cs diff --git a/Monorail/Monorail/DrawningMonorail.cs b/Monorail/Monorail/DrawningMonorail.cs deleted file mode 100644 index 55f9f45..0000000 --- a/Monorail/Monorail/DrawningMonorail.cs +++ /dev/null @@ -1,204 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Monorail -{ - public class DrawningMonorail - { - public Entity? Entity { get; private set; } - - private int _pictureWidth; - private int _pictureHeight; - private int _startPosX; - private int _startPosY; - private int _relWidth = 150; - private readonly int _relHeight = 46; - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, - bool monorails, bool secondCabin, int width, int height) - { - if (0 + _relWidth >= width || 0 + _relHeight >= height) - { - return false; - } - _pictureWidth = width; - _pictureHeight = height; - Entity = new Entity(); - Entity.Init(speed, weight, bodyColor, additionalColor, monorails, secondCabin); - return true; - } - public void SetPosition(int x, int y) - { - if (x < 0 || x > _pictureWidth - _relWidth) - { - x = 0; - } - if (y < 0 || y > _pictureHeight - _relHeight) - { - y = 0; - } - _startPosX = x; - _startPosY = y; - } - public void MoveTransport(DirectionType direction) - { - if (Entity == null) - { - return; - } - switch (direction) - { - case DirectionType.Left: - if (_startPosX - Entity.Step > 0) - { - _startPosX -= (int)Entity.Step; - } - break; - case DirectionType.Right: - if (_startPosX + (int)Entity.Step < _pictureWidth - _relWidth) - { - _startPosX += (int)Entity.Step; - } - break; - case DirectionType.Up: - if (_startPosY - Entity.Step > 0) - { - _startPosY -= (int)Entity.Step; - } - break; - case DirectionType.Down: - if (_startPosY + Entity.Step < _pictureHeight - _relHeight) - { - _startPosY += (int)Entity.Step; - } - break; - } - } - - public void DrawMonorail(Graphics g) - { - if (Entity == null) - { - return; - } - _relWidth = 150; - Pen pen = new(Color.Black, 2); - Brush additionalBrush = new SolidBrush(Entity.AdditionalColor); - Brush bodyBrush = new SolidBrush(Entity.BodyColor); - //колёса - - g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 50, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 110, _startPosY + 35, 15, 15); - g.DrawRectangle(pen, _startPosX + 22, _startPosY + 36, 40, 8); - g.DrawRectangle(pen, _startPosX + 82, _startPosY + 36, 40, 8); - g.DrawEllipse(pen, _startPosX + 3, _startPosY + 37, 30, 8); - g.DrawEllipse(pen, _startPosX + 110, _startPosY + 37, 29, 8); - - Brush brBlack = new SolidBrush(Color.Black); - g.FillRectangle(brBlack, _startPosX + 22, _startPosY + 36, 40, 8); - g.FillRectangle(brBlack, _startPosX + 82, _startPosY + 36, 40, 8); - g.FillEllipse(brBlack, _startPosX + 3, _startPosY + 37, 30, 8); - g.FillEllipse(brBlack, _startPosX + 110, _startPosY + 37, 29, 8); - - Brush brWhite = new SolidBrush(Color.White); - g.FillEllipse(brWhite, _startPosX + 20, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 50, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 80, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 110, _startPosY + 35, 15, 15); - - //Кабина - - g.DrawRectangle(pen, _startPosX + 10, _startPosY + 20, 120, 16); - g.FillRectangle(bodyBrush, _startPosX + 10, _startPosY + 20, 120, 16); - Point p1 = new Point(_startPosX + 10, _startPosY + 20); - Point p2 = new Point(_startPosX + 130, _startPosY + 20); - Point p3 = new Point(_startPosX + 130, _startPosY + 5); - Point p4 = new Point(_startPosX + 13, _startPosY + 5); - - g.DrawPolygon(pen, new Point[] { p1, p2, p3, p4 }); - g.FillPolygon(bodyBrush, new Point[] { p1, p2, p3, p4 }); - - - //дверь - g.FillRectangle(brWhite, _startPosX + 49, _startPosY + 9, 12, 22); - g.DrawRectangle(pen, _startPosX + 49, _startPosY + 9, 12, 22); - - //Окна и прочее - - Pen penBlue = new Pen(Color.Cyan, 2); - g.DrawRectangle(penBlue, _startPosX + 20, _startPosY + 8, 10, 10); - g.DrawRectangle(penBlue, _startPosX + 35, _startPosY + 8, 10, 10); - g.DrawRectangle(penBlue, _startPosX + 117, _startPosY + 8, 10, 10); - - g.DrawRectangle(pen, _startPosX + 132, _startPosY + 10, 2, 22); - - //Магнитная рельса - - if (Entity.Monorails == true) - { - g.DrawRectangle(pen, _startPosX, _startPosY + 50, 140, 10); - g.FillRectangle(brBlack, _startPosX, _startPosY + 50, 140, 10); - - g.FillRectangle(brWhite, _startPosX + 5, _startPosY + 53, 130, 5); - } - - if (Entity.SecondCabin == true) - { - _relWidth = 290; - //низ - g.DrawEllipse(pen, _startPosX + 160, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 190, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 220, _startPosY + 35, 15, 15); - g.DrawEllipse(pen, _startPosX + 250, _startPosY + 35, 15, 15); - g.DrawRectangle(pen, _startPosX + 162, _startPosY + 36, 40, 8); - g.DrawRectangle(pen, _startPosX + 222, _startPosY + 36, 40, 8); - g.DrawEllipse(pen, _startPosX + 143, _startPosY + 37, 30, 8); - g.DrawEllipse(pen, _startPosX + 250, _startPosY + 37, 29, 8); - - g.FillRectangle(brBlack, _startPosX + 162, _startPosY + 36, 40, 8); - g.FillRectangle(brBlack, _startPosX + 222, _startPosY + 36, 40, 8); - g.FillEllipse(brBlack, _startPosX + 143, _startPosY + 37, 30, 8); - g.FillEllipse(brBlack, _startPosX + 250, _startPosY + 37, 29, 8); - - g.FillEllipse(brWhite, _startPosX + 160, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 190, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 220, _startPosY + 35, 15, 15); - g.FillEllipse(brWhite, _startPosX + 250, _startPosY + 35, 15, 15); - - if (Entity.Monorails == true) - { - g.DrawRectangle(pen, _startPosX + 140, _startPosY + 50, 145, 10); - g.FillRectangle(brBlack, _startPosX + 140, _startPosY + 50, 145, 10); - - g.FillRectangle(brWhite, _startPosX + 135, _startPosY + 53, 145, 5); - } - - //Кабина - g.DrawRectangle(pen, _startPosX + 150, _startPosY + 20, 120, 16); - g.FillRectangle(additionalBrush, _startPosX + 150, _startPosY + 20, 120, 16); - Point p5 = new Point(_startPosX + 150, _startPosY + 20); - Point p6 = new Point(_startPosX + 270, _startPosY + 20); - Point p7 = new Point(_startPosX + 267, _startPosY + 5); - Point p8 = new Point(_startPosX + 150, _startPosY + 5); - - g.DrawPolygon(pen, new Point[] { p5, p6, p7, p8 }); - g.FillPolygon(additionalBrush, new Point[] { p5, p6, p7, p8 }); - - //дверь - g.FillRectangle(brWhite, _startPosX + 189, _startPosY + 9, 12, 22); - g.DrawRectangle(pen, _startPosX + 189, _startPosY + 9, 12, 22); - - //Окна и прочее - g.DrawRectangle(penBlue, _startPosX + 160, _startPosY + 8, 10, 10); - g.DrawRectangle(penBlue, _startPosX + 175, _startPosY + 8, 10, 10); - g.DrawRectangle(penBlue, _startPosX + 257, _startPosY + 8, 10, 10); - - g.DrawRectangle(pen, _startPosX + 272, _startPosY + 10, 2, 22); - } - } - } -} diff --git a/Monorail/Monorail/DrawningObjects/DrawningMonorail.cs b/Monorail/Monorail/DrawningObjects/DrawningMonorail.cs new file mode 100644 index 0000000..4375cc0 --- /dev/null +++ b/Monorail/Monorail/DrawningObjects/DrawningMonorail.cs @@ -0,0 +1,156 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Monorail.Entities; + +namespace Monorail.DrawningObjects +{ + public class DrawningMonorail + { + public EntityMonorail? EntityMonorail { get; protected set; } + private int _pictureWidth; + private int _pictureHeight; + protected int _startPosX; + protected int _startPosY; + protected int _relWidth = 150; + protected readonly int _relHeight = 46; + public DrawningMonorail(int speed, double weight, Color bodyColor, int width, int height) + { + if (_relWidth >= width || _relHeight >= height) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + EntityMonorail = new EntityMonorail(speed, weight, bodyColor); + } + protected DrawningMonorail(int speed, double weight, Color bodyColor, int width, + int height, int carWidth, int carHeight) + { + if (_relWidth >= width || _relHeight >= height) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + _relWidth = carWidth; + _relHeight = carHeight; + EntityMonorail = new EntityMonorail(speed, weight, bodyColor); + } + + public void SetPosition(int x, int y) + { + if (x < 0 || x > _pictureWidth - _relWidth) + { + x = 0; + } + if (y < 0 || y > _pictureHeight - _relHeight) + { + y = 0; + } + _startPosX = x; + _startPosY = y; + } + public void MoveTransport(DirectionType direction) + { + if (!CanMove(direction) || EntityMonorail == null) + { + return; + } + switch (direction) + { + case DirectionType.Left: + _startPosX -= (int)EntityMonorail.Step; + break; + case DirectionType.Right: + _startPosX += (int)EntityMonorail.Step; + break; + case DirectionType.Up: + _startPosY -= (int)EntityMonorail.Step; + break; + case DirectionType.Down: + _startPosY += (int)EntityMonorail.Step; + break; + } + } + public int GetPosX => _startPosX; + public int GetPosY => _startPosY; + public int GetWidth => _relWidth; + public int GetHeight => _relHeight; + public bool CanMove(DirectionType direction) + { + if (EntityMonorail == null) + { + return false; + } + return direction switch + { + DirectionType.Left => _startPosX - EntityMonorail.Step > 0, + DirectionType.Up => _startPosY - EntityMonorail.Step > 0, + DirectionType.Right => _startPosX + EntityMonorail.Step < _pictureWidth - _relWidth, + DirectionType.Down => _startPosY + EntityMonorail.Step < _pictureHeight - _relHeight + }; + } + + public virtual void DrawTransport(Graphics g) + { + if (EntityMonorail == null) + { + return; + } + _relWidth = 150; + Pen pen = new(Color.Black, 2); + Brush bodyBrush = new SolidBrush(EntityMonorail.BodyColor); + //колёса + + g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 50, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 110, _startPosY + 35, 15, 15); + g.DrawRectangle(pen, _startPosX + 22, _startPosY + 36, 40, 8); + g.DrawRectangle(pen, _startPosX + 82, _startPosY + 36, 40, 8); + g.DrawEllipse(pen, _startPosX + 3, _startPosY + 37, 30, 8); + g.DrawEllipse(pen, _startPosX + 110, _startPosY + 37, 29, 8); + + Brush brBlack = new SolidBrush(Color.Black); + g.FillRectangle(brBlack, _startPosX + 22, _startPosY + 36, 40, 8); + g.FillRectangle(brBlack, _startPosX + 82, _startPosY + 36, 40, 8); + g.FillEllipse(brBlack, _startPosX + 3, _startPosY + 37, 30, 8); + g.FillEllipse(brBlack, _startPosX + 110, _startPosY + 37, 29, 8); + + Brush brWhite = new SolidBrush(Color.White); + g.FillEllipse(brWhite, _startPosX + 20, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 50, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 80, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 110, _startPosY + 35, 15, 15); + + //Кабина + + g.DrawRectangle(pen, _startPosX + 10, _startPosY + 20, 120, 16); + g.FillRectangle(bodyBrush, _startPosX + 10, _startPosY + 20, 120, 16); + Point p1 = new Point(_startPosX + 10, _startPosY + 20); + Point p2 = new Point(_startPosX + 130, _startPosY + 20); + Point p3 = new Point(_startPosX + 130, _startPosY + 5); + Point p4 = new Point(_startPosX + 13, _startPosY + 5); + + g.DrawPolygon(pen, new Point[] { p1, p2, p3, p4 }); + g.FillPolygon(bodyBrush, new Point[] { p1, p2, p3, p4 }); + + + //дверь + g.FillRectangle(brWhite, _startPosX + 49, _startPosY + 9, 12, 22); + g.DrawRectangle(pen, _startPosX + 49, _startPosY + 9, 12, 22); + + //Окна и прочее + + Pen penBlue = new Pen(Color.Cyan, 2); + g.DrawRectangle(penBlue, _startPosX + 20, _startPosY + 8, 10, 10); + g.DrawRectangle(penBlue, _startPosX + 35, _startPosY + 8, 10, 10); + g.DrawRectangle(penBlue, _startPosX + 117, _startPosY + 8, 10, 10); + + g.DrawRectangle(pen, _startPosX + 132, _startPosY + 10, 2, 22); + } + } +} \ No newline at end of file diff --git a/Monorail/Monorail/DrawningObjects/DrawningSecondMonorail.cs b/Monorail/Monorail/DrawningObjects/DrawningSecondMonorail.cs new file mode 100644 index 0000000..f9ad40d --- /dev/null +++ b/Monorail/Monorail/DrawningObjects/DrawningSecondMonorail.cs @@ -0,0 +1,100 @@ +using Monorail.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.DrawningObjects +{ + public class DrawningSecondMonorail : DrawningMonorail + { + public DrawningSecondMonorail(int speed, double weight, Color bodyColor, Color +additionalColor, bool monorails, bool secondCabin, int width, int height) : + base(speed, weight, bodyColor, width, height, 110, 60) + { + if (EntityMonorail != null) + { + EntityMonorail = new EntitySecondMonorail(speed, weight, bodyColor, + additionalColor, monorails, secondCabin); + } + } + public override void DrawTransport(Graphics g) + { + base.DrawTransport(g); + + if (EntityMonorail is not EntitySecondMonorail secondMonorail) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(secondMonorail.AdditionalColor); + Brush brBlack = new SolidBrush(Color.Black); + Brush brWhite = new SolidBrush(Color.White); + Pen penBlue = new Pen(Color.Cyan, 2); + + if (secondMonorail.Monorails) + { + g.DrawRectangle(pen, _startPosX, _startPosY + 50, 140, 10); + g.FillRectangle(brBlack, _startPosX, _startPosY + 50, 140, 10); + + g.FillRectangle(brWhite, _startPosX + 5, _startPosY + 53, 130, 5); + } + + if (secondMonorail.SecondCabin) + { + _relWidth = 290; + //низ + g.DrawEllipse(pen, _startPosX + 160, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 190, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 220, _startPosY + 35, 15, 15); + g.DrawEllipse(pen, _startPosX + 250, _startPosY + 35, 15, 15); + g.DrawRectangle(pen, _startPosX + 162, _startPosY + 36, 40, 8); + g.DrawRectangle(pen, _startPosX + 222, _startPosY + 36, 40, 8); + g.DrawEllipse(pen, _startPosX + 143, _startPosY + 37, 30, 8); + g.DrawEllipse(pen, _startPosX + 250, _startPosY + 37, 29, 8); + + g.FillRectangle(brBlack, _startPosX + 162, _startPosY + 36, 40, 8); + g.FillRectangle(brBlack, _startPosX + 222, _startPosY + 36, 40, 8); + g.FillEllipse(brBlack, _startPosX + 143, _startPosY + 37, 30, 8); + g.FillEllipse(brBlack, _startPosX + 250, _startPosY + 37, 29, 8); + + g.FillEllipse(brWhite, _startPosX + 160, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 190, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 220, _startPosY + 35, 15, 15); + g.FillEllipse(brWhite, _startPosX + 250, _startPosY + 35, 15, 15); + + if (secondMonorail.Monorails) + { + g.DrawRectangle(pen, _startPosX + 140, _startPosY + 50, 145, 10); + g.FillRectangle(brBlack, _startPosX + 140, _startPosY + 50, 145, 10); + + g.FillRectangle(brWhite, _startPosX + 135, _startPosY + 53, 145, 5); + } + + //Кабина + g.DrawRectangle(pen, _startPosX + 150, _startPosY + 20, 120, 16); + g.FillRectangle(additionalBrush, _startPosX + 150, _startPosY + 20, 120, 16); + Point p5 = new Point(_startPosX + 150, _startPosY + 20); + Point p6 = new Point(_startPosX + 270, _startPosY + 20); + Point p7 = new Point(_startPosX + 267, _startPosY + 5); + Point p8 = new Point(_startPosX + 150, _startPosY + 5); + + g.DrawPolygon(pen, new Point[] { p5, p6, p7, p8 }); + g.FillPolygon(additionalBrush, new Point[] { p5, p6, p7, p8 }); + + //дверь + g.FillRectangle(brWhite, _startPosX + 189, _startPosY + 9, 12, 22); + g.DrawRectangle(pen, _startPosX + 189, _startPosY + 9, 12, 22); + + //Окна и прочее + g.DrawRectangle(penBlue, _startPosX + 160, _startPosY + 8, 10, 10); + g.DrawRectangle(penBlue, _startPosX + 175, _startPosY + 8, 10, 10); + g.DrawRectangle(penBlue, _startPosX + 257, _startPosY + 8, 10, 10); + + g.DrawRectangle(pen, _startPosX + 272, _startPosY + 10, 2, 22); + } + } + } +} \ No newline at end of file diff --git a/Monorail/Monorail/Entities/EntityMonorail.cs b/Monorail/Monorail/Entities/EntityMonorail.cs new file mode 100644 index 0000000..f950820 --- /dev/null +++ b/Monorail/Monorail/Entities/EntityMonorail.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.Entities +{ + public class EntityMonorail + { + public int Speed { get; private set; } + public double Weight { get; private set; } + public Color BodyColor { get; private set; } + public double Step => (double)Speed * 130 / Weight; + public EntityMonorail(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } + } +} diff --git a/Monorail/Monorail/Entities/EntitySecondMonorail.cs b/Monorail/Monorail/Entities/EntitySecondMonorail.cs new file mode 100644 index 0000000..0b4f0e5 --- /dev/null +++ b/Monorail/Monorail/Entities/EntitySecondMonorail.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.Entities +{ + public class EntitySecondMonorail : EntityMonorail + { + public Color AdditionalColor { get; private set; } + public bool Monorails { get; private set; } + public bool SecondCabin { get; private set; } + public EntitySecondMonorail(int speed, double weight, Color bodyColor, + Color additionalColor, bool monorails, bool secondCabin) : base(speed, weight, bodyColor) + { + AdditionalColor = additionalColor; + Monorails = monorails; + SecondCabin = secondCabin; + } + } +} diff --git a/Monorail/Monorail/Entity.cs b/Monorail/Monorail/Entity.cs deleted file mode 100644 index 65b2b85..0000000 --- a/Monorail/Monorail/Entity.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Monorail -{ - public class Entity - { - 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 Monorails { get; private set; } - public bool SecondCabin { get; private set; } - public double Step => (double)Speed * 130 / Weight; - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, - bool monorails, bool secondCabin) - { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; - AdditionalColor = additionalColor; - Monorails = monorails; - SecondCabin = secondCabin; - } - } -} diff --git a/Monorail/Monorail/Form1.Designer.cs b/Monorail/Monorail/Form1.Designer.cs index 606c4b6..4c002a3 100644 --- a/Monorail/Monorail/Form1.Designer.cs +++ b/Monorail/Monorail/Form1.Designer.cs @@ -28,24 +28,27 @@ /// private void InitializeComponent() { - pictureBox1 = new PictureBox(); + pictureBoxMonorail = new PictureBox(); buttonUp = new Button(); buttonLeft = new Button(); buttonDown = new Button(); buttonRight = new Button(); - buttonCreate = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); + ButtonCreateMonorail = new Button(); + ButtonCreateSecondMonorail = new Button(); + buttonStep = new Button(); + comboBoxStrategy = new ComboBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit(); SuspendLayout(); // - // pictureBox1 + // pictureBoxMonorail // - pictureBox1.Dock = DockStyle.Fill; - pictureBox1.Location = new Point(0, 0); - pictureBox1.Name = "pictureBox1"; - pictureBox1.Size = new Size(882, 453); - pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; - pictureBox1.TabIndex = 1; - pictureBox1.TabStop = false; + pictureBoxMonorail.Dock = DockStyle.Fill; + pictureBoxMonorail.Location = new Point(0, 0); + pictureBoxMonorail.Name = "pictureBoxMonorail"; + pictureBoxMonorail.Size = new Size(882, 453); + pictureBoxMonorail.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxMonorail.TabIndex = 1; + pictureBoxMonorail.TabStop = false; // // buttonUp // @@ -99,17 +102,49 @@ buttonRight.UseVisualStyleBackColor = false; buttonRight.Click += buttonMove_Click; // - // buttonCreate + // ButtonCreateMonorail // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.BackColor = SystemColors.Info; - buttonCreate.Location = new Point(12, 412); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(77, 29); - buttonCreate.TabIndex = 7; - buttonCreate.Text = "Создать"; - buttonCreate.UseVisualStyleBackColor = false; - buttonCreate.Click += buttonCreate_Click; + ButtonCreateMonorail.BackColor = SystemColors.Info; + ButtonCreateMonorail.Location = new Point(9, 400); + ButtonCreateMonorail.Name = "ButtonCreateMonorail"; + ButtonCreateMonorail.Size = new Size(175, 41); + ButtonCreateMonorail.TabIndex = 22; + ButtonCreateMonorail.Text = "Создать Монорельс"; + ButtonCreateMonorail.UseVisualStyleBackColor = false; + ButtonCreateMonorail.Click += ButtonCreateMonorail_Click; + // + // ButtonCreateSecondMonorail + // + ButtonCreateSecondMonorail.BackColor = SystemColors.Info; + ButtonCreateSecondMonorail.Location = new Point(202, 400); + ButtonCreateSecondMonorail.Name = "ButtonCreateSecondMonorail"; + ButtonCreateSecondMonorail.Size = new Size(239, 41); + ButtonCreateSecondMonorail.TabIndex = 21; + ButtonCreateSecondMonorail.Text = "Создать два Монорельса"; + ButtonCreateSecondMonorail.UseVisualStyleBackColor = false; + ButtonCreateSecondMonorail.Click += ButtonCreateSecondMonorail_Click; + // + // buttonStep + // + buttonStep.BackColor = SystemColors.Info; + buttonStep.Location = new Point(782, 43); + buttonStep.Name = "buttonStep"; + buttonStep.Size = new Size(94, 29); + buttonStep.TabIndex = 20; + buttonStep.Text = "Шаг"; + buttonStep.UseVisualStyleBackColor = false; + buttonStep.Click += ButtonStep_Click; + // + // comboBoxStrategy + // + comboBoxStrategy.BackColor = SystemColors.Info; + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "0", "1" }); + comboBoxStrategy.Location = new Point(725, 9); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(151, 28); + comboBoxStrategy.TabIndex = 19; // // MonoRail // @@ -117,27 +152,33 @@ AutoScaleMode = AutoScaleMode.Font; BackColor = SystemColors.ControlDarkDark; ClientSize = new Size(882, 453); + Controls.Add(ButtonCreateMonorail); + Controls.Add(ButtonCreateSecondMonorail); + Controls.Add(buttonStep); + Controls.Add(comboBoxStrategy); Controls.Add(buttonLeft); Controls.Add(buttonDown); Controls.Add(buttonRight); - Controls.Add(buttonCreate); Controls.Add(buttonUp); - Controls.Add(pictureBox1); + Controls.Add(pictureBoxMonorail); Name = "MonoRail"; StartPosition = FormStartPosition.CenterScreen; Text = "Monorail"; - ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).EndInit(); ResumeLayout(false); PerformLayout(); } #endregion - private PictureBox pictureBox1; + private PictureBox pictureBoxMonorail; private Button buttonUp; private Button buttonLeft; private Button buttonDown; private Button buttonRight; - private Button buttonCreate; + private Button ButtonCreateMonorail; + private Button ButtonCreateSecondMonorail; + private Button buttonStep; + private ComboBox comboBoxStrategy; } } \ No newline at end of file diff --git a/Monorail/Monorail/Form1.cs b/Monorail/Monorail/Form1.cs index fb14ce0..58f7888 100644 --- a/Monorail/Monorail/Form1.cs +++ b/Monorail/Monorail/Form1.cs @@ -1,9 +1,13 @@ +using Monorail.DrawningObjects; +using Monorail.MovementStrategy; + namespace Monorail { public partial class MonoRail : Form { private DrawningMonorail? _drawningMonorail; + private AbstractStrategy? _abstractStrategy; public MonoRail() { @@ -15,24 +19,36 @@ namespace Monorail { return; } - Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height); + Bitmap bmp = new(pictureBoxMonorail.Width, + pictureBoxMonorail.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningMonorail.DrawMonorail(gr); - pictureBox1.Image = bmp; + _drawningMonorail.DrawTransport(gr); + pictureBoxMonorail.Image = bmp; } - private void buttonCreate_Click(object sender, EventArgs e) + private void ButtonCreateSecondMonorail_Click(object sender, EventArgs e) { Random random = new(); - _drawningMonorail = new DrawningMonorail(); - _drawningMonorail.Init(random.Next(500, 800), 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); - _drawningMonorail.SetPosition(random.Next(10, 100), - random.Next(30, 100)); + + _drawningMonorail = new DrawningSecondMonorail(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)), + true, true, + pictureBoxMonorail.Width, pictureBoxMonorail.Height); + _drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, + 100)); + Draw(); + } + private void ButtonCreateMonorail_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningMonorail = new DrawningMonorail(random.Next(100, 300), + random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), pictureBoxMonorail.Width, pictureBoxMonorail.Height); + _drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void buttonMove_Click(object sender, EventArgs e) @@ -59,5 +75,41 @@ namespace Monorail } Draw(); } + private void ButtonStep_Click(object sender, EventArgs e) + { + if (_drawningMonorail == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _abstractStrategy = comboBoxStrategy.SelectedIndex + switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.SetData(new + DrawningObjectMonorail(_drawningMonorail), pictureBoxMonorail.Width, + pictureBoxMonorail.Height); + //comboBoxStrategy.Enabled = false; + } + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.MakeStep(); + Draw(); + if (_abstractStrategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.Enabled = true; + _abstractStrategy = null; + } + } } } \ No newline at end of file diff --git a/Monorail/Monorail/MovementStrategy/AbstractStrategy.cs b/Monorail/Monorail/MovementStrategy/AbstractStrategy.cs new file mode 100644 index 0000000..f9cf3d5 --- /dev/null +++ b/Monorail/Monorail/MovementStrategy/AbstractStrategy.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.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; + } + } +} \ No newline at end of file diff --git a/Monorail/Monorail/MovementStrategy/DrawningObjectMonorail.cs b/Monorail/Monorail/MovementStrategy/DrawningObjectMonorail.cs new file mode 100644 index 0000000..72eba2d --- /dev/null +++ b/Monorail/Monorail/MovementStrategy/DrawningObjectMonorail.cs @@ -0,0 +1,36 @@ +using Monorail.DrawningObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.MovementStrategy +{ + public class DrawningObjectMonorail :IMoveableObject + { + private readonly DrawningMonorail? _drawningMonorail = null; + public DrawningObjectMonorail(DrawningMonorail drawningMonorail) + { + _drawningMonorail = drawningMonorail; + } + public ObjectParameters? GetObjectPosition + { + get + { + if (_drawningMonorail == null || _drawningMonorail.EntityMonorail == + null) + { + return null; + } + return new ObjectParameters(_drawningMonorail.GetPosX, + _drawningMonorail.GetPosY, _drawningMonorail.GetWidth, _drawningMonorail.GetHeight); + } + } + public int GetStep => (int)(_drawningMonorail?.EntityMonorail?.Step ?? 0); + public bool CheckCanMove(DirectionType direction) => + _drawningMonorail?.CanMove(direction) ?? false; + public void MoveObject(DirectionType direction) => + _drawningMonorail?.MoveTransport(direction); + } +} \ No newline at end of file diff --git a/Monorail/Monorail/MovementStrategy/IMoveableObject.cs b/Monorail/Monorail/MovementStrategy/IMoveableObject.cs new file mode 100644 index 0000000..580a1f0 --- /dev/null +++ b/Monorail/Monorail/MovementStrategy/IMoveableObject.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.MovementStrategy +{ + public interface IMoveableObject + { + ObjectParameters? GetObjectPosition { get; } + int GetStep { get; } + bool CheckCanMove(DirectionType direction); + void MoveObject(DirectionType direction); + } +} diff --git a/Monorail/Monorail/MovementStrategy/MoveToBorder.cs b/Monorail/Monorail/MovementStrategy/MoveToBorder.cs new file mode 100644 index 0000000..de29e62 --- /dev/null +++ b/Monorail/Monorail/MovementStrategy/MoveToBorder.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.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/Monorail/Monorail/MovementStrategy/MoveToCenter.cs b/Monorail/Monorail/MovementStrategy/MoveToCenter.cs new file mode 100644 index 0000000..0cbb938 --- /dev/null +++ b/Monorail/Monorail/MovementStrategy/MoveToCenter.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.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/Monorail/Monorail/MovementStrategy/ObjectParameters.cs b/Monorail/Monorail/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..2ec34a2 --- /dev/null +++ b/Monorail/Monorail/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.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; + } + } +} \ No newline at end of file diff --git a/Monorail/Monorail/MovementStrategy/Status.cs b/Monorail/Monorail/MovementStrategy/Status.cs new file mode 100644 index 0000000..9acb04f --- /dev/null +++ b/Monorail/Monorail/MovementStrategy/Status.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Monorail.MovementStrategy +{ + public enum Status + { + NotInit, + InProgress, + Finish + } +} -- 2.25.1