From f3a64bc61701e498ae839c43f7004aa201337a05 Mon Sep 17 00:00:00 2001 From: DelphyAlmond Date: Sat, 15 Jun 2024 10:03:23 +0400 Subject: [PATCH] delegates --- .../DrawningSamples/DrawningCruiser.cs | 20 ++++++++++--------- ProjectCruiser/EditorForm3.cs | 9 ++------- ProjectCruiser/Entities/EntityCruiser.cs | 4 ++-- ProjectCruiser/OceanForm1.cs | 2 +- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ProjectCruiser/DrawningSamples/DrawningCruiser.cs b/ProjectCruiser/DrawningSamples/DrawningCruiser.cs index 4f3f56e..8b1c8c7 100644 --- a/ProjectCruiser/DrawningSamples/DrawningCruiser.cs +++ b/ProjectCruiser/DrawningSamples/DrawningCruiser.cs @@ -6,17 +6,17 @@ public class DrawningCruiser : DrawningBase { // Инициализация свойств (все параметры класса (сущности)) public DrawningCruiser(int speed, double weight, Color bodyColor, - Color additionalColor, bool hangars) : base(302, 42) - // all additional featchures 'inside' object, so size remains + Color additionalColor, bool pad, bool hangars) : base(302, 42) { EntityTransport = new EntityCruiser(speed, weight, - bodyColor, additionalColor, hangars); + bodyColor, additionalColor, pad, hangars); } public override void DrawTransport(Graphics g) { - if (EntityTransport == null || EntityTransport is not EntityCruiser ship || - !_startPosX.HasValue || !_startPosY.HasValue) // [ !!! ] :O + if (EntityTransport == null || + EntityTransport is not EntityCruiser ship || + !_startPosX.HasValue || !_startPosY.HasValue) { return; } @@ -31,10 +31,12 @@ public class DrawningCruiser : DrawningBase base.DrawTransport(g); - // вертолетная площадка - default TRUE now - g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20); - g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20); - + // вертолетная площадка - non-default + if (ship.HelicopterPads) + { + g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20); + g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20); + } // ангар(ы) if (ship.Hangars) { diff --git a/ProjectCruiser/EditorForm3.cs b/ProjectCruiser/EditorForm3.cs index 949cbf5..269f27b 100644 --- a/ProjectCruiser/EditorForm3.cs +++ b/ProjectCruiser/EditorForm3.cs @@ -28,7 +28,6 @@ public partial class EditorForm3 : Form { if (shipDelegate == null) shipDelegate = del; else shipDelegate += del; - //shipDelegate += del; } private void DrawObject() @@ -69,9 +68,7 @@ public partial class EditorForm3 : Form case "AdvLabel": Random rn = new Random(); _cruiser = new DrawningCruiser((int)SpeedN.Value, (double)WeightN.Value, - Color.White, Color.Black,checkBoxHangars.Checked); - // ADD helicopter PAD as NOT DEFAULT - checkBoxPads.Checked [!] - // Convert.ToBoolean(rn.Next(0, 2))); + Color.White, Color.Black, checkBoxPads.Checked, checkBoxHangars.Checked); break; } labelMcolor.BackColor = Color.Empty; @@ -79,13 +76,12 @@ public partial class EditorForm3 : Form DrawObject(); } - // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) + // Логика смены цветов: основного и дополнительного (для продвинутого объекта) private void BodyColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } - private void BodyColor_DragDrop(object sender, DragEventArgs e) { if (_cruiser != null) @@ -103,7 +99,6 @@ public partial class EditorForm3 : Form else e.Effect = DragDropEffects.None; } } - private void AdditionalColor_DragDrop(object sender, DragEventArgs e) { if (_cruiser.EntityTransport is EntityCruiser _ship) diff --git a/ProjectCruiser/Entities/EntityCruiser.cs b/ProjectCruiser/Entities/EntityCruiser.cs index af25267..e04588a 100644 --- a/ProjectCruiser/Entities/EntityCruiser.cs +++ b/ProjectCruiser/Entities/EntityCruiser.cs @@ -14,11 +14,11 @@ public class EntityCruiser : EntityBase public bool Hangars { get; private set; } // ангар public EntityCruiser(int speed, double weight, Color mainc, - Color additionalColor, bool hangars) + Color additionalColor, bool pad, bool hangars) : base(speed, weight, mainc) { AdditionalColor = additionalColor; - // HelicopterPads = pads; - default TRUE now for Advanced obj + HelicopterPads = pad; // non-default now for editor Form3 Hangars = hangars; } } diff --git a/ProjectCruiser/OceanForm1.cs b/ProjectCruiser/OceanForm1.cs index e8b217f..3c9e341 100644 --- a/ProjectCruiser/OceanForm1.cs +++ b/ProjectCruiser/OceanForm1.cs @@ -68,7 +68,7 @@ namespace ProjectCruiser random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2))); + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: