PIbd-23-Radaev-A.V.-20/Catamaran/FormCatamaran.cs

138 lines
4.6 KiB
C#
Raw Normal View History

2023-10-31 12:23:01 +04:00
namespace Catamaran
{
public partial class FormCatamaran : Form
{
public FormCatamaran()
{
InitializeComponent();
}
private DrawningCatamaran? _DrawningCatamaran;
2023-10-31 12:27:43 +04:00
private AbstractStrategy? _abstractStrategy;
2023-11-12 11:28:15 +04:00
public DrawningCatamaran? SelectedCatamaran { get; private set; }
2023-10-31 12:23:01 +04:00
private void Draw()
{
if (_DrawningCatamaran == null)
{
return;
}
2023-11-25 20:02:11 +04:00
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
2023-10-31 12:23:01 +04:00
Graphics gr = Graphics.FromImage(bmp);
_DrawningCatamaran.DrawTransport(gr);
2023-11-25 20:02:11 +04:00
pictureBox.Image = bmp;
2023-10-31 12:23:01 +04:00
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_DrawningCatamaran == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_DrawningCatamaran.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_DrawningCatamaran.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_DrawningCatamaran.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_DrawningCatamaran.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
2023-10-31 12:27:43 +04:00
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
2023-11-12 11:28:15 +04:00
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
bodyColor = dialog.Color;
}
2023-11-25 20:02:11 +04:00
_DrawningCatamaran = new DrawningCatamaran(random.Next(10, 30), random.Next(100, 300), bodyColor, pictureBox.Width, pictureBox.Height);
2023-10-31 12:23:01 +04:00
_DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
2023-10-31 12:27:43 +04:00
2023-10-31 12:23:01 +04:00
}
2023-10-31 12:27:43 +04:00
private void buttonCreatePro_Click(object sender, EventArgs e)
2023-10-31 12:23:01 +04:00
{
2023-10-31 12:27:43 +04:00
Random random = new();
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color otherColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
2023-11-12 11:28:15 +04:00
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
bodyColor = dialog.Color;
}
if (dialog.ShowDialog() == DialogResult.OK)
{
additionalColor = dialog.Color;
}
2023-11-25 20:02:11 +04:00
2023-10-31 12:27:43 +04:00
_DrawningCatamaran = new DrawningCatamaranPro(random.Next(100, 300),
2023-11-25 20:02:11 +04:00
random.Next(1000, 3000), bodyColor, additionalColor, true, true, true, pictureBox.Width, pictureBox.Height);
2023-10-31 12:27:43 +04:00
_DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
2023-10-31 12:23:01 +04:00
}
2023-10-31 12:27:43 +04:00
private void buttonStep_Click(object sender, EventArgs e)
{
if (_DrawningCatamaran == null)
{
return;
}
if (comboBox.Enabled)
{
_abstractStrategy = comboBox.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToRightBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new
2023-11-25 20:02:11 +04:00
DrawningObjectCatamaran(_DrawningCatamaran), pictureBox.Width,
pictureBox.Height);
2023-10-31 12:27:43 +04:00
comboBox.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBox.Enabled = true;
_abstractStrategy = null;
}
}
2023-11-12 11:28:15 +04:00
private void buttonSelect_Click(object sender, EventArgs e)
{
SelectedCatamaran = _DrawningCatamaran;
DialogResult = DialogResult.OK;
}
2023-10-31 12:27:43 +04:00
}
2023-11-12 11:28:15 +04:00
2023-10-31 12:23:01 +04:00
}