5 лабораторная работа
This commit is contained in:
parent
2862cd6de1
commit
f1592df7b7
14
Stormtrooper/Stormtrooper/AircraftDelegate.cs
Normal file
14
Stormtrooper/Stormtrooper/AircraftDelegate.cs
Normal file
@ -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;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Делегат передачи объекта-прорисовки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="aircraft"></param>
|
||||||
|
public delegate void AircraftDelegate(DrawningAircraft aircraft);
|
@ -8,11 +8,6 @@ namespace Stormtrooper.Entities;
|
|||||||
|
|
||||||
public class EntityStormtrooper : EntityAircraft
|
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; }
|
public Color AdditionalColor { get; private set; }
|
||||||
|
|
||||||
|
@ -40,30 +40,30 @@ public partial class FormAircraftCollection : Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создание объекта класса-перемещения
|
/// Добавление автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">Тип создаваемого объекта</param>
|
/// <param name="sender"></param>
|
||||||
private void CreateObject(string type)
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddAircraft_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_company == null)
|
FormAircraftConfig form = new();
|
||||||
|
//TODO Передать метод
|
||||||
|
form.Show();
|
||||||
|
form.AddEvent(SetAircraft);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление автомобиля в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="aircraft"></param>
|
||||||
|
private void SetAircraft(DrawningAircraft aircraft)
|
||||||
|
{
|
||||||
|
if (_company == null || aircraft == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Random random = new();
|
|
||||||
DrawningAircraft drawningAircraft;
|
if (_company + aircraft != -1)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
@ -74,34 +74,6 @@ public partial class FormAircraftCollection : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получение цвета
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="random">Генератор случайных чисел</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
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)
|
private void ButtonRemoveAircraft_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||||
|
@ -44,11 +44,11 @@
|
|||||||
labelWeight = new Label();
|
labelWeight = new Label();
|
||||||
numericUpDownSpeed = new NumericUpDown();
|
numericUpDownSpeed = new NumericUpDown();
|
||||||
labelSpeed = new Label();
|
labelSpeed = new Label();
|
||||||
label1 = new Label();
|
labelModifiedObject = new Label();
|
||||||
labelSimpleObject = new Label();
|
labelSimpleObject = new Label();
|
||||||
pictureBoxObject = new PictureBox();
|
pictureBoxObject = new PictureBox();
|
||||||
buttonCancel = new Button();
|
buttonCancel = new Button();
|
||||||
button2 = new Button();
|
buttonAdd = new Button();
|
||||||
panelObject = new Panel();
|
panelObject = new Panel();
|
||||||
labelAdditionalColor = new Label();
|
labelAdditionalColor = new Label();
|
||||||
labelBodyColor = new Label();
|
labelBodyColor = new Label();
|
||||||
@ -69,7 +69,7 @@
|
|||||||
groupBoxConfig.Controls.Add(labelWeight);
|
groupBoxConfig.Controls.Add(labelWeight);
|
||||||
groupBoxConfig.Controls.Add(numericUpDownSpeed);
|
groupBoxConfig.Controls.Add(numericUpDownSpeed);
|
||||||
groupBoxConfig.Controls.Add(labelSpeed);
|
groupBoxConfig.Controls.Add(labelSpeed);
|
||||||
groupBoxConfig.Controls.Add(label1);
|
groupBoxConfig.Controls.Add(labelModifiedObject);
|
||||||
groupBoxConfig.Controls.Add(labelSimpleObject);
|
groupBoxConfig.Controls.Add(labelSimpleObject);
|
||||||
groupBoxConfig.Dock = DockStyle.Left;
|
groupBoxConfig.Dock = DockStyle.Left;
|
||||||
groupBoxConfig.Location = new Point(0, 0);
|
groupBoxConfig.Location = new Point(0, 0);
|
||||||
@ -169,7 +169,6 @@
|
|||||||
checkBoxBomb.TabIndex = 8;
|
checkBoxBomb.TabIndex = 8;
|
||||||
checkBoxBomb.Text = "Признак наличия бомб";
|
checkBoxBomb.Text = "Признак наличия бомб";
|
||||||
checkBoxBomb.UseVisualStyleBackColor = true;
|
checkBoxBomb.UseVisualStyleBackColor = true;
|
||||||
|
|
||||||
//
|
//
|
||||||
// checkBoxRocket
|
// checkBoxRocket
|
||||||
//
|
//
|
||||||
@ -219,16 +218,16 @@
|
|||||||
labelSpeed.TabIndex = 2;
|
labelSpeed.TabIndex = 2;
|
||||||
labelSpeed.Text = "Скорость:";
|
labelSpeed.Text = "Скорость:";
|
||||||
//
|
//
|
||||||
// label1
|
// labelModifiedObject
|
||||||
//
|
//
|
||||||
label1.BorderStyle = BorderStyle.FixedSingle;
|
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
label1.Location = new Point(422, 179);
|
labelModifiedObject.Location = new Point(422, 179);
|
||||||
label1.Name = "label1";
|
labelModifiedObject.Name = "labelModifiedObject";
|
||||||
label1.Size = new Size(162, 36);
|
labelModifiedObject.Size = new Size(162, 36);
|
||||||
label1.TabIndex = 1;
|
labelModifiedObject.TabIndex = 1;
|
||||||
label1.Text = "Продвинутый объект";
|
labelModifiedObject.Text = "Продвинутый объект";
|
||||||
label1.TextAlign = ContentAlignment.MiddleCenter;
|
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
label1.MouseDown += labelObject_MouseDown;
|
labelModifiedObject.MouseDown += labelObject_MouseDown;
|
||||||
//
|
//
|
||||||
// labelSimpleObject
|
// labelSimpleObject
|
||||||
//
|
//
|
||||||
@ -245,27 +244,28 @@
|
|||||||
//
|
//
|
||||||
pictureBoxObject.Location = new Point(12, 47);
|
pictureBoxObject.Location = new Point(12, 47);
|
||||||
pictureBoxObject.Name = "pictureBoxObject";
|
pictureBoxObject.Name = "pictureBoxObject";
|
||||||
pictureBoxObject.Size = new Size(180, 143);
|
pictureBoxObject.Size = new Size(180, 153);
|
||||||
pictureBoxObject.TabIndex = 1;
|
pictureBoxObject.TabIndex = 1;
|
||||||
pictureBoxObject.TabStop = false;
|
pictureBoxObject.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
buttonCancel.Location = new Point(712, 199);
|
buttonCancel.Location = new Point(704, 206);
|
||||||
buttonCancel.Name = "buttonCancel";
|
buttonCancel.Name = "buttonCancel";
|
||||||
buttonCancel.Size = new Size(84, 36);
|
buttonCancel.Size = new Size(84, 36);
|
||||||
buttonCancel.TabIndex = 3;
|
buttonCancel.TabIndex = 3;
|
||||||
buttonCancel.Text = "Отмена";
|
buttonCancel.Text = "Отмена";
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// button2
|
// buttonAdd
|
||||||
//
|
//
|
||||||
button2.Location = new Point(599, 199);
|
buttonAdd.Location = new Point(608, 206);
|
||||||
button2.Name = "button2";
|
buttonAdd.Name = "buttonAdd";
|
||||||
button2.Size = new Size(84, 36);
|
buttonAdd.Size = new Size(84, 36);
|
||||||
button2.TabIndex = 4;
|
buttonAdd.TabIndex = 4;
|
||||||
button2.Text = "Добавить";
|
buttonAdd.Text = "Добавить";
|
||||||
button2.UseVisualStyleBackColor = true;
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += buttonAdd_Click;
|
||||||
//
|
//
|
||||||
// panelObject
|
// panelObject
|
||||||
//
|
//
|
||||||
@ -275,13 +275,14 @@
|
|||||||
panelObject.Controls.Add(pictureBoxObject);
|
panelObject.Controls.Add(pictureBoxObject);
|
||||||
panelObject.Location = new Point(596, 0);
|
panelObject.Location = new Point(596, 0);
|
||||||
panelObject.Name = "panelObject";
|
panelObject.Name = "panelObject";
|
||||||
panelObject.Size = new Size(203, 193);
|
panelObject.Size = new Size(203, 203);
|
||||||
panelObject.TabIndex = 5;
|
panelObject.TabIndex = 5;
|
||||||
panelObject.DragDrop += panelObject_DragDrop;
|
panelObject.DragDrop += panelObject_DragDrop;
|
||||||
panelObject.DragEnter += panelObject_DragEnter;
|
panelObject.DragEnter += panelObject_DragEnter;
|
||||||
//
|
//
|
||||||
// labelAdditionalColor
|
// labelAdditionalColor
|
||||||
//
|
//
|
||||||
|
labelAdditionalColor.AllowDrop = true;
|
||||||
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
labelAdditionalColor.Location = new Point(105, 9);
|
labelAdditionalColor.Location = new Point(105, 9);
|
||||||
labelAdditionalColor.Name = "labelAdditionalColor";
|
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||||
@ -311,7 +312,7 @@
|
|||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 247);
|
ClientSize = new Size(800, 247);
|
||||||
Controls.Add(panelObject);
|
Controls.Add(panelObject);
|
||||||
Controls.Add(button2);
|
Controls.Add(buttonAdd);
|
||||||
Controls.Add(buttonCancel);
|
Controls.Add(buttonCancel);
|
||||||
Controls.Add(groupBoxConfig);
|
Controls.Add(groupBoxConfig);
|
||||||
Name = "FormAircraftConfig";
|
Name = "FormAircraftConfig";
|
||||||
@ -332,7 +333,7 @@
|
|||||||
private Label labelSimpleObject;
|
private Label labelSimpleObject;
|
||||||
private NumericUpDown numericUpDownSpeed;
|
private NumericUpDown numericUpDownSpeed;
|
||||||
private Label labelSpeed;
|
private Label labelSpeed;
|
||||||
private Label label1;
|
private Label labelModifiedObject;
|
||||||
private NumericUpDown numericUpDownWeight;
|
private NumericUpDown numericUpDownWeight;
|
||||||
private Label labelWeight;
|
private Label labelWeight;
|
||||||
private CheckBox checkBoxRocket;
|
private CheckBox checkBoxRocket;
|
||||||
@ -348,7 +349,7 @@
|
|||||||
private Panel panelWhite;
|
private Panel panelWhite;
|
||||||
private PictureBox pictureBoxObject;
|
private PictureBox pictureBoxObject;
|
||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
private Button button2;
|
private Button buttonAdd;
|
||||||
private Panel panelObject;
|
private Panel panelObject;
|
||||||
private Label labelAdditionalColor;
|
private Label labelAdditionalColor;
|
||||||
private Label labelBodyColor;
|
private Label labelBodyColor;
|
||||||
|
@ -20,7 +20,13 @@ public partial class FormAircraftConfig : Form
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Объект - прорисовка самолета
|
/// Объект - прорисовка самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningAircraft? _aircraft = null;
|
private DrawningAircraft? _aircraft;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Событие для передачи объекта
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
private event AircraftDelegate? AircraftDelegate;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -41,6 +47,22 @@ public partial class FormAircraftConfig : Form
|
|||||||
buttonCancel.Click += (sender, e) => Close();
|
buttonCancel.Click += (sender, e) => Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Привязка внешнего метода к событию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="aircraftDelegate"></param>
|
||||||
|
public void AddEvent(AircraftDelegate aircraftDelegate)
|
||||||
|
{
|
||||||
|
if (AircraftDelegate != null)
|
||||||
|
{
|
||||||
|
AircraftDelegate = aircraftDelegate;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AircraftDelegate += aircraftDelegate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -151,7 +173,7 @@ public partial class FormAircraftConfig : Form
|
|||||||
{
|
{
|
||||||
if (_aircraft != null)
|
if (_aircraft != null)
|
||||||
{
|
{
|
||||||
_stormtrooperDelegate?.Invoke(_aircraft);
|
AircraftDelegate?.Invoke(_aircraft);
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace Stormtrooper
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormAircraftConfig());
|
Application.Run(new FormAircraftCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user