From 01b6de30dd1d3f9f4e663f1ef84e211cf81eb941 Mon Sep 17 00:00:00 2001 From: "yuliya.mavrina@internet.ru" Date: Sun, 10 Dec 2023 19:45:48 +0300 Subject: [PATCH 1/2] Hard_lab2 --- .../DoubleDeckerBus.Designer.cs | 65 +++++++-- .../DoubleDeckerBus_Hard/DoubleDeckerBus.cs | 85 +++++++++-- .../DrawningDoubleDeckerBus.cs | 114 --------------- .../DrawningObjects/DrawningBus.cs | 138 ++++++++++++++++++ .../DrawningObjects/DrawningDoorOval.cs | 47 ++++++ .../DrawningDoorRectangle.cs} | 18 +-- .../DrawningObjects/DrawningDoorTriangle.cs | 73 +++++++++ .../DrawningDoubleDeckerBus.cs | 72 +++++++++ .../Entities/EntityBus.cs | 22 +++ .../Entities/EntityDoubleDeckerBus.cs | 29 ++++ .../EntityDoubleDeckerBus.cs | 33 ----- .../DoubleDeckerBus_Hard/IDrawningDoors.cs | 14 ++ .../MovementStrategy/AbstractStrategy.cs | 73 +++++++++ .../MovementStrategy/DrawningObjectBus.cs | 35 +++++ .../MovementStrategy/IMoveableObject.cs | 16 ++ .../MovementStrategy/MoveToBorder.cs | 57 ++++++++ .../MovementStrategy/MoveToCenter.cs | 56 +++++++ .../MovementStrategy/ObjectParameters.cs | 29 ++++ .../MovementStrategy/Status.cs | 15 ++ 19 files changed, 814 insertions(+), 177 deletions(-) delete mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningDoubleDeckerBus.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningBus.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorOval.cs rename DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/{DrawningDoor.cs => DrawningObjects/DrawningDoorRectangle.cs} (69%) create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorTriangle.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoubleDeckerBus.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/Entities/EntityBus.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/Entities/EntityDoubleDeckerBus.cs delete mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/EntityDoubleDeckerBus.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/IDrawningDoors.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/AbstractStrategy.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/DrawningObjectBus.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/IMoveableObject.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/MoveToBorder.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/MoveToCenter.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/ObjectParameters.cs create mode 100644 DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/Status.cs diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.Designer.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.Designer.cs index 77d50f9..1f89ba4 100644 --- a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.Designer.cs +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.Designer.cs @@ -29,11 +29,14 @@ private void InitializeComponent() { pictureBoxBus = new PictureBox(); - buttonCreate = new Button(); + buttonCreatDoubleDeckerBus = new Button(); buttonDown = new Button(); buttonUp = new Button(); buttonLeft = new Button(); buttonRight = new Button(); + buttonCreateBus = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxBus).BeginInit(); SuspendLayout(); // @@ -47,16 +50,16 @@ pictureBoxBus.TabIndex = 0; pictureBoxBus.TabStop = false; // - // buttonCreate + // buttonCreatDoubleDeckerBus // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 433); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(75, 23); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; + buttonCreatDoubleDeckerBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreatDoubleDeckerBus.Location = new Point(12, 411); + buttonCreatDoubleDeckerBus.Name = "buttonCreatDoubleDeckerBus"; + buttonCreatDoubleDeckerBus.Size = new Size(163, 45); + buttonCreatDoubleDeckerBus.TabIndex = 1; + buttonCreatDoubleDeckerBus.Text = "Создать двухэтажный автобус"; + buttonCreatDoubleDeckerBus.UseVisualStyleBackColor = true; + buttonCreatDoubleDeckerBus.Click += buttonCreatDoubleDeckerBus_Click; // // buttonDown // @@ -106,16 +109,51 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += buttonMove_Click; // + // buttonCreateBus + // + buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateBus.Location = new Point(181, 411); + buttonCreateBus.Name = "buttonCreateBus"; + buttonCreateBus.Size = new Size(137, 45); + buttonCreateBus.TabIndex = 6; + buttonCreateBus.Text = "Создать автобус"; + buttonCreateBus.UseVisualStyleBackColor = true; + buttonCreateBus.Click += buttonCreateBus_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 = 7; + // + // buttonStep + // + buttonStep.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonStep.Location = new Point(811, 41); + buttonStep.Name = "buttonStep"; + buttonStep.Size = new Size(61, 25); + buttonStep.TabIndex = 8; + buttonStep.Text = "Шаг"; + buttonStep.UseVisualStyleBackColor = true; + buttonStep.Click += buttonStep_Click; + // // DoubleDeckerBus // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(884, 468); + Controls.Add(buttonStep); + Controls.Add(comboBoxStrategy); + Controls.Add(buttonCreateBus); Controls.Add(buttonRight); Controls.Add(buttonLeft); Controls.Add(buttonUp); Controls.Add(buttonDown); - Controls.Add(buttonCreate); + Controls.Add(buttonCreatDoubleDeckerBus); Controls.Add(pictureBoxBus); Name = "DoubleDeckerBus"; StartPosition = FormStartPosition.CenterScreen; @@ -128,10 +166,13 @@ #endregion private PictureBox pictureBoxBus; - private Button buttonCreate; + private Button buttonCreatDoubleDeckerBus; private Button buttonDown; private Button buttonUp; private Button buttonLeft; private Button buttonRight; + private Button buttonCreateBus; + private ComboBox comboBoxStrategy; + private Button buttonStep; } } \ No newline at end of file diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.cs index 1c6b80a..5ee08b2 100644 --- a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.cs +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.cs @@ -1,8 +1,13 @@ +using DoubleDeckerBus_Hard.DrawningObjects; +using DoubleDeckerBus_Hard.MovementStrategy; + namespace DoubleDeckerBus_Hard { public partial class DoubleDeckerBus : Form { - private DrawningDoubleDeckerBus? _drawningBus; + private DrawningBus? _drawningBus; + private AbstractStrategy? _strategy; + public DrawningBus? SelectedBus { get; private set; } public DoubleDeckerBus() { InitializeComponent(); @@ -13,22 +18,51 @@ namespace DoubleDeckerBus_Hard { return; } - Bitmap bmp = new(pictureBoxBus.Width, - pictureBoxBus.Height); + Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height); Graphics gr = Graphics.FromImage(bmp); _drawningBus.DrawTransport(gr); pictureBoxBus.Image = bmp; } - private void buttonCreate_Click(object sender, EventArgs e) + private void buttonCreateBus_Click(object sender, EventArgs e) { Random random = new(); - _drawningBus = new DrawningDoubleDeckerBus(); - _drawningBus.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), random.Next(2, 6), pictureBoxBus.Width, pictureBoxBus.Height); + Color color = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _drawningBus = new DrawningBus(random.Next(100, 300),random.Next(1000, 3000), color, + pictureBoxBus.Width, pictureBoxBus.Height, random.Next(2, 6), random.Next(0, 4)); + _drawningBus.SetPosition(random.Next(10, 100), random.Next(10,100)); + Draw(); + } + + private void buttonCreatDoubleDeckerBus_Click(object sender, EventArgs e) + { + Random random = new(); + Color color = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialogColor = new(); + if (dialogColor.ShowDialog() == DialogResult.OK) + { + color = dialogColor.Color; + } + Color dopColor = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialogDopColor = new(); + if (dialogDopColor.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDopColor.Color; + } + _drawningBus = new DrawningDoubleDeckerBus(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), random.Next(2, 6), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxBus.Width, pictureBoxBus.Height, random.Next(0, 4)); _drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + private void buttonMove_Click(object sender, EventArgs e) { if (_drawningBus == null) @@ -53,6 +87,39 @@ namespace DoubleDeckerBus_Hard } Draw(); } - + private void buttonStep_Click(object sender, EventArgs e) + { + if (_drawningBus == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _strategy = comboBoxStrategy.SelectedIndex switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_strategy == null) + { + return; + } + _strategy.SetData(_drawningBus.GetMoveableObject, + pictureBoxBus.Width, pictureBoxBus.Height); + } + if (_strategy == null) + { + return; + } + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); + Draw(); + if (_strategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.Enabled = true; + _strategy = null; + } + } } } \ No newline at end of file diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningDoubleDeckerBus.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningDoubleDeckerBus.cs deleted file mode 100644 index 453d8d0..0000000 --- a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningDoubleDeckerBus.cs +++ /dev/null @@ -1,114 +0,0 @@ -using DoubleDeckerBus_Hard; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DoubleDeckerBus_Hard -{ - internal class DrawningDoubleDeckerBus - { - public EntityDoubleDeckerBus? EntityDoubleDeckerBus { get; private set; } - - private int _pictureWidth; - private int _pictureHeight; - private int _startPosX; - private int _startPosY; - private readonly int _busWidth = 100; - private readonly int _busHeight = 70; - private DrawningDoor drawningsDoors; - - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, - bool secondFloor, bool ladder, bool roadLine, int doorNumbers, int width, int height) - { - _pictureWidth = width; - _pictureHeight = height; - if (_pictureHeight < _busHeight || _pictureWidth < _busWidth) - { - return false; - } - EntityDoubleDeckerBus = new EntityDoubleDeckerBus(); - EntityDoubleDeckerBus.Init(speed, weight, bodyColor, additionalColor, secondFloor, ladder, roadLine, doorNumbers); - - drawningsDoors = new DrawningDoor(); - drawningsDoors.ChangeDoorsNumber(doorNumbers); - return true; - } - public void SetPosition(int x, int y) - { - _startPosX = Math.Min(x, _pictureWidth - _busWidth); - _startPosY = Math.Min(y, _pictureHeight - _busHeight); - } - public void MoveTransport(DirectionBus direction) - { - if (EntityDoubleDeckerBus == null) - { - return; - } - switch (direction) - { - //влево - case DirectionBus.Left: - if (_startPosX - EntityDoubleDeckerBus.Step > 0) - { - _startPosX -= (int)EntityDoubleDeckerBus.Step; - } - break; - //вверх - case DirectionBus.Up: - if (_startPosY - EntityDoubleDeckerBus.Step > 0) - { - _startPosY -= (int)EntityDoubleDeckerBus.Step; - } - break; - // вправо - case DirectionBus.Right: - if (_startPosX + _busWidth + EntityDoubleDeckerBus.Step < _pictureWidth) - { - _startPosX += (int)EntityDoubleDeckerBus.Step; - } - break; - //вниз - case DirectionBus.Down: - if (_startPosY + _busHeight + EntityDoubleDeckerBus.Step < _pictureHeight) - { - _startPosY += (int)EntityDoubleDeckerBus.Step; - } - break; - } - } - public void DrawTransport(Graphics g) - { - if (EntityDoubleDeckerBus == null) - { - return; - } - Pen pen = new(Color.Black); - - g.DrawRectangle(pen, _startPosX - 1, _startPosY + 11, 100, 60); - Brush brBodyColor = new SolidBrush(EntityDoubleDeckerBus.BodyColor); - g.FillRectangle(brBodyColor, _startPosX, _startPosY + 10, 100, 60); - - - Brush brBlack = new SolidBrush(Color.Black); - g.DrawEllipse(pen, _startPosX + 7, _startPosY + 55, 20, 20); - g.DrawEllipse(pen, _startPosX + 77, _startPosY + 55, 20, 20); - g.FillEllipse(brBlack, _startPosX + 7, _startPosY + 55, 20, 20); - g.FillEllipse(brBlack, _startPosX + 77, _startPosY + 55, 20, 20); - - 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); - - g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 35, 10, 15); - g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 35, 10, 15); - g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 35, 10, 15); - g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 35, 10, 15); - - drawningsDoors.DrawDoorsNumber(g, _startPosX, _startPosY); - } - } -} \ No newline at end of file diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningBus.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningBus.cs new file mode 100644 index 0000000..3364d16 --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningBus.cs @@ -0,0 +1,138 @@ +using DoubleDeckerBus_Hard.Entities; +using DoubleDeckerBus_Hard.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.DrawningObjects +{ + public class DrawningBus + { + public EntityBus? EntityBus { get; protected set; } + public IMoveableObject GetMoveableObject => new DrawningObjectBus(this); + public int? _pictureWidth; + public 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; + private IDrawningDoors drawningsDoors; + public DrawningBus(int speed, float weight, Color bodyColor, int width, int height,int doorNumbers, int doorShape) + { + if (width < _busWidth || height < _busHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + EntityBus = new EntityBus(speed, weight, bodyColor); + switch (doorShape) + { + case 1: + drawningsDoors = new DrawningDoorOval(); + break; + case 2: + drawningsDoors = new DrawningDoorTriangle(); + break; + default: + drawningsDoors = new DrawningDoorRectangle(); + break; + } + drawningsDoors.ChangeDoorsNumber(doorNumbers); + } + 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); + // Колеса + Brush brBlack = new SolidBrush(Color.Black); + 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); + g.FillEllipse(brBlue, _startPosX + 30, _startPosY + 15, 10, 15); + + drawningsDoors.DrawDoorsNumber(g, _startPosX, _startPosY); + } + } +} \ No newline at end of file diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorOval.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorOval.cs new file mode 100644 index 0000000..a0714de --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorOval.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.DrawningObjects +{ + internal class DrawningDoorOval : IDrawningDoors + { + public DoorNumbers _doorNumbers; + public void ChangeDoorsNumber(int x) + { + if (x <= 3) + { + _doorNumbers = DoorNumbers.Three; + } + if (x == 4) + { + _doorNumbers = DoorNumbers.Four; + } + if (x >= 5) + { + _doorNumbers = DoorNumbers.Five; + } + } + public void DrawDoorsNumber(Graphics g, int _startPosX, int _startPosY) + { + Pen pen = new(Color.White); + Brush brBlue = new SolidBrush(Color.Black); + g.FillEllipse(brBlue, _startPosX + 20, _startPosY + 21, 10, 20); + g.FillEllipse(brBlue, _startPosX + 31, _startPosY + 21, 10, 20); + g.FillEllipse(brBlue, _startPosX + 60, _startPosY + 21, 10, 20); + + if (_doorNumbers == DoorNumbers.Four || _doorNumbers == DoorNumbers.Five) + { + g.FillEllipse(brBlue, _startPosX + 80, _startPosY + 21, 10, 20); + } + + if (_doorNumbers == DoorNumbers.Five) + { + g.FillEllipse(brBlue, _startPosX + 42, _startPosY + 21, 10, 20); + } + } + } +} diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningDoor.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorRectangle.cs similarity index 69% rename from DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningDoor.cs rename to DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorRectangle.cs index 8d6b102..4d29a23 100644 --- a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningDoor.cs +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorRectangle.cs @@ -7,40 +7,40 @@ using System.Threading.Tasks; using static DoubleDeckerBus_Hard.DoorNumbers; -namespace DoubleDeckerBus_Hard +namespace DoubleDeckerBus_Hard.DrawningObjects { - internal class DrawningDoor + internal class DrawningDoorRectangle : IDrawningDoors { public DoorNumbers _doorNumbers; public void ChangeDoorsNumber(int x) { if (x <= 3) { - _doorNumbers = DoorNumbers.Three; + _doorNumbers = Three; } if (x == 4) { - _doorNumbers = DoorNumbers.Four; + _doorNumbers = Four; } if (x >= 5) { - _doorNumbers = DoorNumbers.Five; + _doorNumbers = Five; } } public void DrawDoorsNumber(Graphics g, int _startPosX, int _startPosY) { - Pen pen = new(Color.White); - Brush brBlue = new SolidBrush(Color.Black); + Pen pen = new(Color.White); + Brush brBlue = new SolidBrush(Color.Black); g.FillRectangle(brBlue, _startPosX + 20, _startPosY + 21, 10, 20); g.FillRectangle(brBlue, _startPosX + 31, _startPosY + 21, 10, 20); g.FillRectangle(brBlue, _startPosX + 60, _startPosY + 21, 10, 20); - if (_doorNumbers == DoorNumbers.Four || _doorNumbers == DoorNumbers.Five) + if (_doorNumbers == Four || _doorNumbers == Five) { g.FillRectangle(brBlue, _startPosX + 80, _startPosY + 21, 10, 20); } - if (_doorNumbers == DoorNumbers.Five) + if (_doorNumbers == Five) { g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 21, 10, 20); } diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorTriangle.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorTriangle.cs new file mode 100644 index 0000000..8f90114 --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoorTriangle.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.DrawningObjects +{ + internal class DrawningDoorTriangle : IDrawningDoors + { + public DoorNumbers _doorNumbers; + public void ChangeDoorsNumber(int x) + { + if (x <= 3) + { + _doorNumbers = DoorNumbers.Three; + } + if (x == 4) + { + _doorNumbers = DoorNumbers.Four; + } + if (x >= 5) + { + _doorNumbers = DoorNumbers.Five; + } + } + public void DrawDoorsNumber(Graphics g, int _startPosX, int _startPosY) + { + Pen pen = new(Color.White); + Brush brBlue = new SolidBrush(Color.Black); + Point[] triangle1 = { + new Point(_startPosX + 20, _startPosY + 41), + new Point(_startPosX + 25, _startPosY + 21), + new Point(_startPosX + 30, _startPosY + 41) + }; + g.FillPolygon(brBlue, triangle1); + + Point[] triangle2 = { + new Point(_startPosX + 41, _startPosY + 41), + new Point(_startPosX + 36, _startPosY + 21), + new Point(_startPosX + 46, _startPosY + 21) + }; + g.FillPolygon(brBlue, triangle2); + + Point[] triangle3 = { + new Point(_startPosX + 60, _startPosY + 41), + new Point(_startPosX + 55, _startPosY + 21), + new Point(_startPosX + 65, _startPosY + 21) + }; + g.FillPolygon(brBlue, triangle3); + + if (_doorNumbers == DoorNumbers.Four || _doorNumbers == DoorNumbers.Five) + { + Point[] triangle4 = { + new Point(_startPosX + 80, _startPosY + 41), + new Point(_startPosX + 75, _startPosY + 21), + new Point(_startPosX + 85, _startPosY + 21) + }; + g.FillPolygon(brBlue, triangle4); + } + + if (_doorNumbers == DoorNumbers.Five) + { + Point[] triangle5 = { + new Point(_startPosX + 42, _startPosY + 41), + new Point(_startPosX + 37, _startPosY + 21), + new Point(_startPosX + 47, _startPosY + 21) + }; + g.FillPolygon(brBlue, triangle5); + } + } + } +} diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoubleDeckerBus.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoubleDeckerBus.cs new file mode 100644 index 0000000..a69f4bf --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DrawningObjects/DrawningDoubleDeckerBus.cs @@ -0,0 +1,72 @@ +using DoubleDeckerBus_Hard.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.DrawningObjects +{ + internal class DrawningDoubleDeckerBus : DrawningBus + { + public EntityDoubleDeckerBus? EntityDoubleDeckerBus { get; private set; } + + public DrawningDoubleDeckerBus(int speed, float weight, Color bodyColor, + Color additionalColor, bool secondFloor, bool ladder, int doorNumbers, bool lineBetweenFloor, bool doors, int width, int height, int doorShape) : + base(speed, weight, bodyColor, width, height, doorNumbers, doorShape) + { + + if (EntityBus != null) + { + EntityBus = new EntityDoubleDeckerBus(speed, weight, bodyColor, + additionalColor, secondFloor, ladder, doorNumbers, lineBetweenFloor, doors); + } + } + 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); + //2 этаж + if (doubleDeckerBus.SecondFloor) + { + //границы 2 этажа + g.FillRectangle(brAdditionalColor, _startPosX, _startPosY + 10, 100, 30); + // Окна 2 этажа + 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); + g.FillEllipse(brBlue, _startPosX + 30, _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))); + } + } + } + } +} + \ No newline at end of file diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/Entities/EntityBus.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/Entities/EntityBus.cs new file mode 100644 index 0000000..f4150c7 --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/Entities/EntityBus.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.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_Hard/DoubleDeckerBus_Hard/Entities/EntityDoubleDeckerBus.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/Entities/EntityDoubleDeckerBus.cs new file mode 100644 index 0000000..f782f23 --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/Entities/EntityDoubleDeckerBus.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.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 int DoorNumbers { get; private set; } + public bool Doors { get; private set; } + public EntityDoubleDeckerBus(int speed, double weight, Color bodyColor, Color + additionalColor, bool secondFloor, bool ladder, int doorNumbers, bool lineBetweenFloor, bool doors) : base(speed, weight, bodyColor) + { + AdditionalColor = additionalColor; + SecondFloor = secondFloor; + Ladder = ladder; + LineBetweenFloor = lineBetweenFloor; + DoorNumbers = doorNumbers; + Doors = doors; + } + } +} + \ No newline at end of file diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/EntityDoubleDeckerBus.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/EntityDoubleDeckerBus.cs deleted file mode 100644 index 490840e..0000000 --- a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/EntityDoubleDeckerBus.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DoubleDeckerBus_Hard -{ - public class EntityDoubleDeckerBus - { - 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 SecondFloor { get; private set; } - public bool Ladder { get; private set; } - public bool RoadLine { get; private set; } - public int DoorNumbers { get; private set; } - public double Step => (double)Speed * 100 / Weight; - public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, bool secondFloor, bool ladder, bool roadLine, int doorNumbers) - { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; - AdditionalColor = additionalColor; - SecondFloor = secondFloor; - Ladder = ladder; - RoadLine = roadLine; - DoorNumbers = doorNumbers; - } - } -} \ No newline at end of file diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/IDrawningDoors.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/IDrawningDoors.cs new file mode 100644 index 0000000..0b0dfc1 --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/IDrawningDoors.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard +{ + internal interface IDrawningDoors + { + public void ChangeDoorsNumber(int x); + public void DrawDoorsNumber(Graphics g, int _startPosX, int _startPosY); + } +} diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/AbstractStrategy.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/AbstractStrategy.cs new file mode 100644 index 0000000..fa4e3ac --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/AbstractStrategy.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DoubleDeckerBus_Hard.DrawningObjects; + +namespace DoubleDeckerBus_Hard.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; + } + } +} \ No newline at end of file diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/DrawningObjectBus.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/DrawningObjectBus.cs new file mode 100644 index 0000000..e584622 --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/DrawningObjectBus.cs @@ -0,0 +1,35 @@ +using DoubleDeckerBus_Hard.DrawningObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.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_Hard/DoubleDeckerBus_Hard/MovementStrategy/IMoveableObject.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/IMoveableObject.cs new file mode 100644 index 0000000..dd91898 --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/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_Hard.MovementStrategy +{ + public interface IMoveableObject + { + ObjectParameters? GetObjectPosition { get; } + int GetStep { get; } + bool CheckCanMove(DirectionBus direction); + void MoveObject(DirectionBus direction); + } +} \ No newline at end of file diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/MoveToBorder.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/MoveToBorder.cs new file mode 100644 index 0000000..fe09233 --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/MoveToBorder.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.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_Hard/DoubleDeckerBus_Hard/MovementStrategy/MoveToCenter.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/MoveToCenter.cs new file mode 100644 index 0000000..1c618dd --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/MoveToCenter.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.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_Hard/DoubleDeckerBus_Hard/MovementStrategy/ObjectParameters.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..9355c26 --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus_Hard.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_Hard/DoubleDeckerBus_Hard/MovementStrategy/Status.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/MovementStrategy/Status.cs new file mode 100644 index 0000000..70f587b --- /dev/null +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/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_Hard.MovementStrategy +{ + public enum Status + { + NotInit, + InProgress, + Finish + } +} \ No newline at end of file -- 2.25.1 From 1c2170a64a36a8ca01277d78825e22915bb7734c Mon Sep 17 00:00:00 2001 From: "yuliya.mavrina@internet.ru" Date: Sat, 16 Dec 2023 19:41:28 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=E2=84=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DoubleDeckerBus_Hard/DoubleDeckerBus.cs | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.cs b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.cs index 5ee08b2..bd5c338 100644 --- a/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.cs +++ b/DoubleDeckerBus_Hard/DoubleDeckerBus_Hard/DoubleDeckerBus.cs @@ -26,14 +26,7 @@ namespace DoubleDeckerBus_Hard private void buttonCreateBus_Click(object sender, EventArgs e) { Random random = new(); - Color color = Color.FromArgb(random.Next(0, 256), - random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialog = new(); - if (dialog.ShowDialog() == DialogResult.OK) - { - color = dialog.Color; - } - _drawningBus = new DrawningBus(random.Next(100, 300),random.Next(1000, 3000), color, + _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, random.Next(2, 6), random.Next(0, 4)); _drawningBus.SetPosition(random.Next(10, 100), random.Next(10,100)); Draw(); @@ -42,21 +35,8 @@ namespace DoubleDeckerBus_Hard private void buttonCreatDoubleDeckerBus_Click(object sender, EventArgs e) { Random random = new(); - Color color = Color.FromArgb(random.Next(0, 256), - random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialogColor = new(); - if (dialogColor.ShowDialog() == DialogResult.OK) - { - color = dialogColor.Color; - } - Color dopColor = Color.FromArgb(random.Next(0, 256), - random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialogDopColor = new(); - if (dialogDopColor.ShowDialog() == DialogResult.OK) - { - dopColor = dialogDopColor.Color; - } - _drawningBus = new DrawningDoubleDeckerBus(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, + _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)), random.Next(2, 6), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxBus.Width, pictureBoxBus.Height, random.Next(0, 4)); _drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100)); -- 2.25.1