From 854b4ac29610a2e3152af37f32f182354a8d8acd Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 8 Oct 2023 12:45:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D1=8B=20FormStormtrooper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectStormtrooper/FormStormtrooper.cs | 61 +++++++++++++++---- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs index 96fc949..98fdfb0 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs @@ -9,13 +9,22 @@ namespace ProjectStormtrooper /// Поле-объект для прорисовки объекта /// private DrawingPlane? _drawingPlane; - private AbstractStrategy? _abstractStrategy; + /// + /// Стратегия перемещения + /// + private AbstractStrategy? _strategy; + /// + /// Выбранный автомобиль + /// + public DrawingPlane? SelectedPlane { get; private set; } /// /// Инициализация формы /// public FormStormtrooper() { InitializeComponent(); + _strategy = null; + SelectedPlane = null; } /// /// Метод прорисовки объекта @@ -39,11 +48,23 @@ namespace ProjectStormtrooper private void buttonCreateStormtrooper_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)); + dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + dopColor = dialog.Color; + } _drawingPlane = new DrawingStormtrooper( 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)), + color, + dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxStormtrooper.Width, @@ -60,10 +81,16 @@ namespace ProjectStormtrooper private void buttonCreatePlane_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; + } _drawingPlane = new DrawingPlane( random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + color, pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height ); @@ -112,30 +139,40 @@ namespace ProjectStormtrooper } if (comboBoxStrategy.Enabled) { - _abstractStrategy = comboBoxStrategy.SelectedIndex switch + _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToRightBottom(), _ => null, }; - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); - comboBoxStrategy.Enabled = false; + _strategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.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 ButtonSelectPlane_Click(object sender, EventArgs e) + { + SelectedPlane = _drawingPlane; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file