From f1592df7b7436edfb9283b3263125eaf2ea08382 Mon Sep 17 00:00:00 2001 From: rakhaliullov Date: Tue, 16 Apr 2024 22:56:14 +0300 Subject: [PATCH] =?UTF-8?q?5=20=D0=BB=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=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Stormtrooper/Stormtrooper/AircraftDelegate.cs | 14 ++++ .../Entities/EntityStormtrooper.cs | 5 -- .../Stormtrooper/FormAircraftCollection.cs | 66 ++++++------------- .../FormAircraftConfig.Designer.cs | 53 +++++++-------- .../Stormtrooper/FormAircraftConfig.cs | 28 +++++++- Stormtrooper/Stormtrooper/Program.cs | 2 +- 6 files changed, 86 insertions(+), 82 deletions(-) create mode 100644 Stormtrooper/Stormtrooper/AircraftDelegate.cs diff --git a/Stormtrooper/Stormtrooper/AircraftDelegate.cs b/Stormtrooper/Stormtrooper/AircraftDelegate.cs new file mode 100644 index 0000000..6ad3ce9 --- /dev/null +++ b/Stormtrooper/Stormtrooper/AircraftDelegate.cs @@ -0,0 +1,14 @@ +using Stormtrooper.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper; + +/// +/// Делегат передачи объекта-прорисовки +/// +/// +public delegate void AircraftDelegate(DrawningAircraft aircraft); diff --git a/Stormtrooper/Stormtrooper/Entities/EntityStormtrooper.cs b/Stormtrooper/Stormtrooper/Entities/EntityStormtrooper.cs index b7ebe92..3dc1ddc 100644 --- a/Stormtrooper/Stormtrooper/Entities/EntityStormtrooper.cs +++ b/Stormtrooper/Stormtrooper/Entities/EntityStormtrooper.cs @@ -8,11 +8,6 @@ namespace Stormtrooper.Entities; public class EntityStormtrooper : EntityAircraft { - public int Speed { get; private set; } - // скорость - public double Weight { get; private set; } - // вес - public Color BodyColor { get; private set; } // цвет public Color AdditionalColor { get; private set; } diff --git a/Stormtrooper/Stormtrooper/FormAircraftCollection.cs b/Stormtrooper/Stormtrooper/FormAircraftCollection.cs index 4921c6b..3e3eccf 100644 --- a/Stormtrooper/Stormtrooper/FormAircraftCollection.cs +++ b/Stormtrooper/Stormtrooper/FormAircraftCollection.cs @@ -40,30 +40,30 @@ public partial class FormAircraftCollection : Form } /// - /// Создание объекта класса-перемещения + /// Добавление автомобиля /// - /// Тип создаваемого объекта - private void CreateObject(string type) + /// + /// + private void ButtonAddAircraft_Click(object sender, EventArgs e) { - if (_company == null) + FormAircraftConfig form = new(); + //TODO Передать метод + form.Show(); + form.AddEvent(SetAircraft); + } + + /// + /// Добавление автомобиля в коллекцию + /// + /// + private void SetAircraft(DrawningAircraft aircraft) + { + if (_company == null || aircraft == null) { return; } - Random random = new(); - DrawningAircraft drawningAircraft; - switch (type) - { - case nameof(DrawningAircraft): - drawningAircraft = new DrawningAircraft(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); - break; - case nameof(DrawningStormtrooper): - drawningAircraft = new DrawningStormtrooper(random.Next(100, 300), random.Next(1000, 3000), - GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - if (_company + drawningAircraft != -1) + + if (_company + aircraft != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -74,34 +74,6 @@ public partial class FormAircraftCollection : Form } } - /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// - private static Color GetColor(Random random) - { - 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; - } - return color; - } - //private void ButtonAddAircraft_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAicraft)); - //private void ButtonStormtrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooper)); - private void ButtonAddAircraft_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningAircraft)); - } - - private void ButtonAddStormtrooper_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningStormtrooper)); - } - private void ButtonRemoveAircraft_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) diff --git a/Stormtrooper/Stormtrooper/FormAircraftConfig.Designer.cs b/Stormtrooper/Stormtrooper/FormAircraftConfig.Designer.cs index 597c9be..a89386a 100644 --- a/Stormtrooper/Stormtrooper/FormAircraftConfig.Designer.cs +++ b/Stormtrooper/Stormtrooper/FormAircraftConfig.Designer.cs @@ -44,11 +44,11 @@ labelWeight = new Label(); numericUpDownSpeed = new NumericUpDown(); labelSpeed = new Label(); - label1 = new Label(); + labelModifiedObject = new Label(); labelSimpleObject = new Label(); pictureBoxObject = new PictureBox(); buttonCancel = new Button(); - button2 = new Button(); + buttonAdd = new Button(); panelObject = new Panel(); labelAdditionalColor = new Label(); labelBodyColor = new Label(); @@ -69,7 +69,7 @@ groupBoxConfig.Controls.Add(labelWeight); groupBoxConfig.Controls.Add(numericUpDownSpeed); groupBoxConfig.Controls.Add(labelSpeed); - groupBoxConfig.Controls.Add(label1); + groupBoxConfig.Controls.Add(labelModifiedObject); groupBoxConfig.Controls.Add(labelSimpleObject); groupBoxConfig.Dock = DockStyle.Left; groupBoxConfig.Location = new Point(0, 0); @@ -169,7 +169,6 @@ checkBoxBomb.TabIndex = 8; checkBoxBomb.Text = "Признак наличия бомб"; checkBoxBomb.UseVisualStyleBackColor = true; - // // checkBoxRocket // @@ -219,16 +218,16 @@ labelSpeed.TabIndex = 2; labelSpeed.Text = "Скорость:"; // - // label1 + // labelModifiedObject // - label1.BorderStyle = BorderStyle.FixedSingle; - label1.Location = new Point(422, 179); - label1.Name = "label1"; - label1.Size = new Size(162, 36); - label1.TabIndex = 1; - label1.Text = "Продвинутый объект"; - label1.TextAlign = ContentAlignment.MiddleCenter; - label1.MouseDown += labelObject_MouseDown; + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(422, 179); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(162, 36); + labelModifiedObject.TabIndex = 1; + labelModifiedObject.Text = "Продвинутый объект"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += labelObject_MouseDown; // // labelSimpleObject // @@ -245,27 +244,28 @@ // pictureBoxObject.Location = new Point(12, 47); pictureBoxObject.Name = "pictureBoxObject"; - pictureBoxObject.Size = new Size(180, 143); + pictureBoxObject.Size = new Size(180, 153); pictureBoxObject.TabIndex = 1; pictureBoxObject.TabStop = false; // // buttonCancel // - buttonCancel.Location = new Point(712, 199); + buttonCancel.Location = new Point(704, 206); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(84, 36); buttonCancel.TabIndex = 3; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; // - // button2 + // buttonAdd // - button2.Location = new Point(599, 199); - button2.Name = "button2"; - button2.Size = new Size(84, 36); - button2.TabIndex = 4; - button2.Text = "Добавить"; - button2.UseVisualStyleBackColor = true; + buttonAdd.Location = new Point(608, 206); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(84, 36); + buttonAdd.TabIndex = 4; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; // // panelObject // @@ -275,13 +275,14 @@ panelObject.Controls.Add(pictureBoxObject); panelObject.Location = new Point(596, 0); panelObject.Name = "panelObject"; - panelObject.Size = new Size(203, 193); + panelObject.Size = new Size(203, 203); panelObject.TabIndex = 5; panelObject.DragDrop += panelObject_DragDrop; panelObject.DragEnter += panelObject_DragEnter; // // labelAdditionalColor // + labelAdditionalColor.AllowDrop = true; labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; labelAdditionalColor.Location = new Point(105, 9); labelAdditionalColor.Name = "labelAdditionalColor"; @@ -311,7 +312,7 @@ AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 247); Controls.Add(panelObject); - Controls.Add(button2); + Controls.Add(buttonAdd); Controls.Add(buttonCancel); Controls.Add(groupBoxConfig); Name = "FormAircraftConfig"; @@ -332,7 +333,7 @@ private Label labelSimpleObject; private NumericUpDown numericUpDownSpeed; private Label labelSpeed; - private Label label1; + private Label labelModifiedObject; private NumericUpDown numericUpDownWeight; private Label labelWeight; private CheckBox checkBoxRocket; @@ -348,7 +349,7 @@ private Panel panelWhite; private PictureBox pictureBoxObject; private Button buttonCancel; - private Button button2; + private Button buttonAdd; private Panel panelObject; private Label labelAdditionalColor; private Label labelBodyColor; diff --git a/Stormtrooper/Stormtrooper/FormAircraftConfig.cs b/Stormtrooper/Stormtrooper/FormAircraftConfig.cs index 5cd8c2b..25e8159 100644 --- a/Stormtrooper/Stormtrooper/FormAircraftConfig.cs +++ b/Stormtrooper/Stormtrooper/FormAircraftConfig.cs @@ -20,7 +20,13 @@ public partial class FormAircraftConfig : Form /// /// Объект - прорисовка самолета /// - private DrawningAircraft? _aircraft = null; + private DrawningAircraft? _aircraft; + + /// + /// Событие для передачи объекта + /// + + private event AircraftDelegate? AircraftDelegate; /// /// Конструктор @@ -41,6 +47,22 @@ public partial class FormAircraftConfig : Form buttonCancel.Click += (sender, e) => Close(); } + /// + /// Привязка внешнего метода к событию + /// + /// + public void AddEvent(AircraftDelegate aircraftDelegate) + { + if (AircraftDelegate != null) + { + AircraftDelegate = aircraftDelegate; + } + else + { + AircraftDelegate += aircraftDelegate; + } + } + /// /// Прорисовка объекта /// @@ -149,9 +171,9 @@ public partial class FormAircraftConfig : Form /// private void buttonAdd_Click(object sender, EventArgs e) { - if(_aircraft!= null) + if (_aircraft != null) { - _stormtrooperDelegate?.Invoke(_aircraft); + AircraftDelegate?.Invoke(_aircraft); Close(); } } diff --git a/Stormtrooper/Stormtrooper/Program.cs b/Stormtrooper/Stormtrooper/Program.cs index edd4ec9..8d32d67 100644 --- a/Stormtrooper/Stormtrooper/Program.cs +++ b/Stormtrooper/Stormtrooper/Program.cs @@ -11,7 +11,7 @@ namespace Stormtrooper // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAircraftConfig()); + Application.Run(new FormAircraftCollection()); } } } \ No newline at end of file