diff --git a/AntiAircraftGun/Entities/EntityAntiAircraftGun.cs b/AntiAircraftGun/Entities/EntityAntiAircraftGun.cs
index f19de8a..3d1baaf 100644
--- a/AntiAircraftGun/Entities/EntityAntiAircraftGun.cs
+++ b/AntiAircraftGun/Entities/EntityAntiAircraftGun.cs
@@ -9,6 +9,14 @@ public class EntityAntiAircraftGun : EntityArmoredCar
///
public Color AdditionalColor { get; private set; }
///
+ /// Метод передачи дополнительного цвета
+ ///
+ ///
+ public void setAdditionalColor(Color color)
+ {
+ AdditionalColor = color;
+ }
+ ///
/// Наличие башни
///
public bool Tower { get; private set; }
diff --git a/AntiAircraftGun/Entities/EntityArmoredCar.cs b/AntiAircraftGun/Entities/EntityArmoredCar.cs
index 9de4ea7..8cc8c93 100644
--- a/AntiAircraftGun/Entities/EntityArmoredCar.cs
+++ b/AntiAircraftGun/Entities/EntityArmoredCar.cs
@@ -17,6 +17,14 @@ public class EntityArmoredCar
///
public Color BodyColor { get; private set; }
///
+ /// Метод передачи цвета
+ ///
+ ///
+ public void setBodyColor(Color color)
+ {
+ BodyColor = color;
+ }
+ ///
/// Перемещение зенитной установки
///
public double Step => Speed * 100 / Weight;
diff --git a/AntiAircraftGun/FormCarConfig.cs b/AntiAircraftGun/FormCarConfig.cs
index c717ff4..4eaca69 100644
--- a/AntiAircraftGun/FormCarConfig.cs
+++ b/AntiAircraftGun/FormCarConfig.cs
@@ -1,4 +1,5 @@
using AntiAircraftGun.Drawnings;
+using AntiAircraftGun.Entities;
namespace AntiAircraftGun;
///
@@ -9,13 +10,14 @@ public partial class FormCarConfig : Form
///
/// Объект - прорисовка бронемашины
///
- private DrawningArmoredCar? _armoredCar;
+ private DrawningArmoredCar? _armoredCar = null;
///
/// Событие для передачи объекта
///
- private event ArmoredCarDelegate? armoredCarDelegate = null;
+ private event ArmoredCarDelegate? ArmoredCarDelegate;
public FormCarConfig()
{
+ InitializeComponent();
panelRed.MouseDown += Panel_MouseDown;
panelGreen.MouseDown += Panel_MouseDown;
panelBlue.MouseDown += Panel_MouseDown;
@@ -27,7 +29,7 @@ public partial class FormCarConfig : Form
// TODO buttonCancel.Click привязать анонимный метод через lambda с закрытием формы
buttonCancel.Click += (sender, e) => Close();
- InitializeComponent();
+
}
///
/// Привязка внешнего метода к событию
@@ -35,7 +37,7 @@ public partial class FormCarConfig : Form
///
public void AddEvent(ArmoredCarDelegate carDelegate)
{
- armoredCarDelegate += carDelegate;
+ ArmoredCarDelegate += carDelegate;
}
///
/// Прорисовка объекта
@@ -96,7 +98,7 @@ public partial class FormCarConfig : Form
private void Panel_MouseDown(object? sender, MouseEventArgs e)
{
// TODO отправка цвета в Drag&Drop
- (sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
+ (sender as Control)?.DoDragDrop((sender as Control)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
@@ -117,17 +119,16 @@ public partial class FormCarConfig : Form
{
if (_armoredCar != null)
{
- _armoredCar.EntityAircraftGun.BodyColor((Color)e.Data.GetData(typeof(Color)));
+ _armoredCar.EntityAircraftGun?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
}
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
- if (_armoredCar is DrawningAntiAircraftGun _antiAircraftGun)
+ if (_armoredCar?.EntityAircraftGun is EntityAntiAircraftGun _airbus)
{
- _antiAircraftGun.AdditionalColor((Color)e.Data.GetData(typeof(Color)));
-
+ _airbus.setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
}
DrawObject();
}