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 int Speed { get; private set; }
|
||||
// скорость
|
||||
public double Weight { get; private set; }
|
||||
// вес
|
||||
public Color BodyColor { get; private set; }
|
||||
// цвет
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
|
@ -40,30 +40,30 @@ public partial class FormAircraftCollection : Form
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// Добавление автомобиля
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
/// <param name="sender"></param>
|
||||
/// <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;
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||
|
@ -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;
|
||||
|
@ -20,7 +20,13 @@ public partial class FormAircraftConfig : Form
|
||||
/// <summary>
|
||||
/// Объект - прорисовка самолета
|
||||
/// </summary>
|
||||
private DrawningAircraft? _aircraft = null;
|
||||
private DrawningAircraft? _aircraft;
|
||||
|
||||
/// <summary>
|
||||
/// Событие для передачи объекта
|
||||
/// </summary>
|
||||
|
||||
private event AircraftDelegate? AircraftDelegate;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -41,6 +47,22 @@ public partial class FormAircraftConfig : Form
|
||||
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>
|
||||
@ -149,9 +171,9 @@ public partial class FormAircraftConfig : Form
|
||||
/// <param name="e"></param>
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if(_aircraft!= null)
|
||||
if (_aircraft != null)
|
||||
{
|
||||
_stormtrooperDelegate?.Invoke(_aircraft);
|
||||
AircraftDelegate?.Invoke(_aircraft);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user