From 20f939bb779e3ac44b04c81113dbe66e0fadc7b1 Mon Sep 17 00:00:00 2001 From: Ivan_Starostin Date: Fri, 8 Dec 2023 21:15:40 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lainer/Lainer1/LainerForm.Designer.cs | 15 +++++- lainer/Lainer1/LainerForm.cs | 69 +++++++++++++++++---------- 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/lainer/Lainer1/LainerForm.Designer.cs b/lainer/Lainer1/LainerForm.Designer.cs index 25b0db9..26fbf24 100644 --- a/lainer/Lainer1/LainerForm.Designer.cs +++ b/lainer/Lainer1/LainerForm.Designer.cs @@ -37,6 +37,7 @@ ButtonCreateSuperLainer = new Button(); comboBoxStrategy = new ComboBox(); ButtonStep = new Button(); + ButtonSelectLainer = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxLainer).BeginInit(); SuspendLayout(); // @@ -122,7 +123,7 @@ // comboBoxStrategy // comboBoxStrategy.FormattingEnabled = true; - comboBoxStrategy.Items.AddRange(new object[] { "центр", "край"}); + comboBoxStrategy.Items.AddRange(new object[] { "центр", "край" }); comboBoxStrategy.Location = new Point(566, 12); comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(151, 28); @@ -138,11 +139,22 @@ ButtonStep.UseVisualStyleBackColor = true; ButtonStep.Click += ButtonStep_Click; // + // ButtonSelectLainer + // + ButtonSelectLainer.Location = new Point(369, 356); + ButtonSelectLainer.Name = "ButtonSelectLainer"; + ButtonSelectLainer.Size = new Size(94, 29); + ButtonSelectLainer.TabIndex = 9; + ButtonSelectLainer.Text = "выбрать"; + ButtonSelectLainer.UseVisualStyleBackColor = true; + ButtonSelectLainer.Click += ButtonSelectLainer_Click; + // // LainerForm // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(729, 397); + Controls.Add(ButtonSelectLainer); Controls.Add(ButtonStep); Controls.Add(comboBoxStrategy); Controls.Add(ButtonCreateSuperLainer); @@ -171,5 +183,6 @@ private Button ButtonCreateSuperLainer; private ComboBox comboBoxStrategy; private Button ButtonStep; + private Button ButtonSelectLainer; } } \ No newline at end of file diff --git a/lainer/Lainer1/LainerForm.cs b/lainer/Lainer1/LainerForm.cs index fe7518d..1e93d0c 100644 --- a/lainer/Lainer1/LainerForm.cs +++ b/lainer/Lainer1/LainerForm.cs @@ -6,9 +6,13 @@ namespace ProjectLainer { private DrawingLainer? _drawningLainer; private AbstractStrategy? _abstractStrategy; + private AbstractStrategy? _strategy; + public DrawingLainer? SelectedLainer { get; private set; } public LainerForm() { InitializeComponent(); + _strategy = null; + SelectedLainer = null; } private void Draw() { @@ -25,29 +29,39 @@ namespace ProjectLainer private void ButtonCreateSuperLainer_Click(object sender, EventArgs e) { Random random = new(); + Color mainColor = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + Color additColor = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + mainColor = dialog.Color; + } + if (dialog.ShowDialog() == DialogResult.OK) + { + additColor = dialog.Color; + } _drawningLainer = new DrawningSuperLainer(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)), + random.Next(1000, 3000), mainColor, additColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxLainer.Width, pictureBoxLainer.Height); - _drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, - 100)); + _drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void ButtonCreate_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; + } _drawningLainer = new DrawingLainer(random.Next(100, 300), - random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), + random.Next(1000, 3000), color, pictureBoxLainer.Width, pictureBoxLainer.Height); - _drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, - 100)); + _drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) @@ -82,33 +96,36 @@ namespace ProjectLainer } if (comboBoxStrategy.Enabled) { - _abstractStrategy = comboBoxStrategy.SelectedIndex - switch + _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.SetData(new - DrawningObjectLainer(_drawningLainer), pictureBoxLainer.Width, - pictureBoxLainer.Height); - comboBoxStrategy.Enabled = false; + _strategy.SetData(_drawningLainer.GetMoveableObject, + pictureBoxLainer.Width, pictureBoxLainer.Height); } - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.MakeStep(); + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); Draw(); - if (_abstractStrategy.GetStatus() == Status.Finish) + if (_strategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; - _abstractStrategy = null; + _strategy = null; } } + private void ButtonSelectLainer_Click(object sender, EventArgs e) + { + SelectedLainer = _drawningLainer; + DialogResult = DialogResult.OK; + } } -} \ No newline at end of file +}