From 0a07bace59be04a62b54e6bf3b37bb215657e622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D1=84=D1=8C=D1=8F=20=D0=AF=D0=BA=D0=BE=D0=B1?= =?UTF-8?q?=D1=87=D1=83=D0=BA?= Date: Tue, 28 Nov 2023 02:00:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B?= =?UTF-8?q?=20FormSailboat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/FormSailboat.Designer.cs | 13 ++++ Sailboat/Sailboat/FormSailboat.cs | 85 +++++++++++----------- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/Sailboat/Sailboat/FormSailboat.Designer.cs b/Sailboat/Sailboat/FormSailboat.Designer.cs index 4b435b1..3dcc60e 100644 --- a/Sailboat/Sailboat/FormSailboat.Designer.cs +++ b/Sailboat/Sailboat/FormSailboat.Designer.cs @@ -37,6 +37,7 @@ buttonCreateSailboat = new Button(); comboBoxStrategy = new ComboBox(); buttonStep = new Button(); + buttonSelectBoat = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxSailboat).BeginInit(); SuspendLayout(); // @@ -140,11 +141,22 @@ buttonStep.UseVisualStyleBackColor = true; buttonStep.Click += buttonStep_Click; // + // buttonSelectBoat + // + buttonSelectBoat.Location = new Point(137, 243); + buttonSelectBoat.Name = "buttonSelectBoat"; + buttonSelectBoat.Size = new Size(122, 40); + buttonSelectBoat.TabIndex = 9; + buttonSelectBoat.Text = "Выбрать лодку"; + buttonSelectBoat.UseVisualStyleBackColor = true; + buttonSelectBoat.Click += buttonSelectBoat_Click; + // // FormSailboat // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(882, 453); + Controls.Add(buttonSelectBoat); Controls.Add(buttonStep); Controls.Add(comboBoxStrategy); Controls.Add(buttonCreateSailboat); @@ -173,5 +185,6 @@ private Button buttonCreateSailboat; private ComboBox comboBoxStrategy; private Button buttonStep; + private Button buttonSelectBoat; } } \ No newline at end of file diff --git a/Sailboat/Sailboat/FormSailboat.cs b/Sailboat/Sailboat/FormSailboat.cs index 597a952..99c08d9 100644 --- a/Sailboat/Sailboat/FormSailboat.cs +++ b/Sailboat/Sailboat/FormSailboat.cs @@ -12,28 +12,19 @@ using System.Windows.Forms; namespace Sailboat { - /// - /// Форма работы с объектом "Парусная лодка" - /// public partial class FormSailboat : Form { - /// - /// Поле-объект для прорисовки объекта - /// private DrawingBoat? _drawingBoat; private AbstractStrategy? _abstractStrategy; + public DrawingBoat? SelectedBoat { get; private set; } - /// - /// Инициализация формы - /// public FormSailboat() { InitializeComponent(); + _abstractStrategy = null; + SelectedBoat = null; } - /// - /// Метод прорисовки лодки - /// private void Draw() { if (_drawingBoat == null) @@ -47,40 +38,45 @@ namespace Sailboat pictureBoxSailboat.Image = bmp; } - /// - /// Обработка нажатия кнопки "Создать лодку" - /// - /// - /// private void buttonCreateBoat_Click(object sender, EventArgs e) { Random random = new(); - _drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxSailboat.Width, pictureBoxSailboat.Height); - _drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, - 100)); - Draw(); - } - - /// - /// Обработка нажатия кнопки "Создать улучшеную лодку" - /// - /// - /// - private void buttonCreateSailboat_Click(object sender, EventArgs e) - { - Random random = new(); - _drawingBoat = new DrawingSailboat(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)), pictureBoxSailboat.Width, pictureBoxSailboat.Height); + 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; + } + _drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxSailboat.Width, pictureBoxSailboat.Height); + _drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + + private void buttonCreateSailboat_Click(object sender, EventArgs e) + { + Random random = new(); + 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; + } + + Color dopColor = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + if (dialog.ShowDialog() == DialogResult.OK) + { + dopColor = dialog.Color; + } + + _drawingBoat = new DrawingSailboat(random.Next(100, 300), + random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), + pictureBoxSailboat.Width, pictureBoxSailboat.Height); _drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } - /// - /// Изменение размеров формы - /// - /// - /// private void buttonMove_Click(object sender, EventArgs e) { if (_drawingBoat == null) @@ -106,11 +102,6 @@ namespace Sailboat Draw(); } - /// - /// Обработка нажатия кнопки "Шаг" - /// - /// - /// private void buttonStep_Click(object sender, EventArgs e) { if (_drawingBoat == null) @@ -146,5 +137,11 @@ namespace Sailboat _abstractStrategy = null; } } + + private void buttonSelectBoat_Click(object sender, EventArgs e) + { + SelectedBoat = _drawingBoat; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file