From 1994f6ec4d1b8d1f62231b161982c685559b1d52 Mon Sep 17 00:00:00 2001 From: ALINA_KURBANOVA Date: Fri, 3 Nov 2023 21:51:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyLocomotive/AbstractStrategy.cs | 11 +--- WarmlyLocomotive/Direction.cs | 9 +--- WarmlyLocomotive/DrawningObjectCar.cs | 24 ++++----- WarmlyLocomotive/DrawningPro.cs | 11 +--- WarmlyLocomotive/DrawningWarmlyLocomotive.cs | 12 +---- WarmlyLocomotive/EntityWarmlyLocomotive.cs | 8 +-- WarmlyLocomotive/IMoveableObject.cs | 8 +-- WarmlyLocomotive/MoveToBorder.cs | 16 +----- WarmlyLocomotive/MoveToCenter.cs | 10 +--- WarmlyLocomotive/ObjectParameters.cs | 8 +-- WarmlyLocomotive/Pro.cs | 9 +--- WarmlyLocomotive/Status.cs | 8 +-- WarmlyLocomotive/WarmlyLocomotiveForm.cs | 41 ++++++--------- .../WarmlylocomotiveForm.Designer.cs | 51 +++++++++---------- 14 files changed, 61 insertions(+), 165 deletions(-) diff --git a/WarmlyLocomotive/AbstractStrategy.cs b/WarmlyLocomotive/AbstractStrategy.cs index f77c150..be33106 100644 --- a/WarmlyLocomotive/AbstractStrategy.cs +++ b/WarmlyLocomotive/AbstractStrategy.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WarmlyLocomotive.MovementStrategy +namespace WarmlyLocomotive.MovementStrategy { public abstract class AbstractStrategy { @@ -83,8 +77,7 @@ namespace WarmlyLocomotive.MovementStrategy /// /// Параметры объекта /// - protected ObjectParameters? GetObjectParameters => - _moveableObject?.GetObjectPosition; + protected ObjectParameters? GetObjectParameters =>_moveableObject?.GetObjectPosition; /// /// Шаг объекта /// diff --git a/WarmlyLocomotive/Direction.cs b/WarmlyLocomotive/Direction.cs index 3fd3c4a..ad068cc 100644 --- a/WarmlyLocomotive/Direction.cs +++ b/WarmlyLocomotive/Direction.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WarmlyLocomotive +namespace WarmlyLocomotive { /// /// Направление перемещения @@ -27,6 +21,5 @@ namespace WarmlyLocomotive /// Вправо /// Right = 4 - } } \ No newline at end of file diff --git a/WarmlyLocomotive/DrawningObjectCar.cs b/WarmlyLocomotive/DrawningObjectCar.cs index d5035c7..b8b339e 100644 --- a/WarmlyLocomotive/DrawningObjectCar.cs +++ b/WarmlyLocomotive/DrawningObjectCar.cs @@ -1,37 +1,31 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WarmlyLocomotive.DrawningObjects; -using WarmlyLocomotive.MovementStrategy; +using WarmlyLocomotive.DrawningObjects; namespace WarmlyLocomotive.MovementStrategy { internal class DrawningObjectCar : IMoveableObject { - private readonly DrawningWarmlyLocomotive? _drawningCar = null; + private readonly DrawningWarmlyLocomotive? _drawningWarmlyLocomotive = null; public DrawningObjectCar(DrawningWarmlyLocomotive drawningCar) { - _drawningCar = drawningCar; + _drawningWarmlyLocomotive = drawningCar; } public ObjectParameters? GetObjectPosition { get { - if (_drawningCar == null || _drawningCar.EntityWarmlyLocomotive == + if (_drawningWarmlyLocomotive == null || _drawningWarmlyLocomotive.EntityWarmlyLocomotive == null) { return null; } - return new ObjectParameters(_drawningCar.GetPosX, - _drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight); + return new ObjectParameters(_drawningWarmlyLocomotive.GetPosX, + _drawningWarmlyLocomotive.GetPosY, _drawningWarmlyLocomotive.GetWidth, _drawningWarmlyLocomotive.GetHeight); } } - public int GetStep => (int)(_drawningCar?.EntityWarmlyLocomotive?.Step ?? 0); + public int GetStep => (int)(_drawningWarmlyLocomotive?.EntityWarmlyLocomotive?.Step ?? 0); public bool CheckCanMove(Direction direction) => - _drawningCar?.CanMove(direction) ?? false; + _drawningWarmlyLocomotive?.CanMove(direction) ?? false; public void MoveObject(Direction direction) => - _drawningCar?.MoveTransport(direction); + _drawningWarmlyLocomotive?.MoveTransport(direction); } } diff --git a/WarmlyLocomotive/DrawningPro.cs b/WarmlyLocomotive/DrawningPro.cs index 393e97a..a1d028f 100644 --- a/WarmlyLocomotive/DrawningPro.cs +++ b/WarmlyLocomotive/DrawningPro.cs @@ -1,11 +1,4 @@ -using WarmlyLocomotive.DrawningObjects; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WarmlyLocomotive.Entities; -using WarmlyLocomotive; +using WarmlyLocomotive.Entities; namespace WarmlyLocomotive.DrawningObjects { @@ -28,8 +21,6 @@ namespace WarmlyLocomotive.DrawningObjects { return; } - Pen pen = new(Color.Black, 2); - Brush bodyBrush = new SolidBrush(warmlylocomotive.BodyColor); Brush addBrush = new SolidBrush(warmlylocomotive.AdditionalColor); Brush wheelBrush = new SolidBrush(Color.Black); base.DrawTransport(g); diff --git a/WarmlyLocomotive/DrawningWarmlyLocomotive.cs b/WarmlyLocomotive/DrawningWarmlyLocomotive.cs index b20bf5e..88911f2 100644 --- a/WarmlyLocomotive/DrawningWarmlyLocomotive.cs +++ b/WarmlyLocomotive/DrawningWarmlyLocomotive.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WarmlyLocomotive.Entities; - +using WarmlyLocomotive.Entities; namespace WarmlyLocomotive.DrawningObjects { /// @@ -65,7 +59,6 @@ namespace WarmlyLocomotive.DrawningObjects EntityWarmlyLocomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor); } - protected DrawningWarmlyLocomotive(int speed, double weight, Color bodyColor, int width, int height, int carWidth, int carHeight) { @@ -95,7 +88,6 @@ namespace WarmlyLocomotive.DrawningObjects _startPosY = y; } - public bool CanMove(Direction direction) { if (EntityWarmlyLocomotive == null) @@ -115,7 +107,6 @@ namespace WarmlyLocomotive.DrawningObjects _ => false, }; } - /// Направление public void MoveTransport(Direction direction) { @@ -186,7 +177,6 @@ namespace WarmlyLocomotive.DrawningObjects g.FillEllipse(wheelBrush, _startPosX + 85, _startPosY + 50, 20, 20); g.FillEllipse(wheelBrush, _startPosX + 145, _startPosY + 50, 20, 20); g.FillEllipse(wheelBrush, _startPosX + 170, _startPosY + 50, 20, 20); - } } } diff --git a/WarmlyLocomotive/EntityWarmlyLocomotive.cs b/WarmlyLocomotive/EntityWarmlyLocomotive.cs index 4c83bcc..f5ce921 100644 --- a/WarmlyLocomotive/EntityWarmlyLocomotive.cs +++ b/WarmlyLocomotive/EntityWarmlyLocomotive.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WarmlyLocomotive.Entities +namespace WarmlyLocomotive.Entities { /// /// Класс-сущность "Автомобиль" diff --git a/WarmlyLocomotive/IMoveableObject.cs b/WarmlyLocomotive/IMoveableObject.cs index a038a63..4bb671f 100644 --- a/WarmlyLocomotive/IMoveableObject.cs +++ b/WarmlyLocomotive/IMoveableObject.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WarmlyLocomotive.MovementStrategy +namespace WarmlyLocomotive.MovementStrategy { /// /// Интерфейс для работы с перемещаемым объектом diff --git a/WarmlyLocomotive/MoveToBorder.cs b/WarmlyLocomotive/MoveToBorder.cs index 01162f8..24052ee 100644 --- a/WarmlyLocomotive/MoveToBorder.cs +++ b/WarmlyLocomotive/MoveToBorder.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WarmlyLocomotive.MovementStrategy; - -namespace WarmlyLocomotive.MovementStrategy +namespace WarmlyLocomotive.MovementStrategy { internal class MoveToBorder : AbstractStrategy { @@ -21,7 +14,6 @@ namespace WarmlyLocomotive.MovementStrategy objParams.DownBorder <= FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight; } - protected override void MoveToTarget() { var objParams = GetObjectParameters; @@ -32,19 +24,13 @@ namespace WarmlyLocomotive.MovementStrategy var diffX = FieldWidth - objParams.ObjectMiddleHorizontal; if (Math.Abs(diffX) > GetStep()) { - MoveRight(); - } var diffY = FieldHeight - objParams.ObjectMiddleVertical; if (Math.Abs(diffY) > GetStep()) { - MoveDown(); - } } - - } } \ No newline at end of file diff --git a/WarmlyLocomotive/MoveToCenter.cs b/WarmlyLocomotive/MoveToCenter.cs index a6b9a85..c5ec254 100644 --- a/WarmlyLocomotive/MoveToCenter.cs +++ b/WarmlyLocomotive/MoveToCenter.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WarmlyLocomotive.MovementStrategy; -namespace WarmlyLocomotive.MovementStrategy - +namespace WarmlyLocomotive.MovementStrategy { internal class MoveToCenter : AbstractStrategy { @@ -20,7 +13,6 @@ namespace WarmlyLocomotive.MovementStrategy objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && objParams.ObjectMiddleVertical <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2); - } protected override void MoveToTarget() { diff --git a/WarmlyLocomotive/ObjectParameters.cs b/WarmlyLocomotive/ObjectParameters.cs index 30bdeb7..b4b23ff 100644 --- a/WarmlyLocomotive/ObjectParameters.cs +++ b/WarmlyLocomotive/ObjectParameters.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WarmlyLocomotive.MovementStrategy +namespace WarmlyLocomotive.MovementStrategy { /// /// Параметры-координаты объекта diff --git a/WarmlyLocomotive/Pro.cs b/WarmlyLocomotive/Pro.cs index 1c2d294..a3f3d79 100644 --- a/WarmlyLocomotive/Pro.cs +++ b/WarmlyLocomotive/Pro.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static System.Net.Mime.MediaTypeNames; - -namespace WarmlyLocomotive.Entities +namespace WarmlyLocomotive.Entities { public class Pro : EntityWarmlyLocomotive { diff --git a/WarmlyLocomotive/Status.cs b/WarmlyLocomotive/Status.cs index 9184bdd..3d68e6b 100644 --- a/WarmlyLocomotive/Status.cs +++ b/WarmlyLocomotive/Status.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WarmlyLocomotive.MovementStrategy +namespace WarmlyLocomotive.MovementStrategy { /// /// Статус выполнения операции перемещения diff --git a/WarmlyLocomotive/WarmlyLocomotiveForm.cs b/WarmlyLocomotive/WarmlyLocomotiveForm.cs index 7cf6e64..a9b7087 100644 --- a/WarmlyLocomotive/WarmlyLocomotiveForm.cs +++ b/WarmlyLocomotive/WarmlyLocomotiveForm.cs @@ -1,3 +1,4 @@ +using System; using System.Windows.Forms; using WarmlyLocomotive.DrawningObjects; @@ -10,16 +11,15 @@ namespace WarmlyLocomotive /// public partial class WarmlyLocomotiveForm : Form { - /// - /// - - /// private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive; + private AbstractStrategy? _abstractStrategy; + + public DrawningWarmlyLocomotive? SelectedCar { get; private set; } public WarmlyLocomotiveForm() { InitializeComponent(); } - /// /// /// @@ -29,11 +29,11 @@ namespace WarmlyLocomotive { return; } - Bitmap bmp = new(pictureBox1.Width, - pictureBox1.Height); + Bitmap bmp = new(pictureBoxWarmlyLocomotive.Width, + pictureBoxWarmlyLocomotive.Height); Graphics gr = Graphics.FromImage(bmp); _drawningWarmlyLocomotive.DrawTransport(gr); - pictureBox1.Image = bmp; + pictureBoxWarmlyLocomotive.Image = bmp; } /// /// " " @@ -47,12 +47,11 @@ namespace WarmlyLocomotive random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - pictureBox1.Width, pictureBox1.Height); + pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height); _drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } - private void buttonMove_Click(object sender, EventArgs e) { @@ -78,16 +77,6 @@ namespace WarmlyLocomotive } Draw(); } - - private void pictureBox1_Click(object sender, EventArgs e) - { - - } - - private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) - { - - } /// /// "" /// @@ -99,9 +88,9 @@ namespace WarmlyLocomotive { return; } - if (comboBox1.Enabled) + if (comboBoxWarmlyLocomotive.Enabled) { - _abstractStrategy = comboBox1.SelectedIndex + _abstractStrategy = comboBoxWarmlyLocomotive.SelectedIndex switch { 0 => new MoveToCenter(), @@ -113,9 +102,9 @@ namespace WarmlyLocomotive return; } _abstractStrategy.SetData(new - DrawningObjectCar(_drawningWarmlyLocomotive), pictureBox1.Width, - pictureBox1.Height); - comboBox1.Enabled = false; + DrawningObjectCar(_drawningWarmlyLocomotive), pictureBoxWarmlyLocomotive.Width, + pictureBoxWarmlyLocomotive.Height); + comboBoxWarmlyLocomotive.Enabled = false; } if (_abstractStrategy == null) { @@ -125,7 +114,7 @@ namespace WarmlyLocomotive Draw(); if (_abstractStrategy.GetStatus() == Status.Finish) { - comboBox1.Enabled = true; + comboBoxWarmlyLocomotive.Enabled = true; _abstractStrategy = null; } } @@ -145,7 +134,7 @@ namespace WarmlyLocomotive random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), - pictureBox1.Width, pictureBox1.Height); + pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height); _drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); diff --git a/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs b/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs index b5f7600..bcb4188 100644 --- a/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs +++ b/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs @@ -29,28 +29,27 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WarmlyLocomotiveForm)); - pictureBox1 = new PictureBox(); + pictureBoxWarmlyLocomotive = new PictureBox(); buttonCreate = new Button(); buttonLeft = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); - comboBox1 = new ComboBox(); + comboBoxWarmlyLocomotive = new ComboBox(); buttonStep = new Button(); buttonCreate_Pro = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit(); SuspendLayout(); // - // pictureBox1 + // pictureBoxWarmlyLocomotive // - pictureBox1.Dock = DockStyle.Fill; - pictureBox1.Location = new Point(0, 0); - pictureBox1.Name = "pictureBox1"; - pictureBox1.Size = new Size(884, 461); - pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; - pictureBox1.TabIndex = 0; - pictureBox1.TabStop = false; - pictureBox1.Click += pictureBox1_Click; + pictureBoxWarmlyLocomotive.Dock = DockStyle.Fill; + pictureBoxWarmlyLocomotive.Location = new Point(0, 0); + pictureBoxWarmlyLocomotive.Name = "pictureBoxWarmlyLocomotive"; + pictureBoxWarmlyLocomotive.Size = new Size(884, 461); + pictureBoxWarmlyLocomotive.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxWarmlyLocomotive.TabIndex = 0; + pictureBoxWarmlyLocomotive.TabStop = false; // // buttonCreate // @@ -111,16 +110,15 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += buttonMove_Click; // - // comboBox1 + // comboBoxWarmlyLocomotive // - comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; - comboBox1.FormattingEnabled = true; - comboBox1.Items.AddRange(new object[] { "Центр", "Угол" }); - comboBox1.Location = new Point(717, 21); - comboBox1.Name = "comboBox1"; - comboBox1.Size = new Size(121, 23); - comboBox1.TabIndex = 7; - comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; + comboBoxWarmlyLocomotive.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxWarmlyLocomotive.FormattingEnabled = true; + comboBoxWarmlyLocomotive.Items.AddRange(new object[] { "Центр", "Угол" }); + comboBoxWarmlyLocomotive.Location = new Point(717, 21); + comboBoxWarmlyLocomotive.Name = "comboBoxWarmlyLocomotive"; + comboBoxWarmlyLocomotive.Size = new Size(121, 23); + comboBoxWarmlyLocomotive.TabIndex = 7; // // buttonStep // @@ -147,16 +145,17 @@ ClientSize = new Size(884, 461); Controls.Add(buttonCreate_Pro); Controls.Add(buttonStep); - Controls.Add(comboBox1); + Controls.Add(comboBoxWarmlyLocomotive); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonLeft); Controls.Add(buttonCreate); - Controls.Add(pictureBox1); + Controls.Add(pictureBoxWarmlyLocomotive); Name = "WarmlyLocomotiveForm"; StartPosition = FormStartPosition.CenterScreen; - ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); + Text = "WarmlyLocomotiveForm"; + ((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -165,13 +164,13 @@ - private PictureBox pictureBox1; + private PictureBox pictureBoxWarmlyLocomotive; private Button buttonCreate; private Button buttonLeft; private Button buttonUp; private Button buttonDown; private Button buttonRight; - private ComboBox comboBox1; + private ComboBox comboBoxWarmlyLocomotive; private Button buttonStep; private Button buttonCreate_Pro; }