From 153af06a04071ab4cd88512d11912bf19bf0b501 Mon Sep 17 00:00:00 2001 From: "Valitov.Damir" Date: Sat, 15 Apr 2023 09:23:33 +0400 Subject: [PATCH] lab3 + edgeColor --- Sailboat/BoatForm.cs | 24 ++++++++++++++++++++---- Sailboat/DrawingSailboat.cs | 6 +++--- Sailboat/MapWithSetBoatsGeneric.cs | 1 - Sailboat/Sailboat.cs | 5 ++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Sailboat/BoatForm.cs b/Sailboat/BoatForm.cs index 4bac71c..1a2e320 100644 --- a/Sailboat/BoatForm.cs +++ b/Sailboat/BoatForm.cs @@ -29,8 +29,13 @@ namespace Sailboat private void btn_create_Click(object sender, EventArgs e) { Random rnd = new(); - _boat = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _boat = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), color); _boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBoat.Width, pictureBoxBoat.Height); SetData(); @@ -44,8 +49,19 @@ namespace Sailboat private void btn_create_sailboat_Click(object sender, EventArgs e) { Random rnd = new(); - _boat = new DrawingSailboat(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + Color edgeColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + edgeColor = dialogDop.Color; + } + _boat = new DrawingSailboat(rnd.Next(100, 300), rnd.Next(1000, 2000), color, edgeColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); _boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBoat.Width, pictureBoxBoat.Height); diff --git a/Sailboat/DrawingSailboat.cs b/Sailboat/DrawingSailboat.cs index ee4cf09..1e55062 100644 --- a/Sailboat/DrawingSailboat.cs +++ b/Sailboat/DrawingSailboat.cs @@ -20,10 +20,10 @@ namespace Sailboat /// Цвет кузова /// Признак наличия паруса /// Признак наличия усиленного корпуса - public DrawingSailboat(int speed, float weight, Color bodyColor, bool sail, bool extendedBody) : + public DrawingSailboat(int speed, float weight, Color bodyColor, Color edgeColor , bool sail, bool extendedBody) : base(speed, weight, bodyColor, 80, 135) { - Boat = new Sailboat(speed, weight, bodyColor, sail, extendedBody); + Boat = new Sailboat(speed, weight, bodyColor, edgeColor, sail, extendedBody); } public override void DrawTransport(Graphics g) { @@ -33,7 +33,7 @@ namespace Sailboat } Pen pen = new(Color.Black); - Brush brush = new SolidBrush(Color.Black); + Brush brush = new SolidBrush(sailboat.EdgeColor); _startPosY += 40; _startPosX += 20; diff --git a/Sailboat/MapWithSetBoatsGeneric.cs b/Sailboat/MapWithSetBoatsGeneric.cs index e6fa5f0..a818735 100644 --- a/Sailboat/MapWithSetBoatsGeneric.cs +++ b/Sailboat/MapWithSetBoatsGeneric.cs @@ -118,7 +118,6 @@ namespace Sailboat for (int i = 0; i < _setBoats.Count; i++) { - _setBoats.Get(i)?.SetObject(currentWidth * _placeSizeWidth, currentHeight * _placeSizeHeight, _pictureWidth, _pictureHeight); diff --git a/Sailboat/Sailboat.cs b/Sailboat/Sailboat.cs index ce2f996..a6838cf 100644 --- a/Sailboat/Sailboat.cs +++ b/Sailboat/Sailboat.cs @@ -17,6 +17,8 @@ namespace Sailboat /// Признак наличия паруса /// public bool Sail { get; private set; } + + public Color EdgeColor{ get; private set; } /// /// Инициализация свойств /// @@ -25,9 +27,10 @@ namespace Sailboat /// Цвет кузова /// Признак наличия паруса /// Признак наличия усиленного корпуса - public Sailboat(int speed, float weight, Color bodyColor, bool sail, bool extendedBody) : + public Sailboat(int speed, float weight, Color bodyColor, Color edgeColor, bool sail, bool extendedBody) : base(speed, weight, bodyColor) { + EdgeColor = edgeColor; Sail = sail; ExtendedBody = extendedBody; }