diff --git a/DoubleDeckerBus/DoubleDeckerBus.sln b/DoubleDeckerBus/DoubleDeckerBus.sln new file mode 100644 index 0000000..5e4da88 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34024.191 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DoubleDeckerBus", "DoubleDeckerBus\DoubleDeckerBus.csproj", "{733E4772-39B5-4155-BB09-07F2025C8475}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {733E4772-39B5-4155-BB09-07F2025C8475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {733E4772-39B5-4155-BB09-07F2025C8475}.Debug|Any CPU.Build.0 = Debug|Any CPU + {733E4772-39B5-4155-BB09-07F2025C8475}.Release|Any CPU.ActiveCfg = Release|Any CPU + {733E4772-39B5-4155-BB09-07F2025C8475}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5A7B2FB1-2C70-4096-8533-3A0542E01030} + EndGlobalSection +EndGlobal diff --git a/DoubleDeckerBus/DoubleDeckerBus/DirectionBus.cs b/DoubleDeckerBus/DoubleDeckerBus/DirectionBus.cs new file mode 100644 index 0000000..07db3c8 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/DirectionBus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus +{ + public enum DirectionBus + { + None = 0, + Up = 1, + Down = 2, + Left = 3, + Right = 4 + } +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.Designer.cs b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.Designer.cs new file mode 100644 index 0000000..0c2e372 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.Designer.cs @@ -0,0 +1,181 @@ +namespace DoubleDeckerBus +{ + partial class DoubleDeckerBus + { + /// + /// 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() + { + pictureBoxBus = new PictureBox(); + buttonCreateBus = new Button(); + buttonUp = new Button(); + buttonLeft = new Button(); + buttonDown = new Button(); + buttonRight = new Button(); + buttonCreatDoubleDeckerDus = new Button(); + buttonStep_Click = new Button(); + comboBoxStrategy = new ComboBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxBus).BeginInit(); + SuspendLayout(); + // + // pictureBoxBus + // + pictureBoxBus.Dock = DockStyle.Fill; + pictureBoxBus.Location = new Point(0, 0); + pictureBoxBus.Name = "pictureBoxBus"; + pictureBoxBus.Size = new Size(884, 461); + pictureBoxBus.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxBus.TabIndex = 0; + pictureBoxBus.TabStop = false; + + // + // buttonCreateBus + // + buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateBus.Location = new Point(12, 409); + buttonCreateBus.Name = "buttonCreateBus"; + buttonCreateBus.Size = new Size(117, 40); + buttonCreateBus.TabIndex = 1; + buttonCreateBus.Text = "Создать автобус"; + buttonCreateBus.UseVisualStyleBackColor = true; + buttonCreateBus.Click += buttonCreateBus_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.arrowUp; + buttonUp.BackgroundImageLayout = ImageLayout.Zoom; + buttonUp.Location = new Point(806, 386); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(30, 30); + buttonUp.TabIndex = 2; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.AutoSizeChanged += ButtonMove_Click; + buttonUp.Click += ButtonMove_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; + buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; + buttonLeft.Location = new Point(770, 422); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(30, 30); + buttonLeft.TabIndex = 3; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.AutoSizeChanged += ButtonMove_Click; + buttonLeft.Click += ButtonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.arrowDown; + buttonDown.BackgroundImageLayout = ImageLayout.Zoom; + buttonDown.Location = new Point(806, 422); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(30, 30); + buttonDown.TabIndex = 4; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.AutoSizeChanged += ButtonMove_Click; + buttonDown.Click += ButtonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.arrowRight; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.Location = new Point(842, 422); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(30, 30); + buttonRight.TabIndex = 5; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.AutoSizeChanged += ButtonMove_Click; + buttonRight.Click += ButtonMove_Click; + // + // buttonCreatDoubleDeckerDus + // + buttonCreatDoubleDeckerDus.Location = new Point(135, 409); + buttonCreatDoubleDeckerDus.Name = "buttonCreatDoubleDeckerDus"; + buttonCreatDoubleDeckerDus.Size = new Size(136, 40); + buttonCreatDoubleDeckerDus.TabIndex = 6; + buttonCreatDoubleDeckerDus.Text = "Создать двухэтажный автобус"; + buttonCreatDoubleDeckerDus.UseVisualStyleBackColor = true; + buttonCreatDoubleDeckerDus.Click += buttonCreatDoubleDeckerDus_Click; + // + // buttonStep_Click + // + buttonStep_Click.Location = new Point(797, 41); + buttonStep_Click.Name = "buttonStep_Click"; + buttonStep_Click.Size = new Size(75, 23); + buttonStep_Click.TabIndex = 7; + buttonStep_Click.Text = "Шаг"; + buttonStep_Click.UseVisualStyleBackColor = true; + buttonStep_Click.Click += buttonStep_Click_Click; + // + // comboBoxStrategy + // + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" }); + comboBoxStrategy.Location = new Point(751, 12); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(121, 23); + comboBoxStrategy.TabIndex = 8; + // + // DoubleDeckerBus + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(884, 461); + Controls.Add(comboBoxStrategy); + Controls.Add(buttonStep_Click); + Controls.Add(buttonCreatDoubleDeckerDus); + Controls.Add(buttonRight); + Controls.Add(buttonDown); + Controls.Add(buttonLeft); + Controls.Add(buttonUp); + Controls.Add(buttonCreateBus); + Controls.Add(pictureBoxBus); + Name = "DoubleDeckerBus"; + StartPosition = FormStartPosition.CenterParent; + Text = "DoubleDeckerBus"; + ((System.ComponentModel.ISupportInitialize)pictureBoxBus).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxBus; + private Button buttonCreateBus; + private Button buttonUp; + private Button buttonLeft; + private Button buttonDown; + private Button buttonRight; + private Button buttonCreatDoubleDeckerDus; + private Button buttonStep_Click; + private ComboBox comboBoxStrategy; + } +} \ No newline at end of file diff --git a/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.cs b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.cs new file mode 100644 index 0000000..2d33c15 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.cs @@ -0,0 +1,118 @@ +using DoubleDeckerBus.DrawningObjects; +using DoubleDeckerBus.MovementStrategy; + +namespace DoubleDeckerBus +{ + public partial class DoubleDeckerBus : Form + { + private DrawningBus? _drawningBus; + private AbstractStrategy? _abstractStrategy; + public DoubleDeckerBus() + { + InitializeComponent(); + } + private void Draw() + { + if (_drawningBus == null) + { + return; + } + Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningBus.DrawTransport(gr); + pictureBoxBus.Image = bmp; + } + + private void buttonCreateBus_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningBus = new DrawningBus(random.Next(100, 300), + random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), + pictureBoxBus.Width, pictureBoxBus.Height); + _drawningBus.SetPosition(random.Next(10, 100), random.Next(10, + 100)); + Draw(); + } + + private void buttonCreatDoubleDeckerDus_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningBus = new DrawningDoubleDeckerBus(random.Next(100, 300), + random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), + pictureBoxBus.Width, pictureBoxBus.Height); + _drawningBus.SetPosition(random.Next(10, 100), random.Next(10, + 100)); + Draw(); + } + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningBus == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawningBus.MoveTransport(DirectionBus.Up); + break; + case "buttonDown": + _drawningBus.MoveTransport(DirectionBus.Down); + break; + case "buttonLeft": + _drawningBus.MoveTransport(DirectionBus.Left); + break; + case "buttonRight": + _drawningBus.MoveTransport(DirectionBus.Right); + break; + } + Draw(); + } + + private void buttonStep_Click_Click(object sender, EventArgs e) + { + if (_drawningBus == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _abstractStrategy = comboBoxStrategy.SelectedIndex + switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.SetData(new + DrawningObjectBus(_drawningBus), pictureBoxBus.Width, + pictureBoxBus.Height); + comboBoxStrategy.Enabled = false; + } + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.MakeStep(); + Draw(); + if (_abstractStrategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.Enabled = true; + _abstractStrategy = null; + } + } + } +} + diff --git a/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.csproj b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.resx b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.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/DoubleDeckerBus/DoubleDeckerBus/DrawningObjects/DrawningBus.cs b/DoubleDeckerBus/DoubleDeckerBus/DrawningObjects/DrawningBus.cs new file mode 100644 index 0000000..7940935 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/DrawningObjects/DrawningBus.cs @@ -0,0 +1,139 @@ +using DoubleDeckerBus.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.DrawningObjects +{ + public class DrawningBus + { + public EntityBus? EntityBus { get; protected set; } + private int? _pictureWidth; + private int? _pictureHeight; + protected int _startPosX; + protected int _startPosY; + protected readonly int _busWidth = 110; + protected readonly int _busHeight = 70; + public int GetPosX => _startPosX; + public int GetPosY => _startPosY; + public int GetWidth => _busWidth; + public int GetHeight => _busHeight; + public DrawningBus(int speed, float weight, Color bodyColor, int + width, int height) + { + if (width < _busWidth || height < _busHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + EntityBus = new EntityBus(speed, weight, bodyColor); + } + protected DrawningBus(int speed, float weight, Color bodyColor, int width, int height, int busWidth, int busHeight) + { + if (width <= _busWidth || height <= _busHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + _busWidth = busWidth; + _busHeight = busHeight; + EntityBus = new EntityBus(speed, weight, bodyColor); + } + public void SetPosition(int x, int y) + { + if (_pictureWidth <= _busWidth || _pictureHeight <= _busHeight) + { + _pictureWidth = null; + _pictureHeight = null; + return; + } + _startPosX = x; + _startPosY = y; + } + public bool CanMove(DirectionBus direction) + { + if (EntityBus == null) + { + return false; + } + return direction switch + { + //влево + DirectionBus.Left => _startPosX - EntityBus.Step > 0, + //вверх + DirectionBus.Up => _startPosY - EntityBus.Step > 0, + //вправо + DirectionBus.Right => _startPosX + _busWidth + EntityBus.Step < _pictureWidth, + //вниз + DirectionBus.Down => _startPosY + _busHeight + EntityBus.Step < _pictureHeight, + _ => false, + }; + } + public void MoveTransport(DirectionBus direction) + { + if (!CanMove(direction) || EntityBus == null) + { + return; + } + switch (direction) + { + //влево + case DirectionBus.Left: + _startPosX -= (int)EntityBus.Step; + break; + //вверх + case DirectionBus.Up: + _startPosY -= (int)EntityBus.Step; + break; + // вправо + case DirectionBus.Right: + _startPosX += (int)EntityBus.Step; + break; + //вниз + case DirectionBus.Down: + _startPosY += (int)EntityBus.Step; + break; + } + } + + public virtual void DrawTransport(Graphics g) + { + if (EntityBus == null) + { + return; + } + if (EntityBus == null) + { + return; + } + + Pen pen = new(Color.Black); + + + g.DrawRectangle(pen, _startPosX - 1, _startPosY + 11, 100, 30); + Brush brBodyColor = new SolidBrush(EntityBus.BodyColor); + g.FillRectangle(brBodyColor, _startPosX, _startPosY + 10, 100, 30); + + + g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20); + Brush brBlack = new SolidBrush(Color.Black); + g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20); + + + g.DrawEllipse(pen, _startPosX + 7, _startPosY + 35, 10, 10); + g.DrawEllipse(pen, _startPosX + 77, _startPosY + 35, 10, 10); + g.FillEllipse(brBlack, _startPosX + 7, _startPosY + 35, 10, 10); + g.FillEllipse(brBlack, _startPosX + 77, _startPosY + 35, 10, 10); + + Brush brBlue = new SolidBrush(Color.Blue); + g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15); + } + } +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/DrawningObjects/DrawningDoubleDeckerBus.cs b/DoubleDeckerBus/DoubleDeckerBus/DrawningObjects/DrawningDoubleDeckerBus.cs new file mode 100644 index 0000000..6a7cd3c --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/DrawningObjects/DrawningDoubleDeckerBus.cs @@ -0,0 +1,78 @@ +using DoubleDeckerBus.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Net.NetworkInformation; + +namespace DoubleDeckerBus.DrawningObjects +{ + public class DrawningDoubleDeckerBus : DrawningBus + { + public DrawningDoubleDeckerBus(int speed, float weight, Color bodyColor, + Color additionalColor, bool secondFloor, bool ladder, bool lineBetweenFloor, int width, int height) : + base(speed, weight, bodyColor, width, height, 120, 85) + { + + if (EntityBus != null) + { + EntityBus = new EntityDoubleDeckerBus(speed, weight, bodyColor, + additionalColor, secondFloor, ladder, lineBetweenFloor); + } + } + + public override void DrawTransport(Graphics g) + { + if (EntityBus is not EntityDoubleDeckerBus doubleDeckerBus) + { + return; + } + + Pen pen = new(Color.Black); + Brush brAdditionalColor = new SolidBrush(doubleDeckerBus.AdditionalColor); + Brush brBlue = new SolidBrush(Color.Blue); + Brush brBlack = new SolidBrush(Color.Black); + + if (doubleDeckerBus.SecondFloor) + { + g.FillRectangle(brAdditionalColor, _startPosX, _startPosY + 10, 100, 30); + + g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20); + g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20); + + g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15); + g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15); + } + + _startPosY += 30; + base.DrawTransport(g); + _startPosY -= 30; + + if (doubleDeckerBus.Ladder) + { + if (doubleDeckerBus.SecondFloor == true) + { + //Вертикальные прямые + g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 70)), new Point((int)(_startPosX), (int)(_startPosY + 10))); + g.DrawLine(pen, new Point((int)(_startPosX + 10), (int)(_startPosY + 70)), new Point((int)(_startPosX + 10), (int)(_startPosY + 10))); + + //Горизонтальные прямые + g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 20)), new Point((int)(_startPosX + 10), (int)(_startPosY + 20))); + g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 30)), new Point((int)(_startPosX + 10), (int)(_startPosY + 30))); + g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 40)), new Point((int)(_startPosX + 10), (int)(_startPosY + 40))); + g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 50)), new Point((int)(_startPosX + 10), (int)(_startPosY + 50))); + g.DrawLine(pen, new Point((int)(_startPosX), (int)(_startPosY + 60)), new Point((int)(_startPosX + 10), (int)(_startPosY + 60))); + } + } + + + } + } +} + + + + diff --git a/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityBus.cs b/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityBus.cs new file mode 100644 index 0000000..6e75501 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityBus.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.Entities +{ + public class EntityBus + { + 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 EntityBus(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } + } + +} + diff --git a/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityDoubleDeckerBus.cs b/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityDoubleDeckerBus.cs new file mode 100644 index 0000000..a762a85 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityDoubleDeckerBus.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.Entities +{ + public class EntityDoubleDeckerBus : EntityBus + { + public Color AdditionalColor { get; private set; } + public bool SecondFloor { get; private set; } + public bool Ladder { get; private set; } + public bool LineBetweenFloor { get; private set; } + public EntityDoubleDeckerBus(int speed, double weight, Color bodyColor, Color + additionalColor, bool secondFloor, bool ladder, bool lineBetweenFloor) : + base(speed, weight, bodyColor) + { + AdditionalColor = additionalColor; + SecondFloor = secondFloor; + Ladder = ladder; + LineBetweenFloor = lineBetweenFloor; + } + } + +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/AbstractStrategy.cs b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/AbstractStrategy.cs new file mode 100644 index 0000000..c2613cf --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/AbstractStrategy.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.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(DirectionBus.Left); + protected bool MoveRight() => MoveTo(DirectionBus.Right); + protected bool MoveUp() => MoveTo(DirectionBus.Up); + protected bool MoveDown() => MoveTo(DirectionBus.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(DirectionBus directionType) + { + if (_state != Status.InProgress) + { + return false; + } + if (_moveableObject?.CheckCanMove(directionType) ?? false) + { + _moveableObject.MoveObject(directionType); + return true; + } + return false; + } + } +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/DrawningObjectBus.cs b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/DrawningObjectBus.cs new file mode 100644 index 0000000..d81df87 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/DrawningObjectBus.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using DoubleDeckerBus.DrawningObjects; + +namespace DoubleDeckerBus.MovementStrategy +{ + public class DrawningObjectBus : IMoveableObject + { + private readonly DrawningBus? _drawningBus = null; + public DrawningObjectBus(DrawningBus drawningBus) + { + _drawningBus = drawningBus; + } + public ObjectParameters? GetObjectPosition + { + get + { + if (_drawningBus == null || _drawningBus.EntityBus == null) + { + return null; + } + return new ObjectParameters(_drawningBus.GetPosX, + _drawningBus.GetPosY, _drawningBus.GetWidth, _drawningBus.GetHeight); + } + } + + public int GetStep => (int)(_drawningBus?.EntityBus?.Step ?? 0); + + public bool CheckCanMove(DirectionBus direction) => + _drawningBus?.CanMove(direction) ?? false; + + public void MoveObject(DirectionBus direction) => + _drawningBus?.MoveTransport(direction); + } +} + diff --git a/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/IMoveableObject.cs b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/IMoveableObject.cs new file mode 100644 index 0000000..d116928 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/IMoveableObject.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.MovementStrategy +{ + public interface IMoveableObject + { + ObjectParameters? GetObjectPosition { get; } + int GetStep { get; } + bool CheckCanMove(DirectionBus direction); + void MoveObject(DirectionBus direction); + } +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/MoveToBorder.cs b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/MoveToBorder.cs new file mode 100644 index 0000000..8115183 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/MoveToBorder.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.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/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/MoveToCenter.cs b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/MoveToCenter.cs new file mode 100644 index 0000000..609c7bf --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/MoveToCenter.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.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/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/ObjectParameters.cs b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..e7136da --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.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/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/Status.cs b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/Status.cs new file mode 100644 index 0000000..c7168d3 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/Status.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.MovementStrategy +{ + public enum Status + { + NotInit, + InProgress, + Finish + } +} \ No newline at end of file diff --git a/DoubleDeckerBus/DoubleDeckerBus/Program.cs b/DoubleDeckerBus/DoubleDeckerBus/Program.cs new file mode 100644 index 0000000..fa559b5 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/Program.cs @@ -0,0 +1,17 @@ +namespace DoubleDeckerBus +{ + 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 DoubleDeckerBus()); + } + } +} \ No newline at end of file diff --git a/DoubleDeckerBus/DoubleDeckerBus/Properties/Resources.Designer.cs b/DoubleDeckerBus/DoubleDeckerBus/Properties/Resources.Designer.cs new file mode 100644 index 0000000..31fbf58 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace DoubleDeckerBus.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("DoubleDeckerBus.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 arrowDown { + get { + object obj = ResourceManager.GetObject("arrowDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowLeft { + get { + object obj = ResourceManager.GetObject("arrowLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowRight { + get { + object obj = ResourceManager.GetObject("arrowRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowUp { + get { + object obj = ResourceManager.GetObject("arrowUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/Properties/Resources.resx b/DoubleDeckerBus/DoubleDeckerBus/Properties/Resources.resx new file mode 100644 index 0000000..59a6f4d --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/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\arrowUp.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowLeft.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowDown.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowRight.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowDown.jpg b/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowDown.jpg new file mode 100644 index 0000000..ec97b04 Binary files /dev/null and b/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowDown.jpg differ diff --git a/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowLeft.jpg b/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowLeft.jpg new file mode 100644 index 0000000..0081b53 Binary files /dev/null and b/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowLeft.jpg differ diff --git a/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowRight.jpg b/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowRight.jpg new file mode 100644 index 0000000..9877025 Binary files /dev/null and b/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowRight.jpg differ diff --git a/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowUp.jpg b/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowUp.jpg new file mode 100644 index 0000000..73e7b1b Binary files /dev/null and b/DoubleDeckerBus/DoubleDeckerBus/Resources/arrowUp.jpg differ