From 6c56275f1e264e4f5f873b856221ea63172d9f97 Mon Sep 17 00:00:00 2001 From: "A.Novopoltsev" Date: Sat, 17 Dec 2022 00:43:12 +0300 Subject: [PATCH] Event work --- Warship/Warship/DrawingAdvancedWarship.cs | 5 +++++ Warship/Warship/DrawingWarship.cs | 5 +++++ Warship/Warship/EntityAdvancedWarship.cs | 2 +- Warship/Warship/EntityWarship.cs | 2 +- Warship/Warship/FormMapWithSetWarships.cs | 26 ++++++++++++----------- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Warship/Warship/DrawingAdvancedWarship.cs b/Warship/Warship/DrawingAdvancedWarship.cs index d040237..c9406d6 100644 --- a/Warship/Warship/DrawingAdvancedWarship.cs +++ b/Warship/Warship/DrawingAdvancedWarship.cs @@ -67,5 +67,10 @@ namespace Warship g.DrawLine(pen, _startPosX + 10, _startPosY + 30 - 5, _startPosX + 20, _startPosY + 30 - 5); } } + + public void SetModifColor(Color modifColor) + { + ((EntityAdvancedWarship)Warship).DopColor = modifColor; + } } } diff --git a/Warship/Warship/DrawingWarship.cs b/Warship/Warship/DrawingWarship.cs index f8e6296..5715c71 100644 --- a/Warship/Warship/DrawingWarship.cs +++ b/Warship/Warship/DrawingWarship.cs @@ -27,6 +27,11 @@ namespace Warship _warshipHeight = warshipHeight; } + public void SetColor(Color color) + { + Warship.BodyColor = color; + } + public void SetPosition(int x, int y, int width, int height) { diff --git a/Warship/Warship/EntityAdvancedWarship.cs b/Warship/Warship/EntityAdvancedWarship.cs index ff91ad1..5ef53e5 100644 --- a/Warship/Warship/EntityAdvancedWarship.cs +++ b/Warship/Warship/EntityAdvancedWarship.cs @@ -8,7 +8,7 @@ namespace Warship { internal class EntityAdvancedWarship : EntityWarship { - public Color DopColor { get; private set; } + public Color DopColor { get; set; } public bool Helipad { get; private set; } public bool Antenna { get; private set; } public bool Missile { get; private set; } diff --git a/Warship/Warship/EntityWarship.cs b/Warship/Warship/EntityWarship.cs index b0a4ede..8663cd0 100644 --- a/Warship/Warship/EntityWarship.cs +++ b/Warship/Warship/EntityWarship.cs @@ -10,7 +10,7 @@ namespace Warship { public int Speed { get; private set; } public float Weight { get; private set; } - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } public int Step => (int)(Speed * 2000 / Weight); public EntityWarship(int speed, float weight, Color bodyColor) diff --git a/Warship/Warship/FormMapWithSetWarships.cs b/Warship/Warship/FormMapWithSetWarships.cs index 7c946ba..996337f 100644 --- a/Warship/Warship/FormMapWithSetWarships.cs +++ b/Warship/Warship/FormMapWithSetWarships.cs @@ -50,24 +50,26 @@ namespace Warship } private void ButtonAddWarship_Click(object sender, EventArgs e) + { + var formWarshipConfig = new FormWarshipConfig(); + formWarshipConfig.AddEvent(AddWarshipOnMap); + formWarshipConfig.Show(); + } + private void AddWarshipOnMap(DrawingWarship drawingWarship) { if (listBoxMaps.SelectedIndex == -1) { return; } - FormWarship form = new(); - if (form.ShowDialog() == DialogResult.OK) + DrawingObjectWarship warship = new(drawingWarship); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + warship != -1) { - DrawingObjectWarship warship = new(form.SelectedWarship); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + warship != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } }