Внесены изменения в логику формы FormStormtrooper

This commit is contained in:
Никита Потапов 2023-10-08 12:45:40 +04:00
parent b1a2751514
commit 854b4ac296

View File

@ -9,13 +9,22 @@ namespace ProjectStormtrooper
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà /// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary> /// </summary>
private DrawingPlane? _drawingPlane; private DrawingPlane? _drawingPlane;
private AbstractStrategy? _abstractStrategy; /// <summary>
/// Ńňđŕňĺăč˙ ďĺđĺěĺůĺíč˙
/// </summary>
private AbstractStrategy? _strategy;
/// <summary>
/// Âűáđŕííűé ŕâňîěîáčëü
/// </summary>
public DrawingPlane? SelectedPlane { get; private set; }
/// <summary> /// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû /// Èíèöèàëèçàöèÿ ôîðìû
/// </summary> /// </summary>
public FormStormtrooper() public FormStormtrooper()
{ {
InitializeComponent(); InitializeComponent();
_strategy = null;
SelectedPlane = null;
} }
/// <summary> /// <summary>
/// Ìåòîä ïðîðèñîâêè îáúåêòà /// Ìåòîä ïðîðèñîâêè îáúåêòà
@ -39,11 +48,23 @@ namespace ProjectStormtrooper
private void buttonCreateStormtrooper_Click(object sender, EventArgs e) private void buttonCreateStormtrooper_Click(object sender, EventArgs e)
{ {
Random random = new(); 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( _drawingPlane = new DrawingStormtrooper(
random.Next(100, 300), random.Next(100, 300),
random.Next(1000, 3000), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), color,
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), dopColor,
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Width,
@ -60,10 +81,16 @@ namespace ProjectStormtrooper
private void buttonCreatePlane_Click(object sender, EventArgs e) private void buttonCreatePlane_Click(object sender, EventArgs e)
{ {
Random random = new(); 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( _drawingPlane = new DrawingPlane(
random.Next(100, 300), random.Next(100, 300),
random.Next(1000, 3000), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), color,
pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Width,
pictureBoxStormtrooper.Height pictureBoxStormtrooper.Height
); );
@ -112,30 +139,40 @@ namespace ProjectStormtrooper
} }
if (comboBoxStrategy.Enabled) if (comboBoxStrategy.Enabled)
{ {
_abstractStrategy = comboBoxStrategy.SelectedIndex switch _strategy = comboBoxStrategy.SelectedIndex switch
{ {
0 => new MoveToCenter(), 0 => new MoveToCenter(),
1 => new MoveToRightBottom(), 1 => new MoveToRightBottom(),
_ => null, _ => null,
}; };
if (_abstractStrategy == null) if (_strategy == null)
{ {
return; return;
} }
_abstractStrategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height); _strategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
comboBoxStrategy.Enabled = false;
} }
if (_abstractStrategy == null) if (_strategy == null)
{ {
return; return;
} }
_abstractStrategy.MakeStep(); comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw(); Draw();
if (_abstractStrategy.GetStatus() == Status.Finish) if (_strategy.GetStatus() == Status.Finish)
{ {
comboBoxStrategy.Enabled = true; comboBoxStrategy.Enabled = true;
_abstractStrategy = null; _strategy = null;
} }
} }
/// <summary>
/// Âűáîđ ńŕěîëĺňŕ
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSelectPlane_Click(object sender, EventArgs e)
{
SelectedPlane = _drawingPlane;
DialogResult = DialogResult.OK;
}
} }
} }