138 lines
4.6 KiB
C#
138 lines
4.6 KiB
C#
namespace Catamaran
|
|
{
|
|
public partial class FormCatamaran : Form
|
|
{
|
|
public FormCatamaran()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private DrawningCatamaran? _DrawningCatamaran;
|
|
private AbstractStrategy? _abstractStrategy;
|
|
public DrawningCatamaran? SelectedCatamaran { get; private set; }
|
|
|
|
private void Draw()
|
|
{
|
|
if (_DrawningCatamaran == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_DrawningCatamaran.DrawTransport(gr);
|
|
pictureBox.Image = bmp;
|
|
}
|
|
|
|
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();
|
|
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));
|
|
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
bodyColor = dialog.Color;
|
|
}
|
|
_DrawningCatamaran = new DrawningCatamaran(random.Next(10, 30), random.Next(100, 300), bodyColor, pictureBox.Width, pictureBox.Height);
|
|
|
|
_DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
|
|
}
|
|
|
|
private void buttonCreatePro_Click(object sender, EventArgs e)
|
|
{
|
|
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));
|
|
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
bodyColor = dialog.Color;
|
|
}
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
additionalColor = dialog.Color;
|
|
}
|
|
|
|
_DrawningCatamaran = new DrawningCatamaranPro(random.Next(100, 300),
|
|
random.Next(1000, 3000), bodyColor, additionalColor, true, true, true, pictureBox.Width, pictureBox.Height);
|
|
_DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
|
|
}
|
|
|
|
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
|
|
DrawningObjectCatamaran(_DrawningCatamaran), pictureBox.Width,
|
|
pictureBox.Height);
|
|
comboBox.Enabled = false;
|
|
}
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.MakeStep();
|
|
Draw();
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBox.Enabled = true;
|
|
_abstractStrategy = null;
|
|
}
|
|
}
|
|
|
|
private void buttonSelect_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedCatamaran = _DrawningCatamaran;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
|
|
} |