Внесены изменения в логику формы 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>
private DrawingPlane? _drawingPlane;
private AbstractStrategy? _abstractStrategy;
/// <summary>
/// Ńňđŕňĺăč˙ ďĺđĺěĺůĺíč˙
/// </summary>
private AbstractStrategy? _strategy;
/// <summary>
/// Âűáđŕííűé ŕâňîěîáčëü
/// </summary>
public DrawingPlane? SelectedPlane { get; private set; }
/// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû
/// </summary>
public FormStormtrooper()
{
InitializeComponent();
_strategy = null;
SelectedPlane = null;
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè îáúåêòà
@ -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;
}
}
/// <summary>
/// Âűáîđ ńŕěîëĺňŕ
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSelectPlane_Click(object sender, EventArgs e)
{
SelectedPlane = _drawingPlane;
DialogResult = DialogResult.OK;
}
}
}