2023-12-08 20:11:31 +04:00
|
|
|
using ProjectLainer.DrawningObjects;
|
|
|
|
using ProjectLainer.MovementStrategy;
|
2023-12-03 18:15:35 +04:00
|
|
|
namespace ProjectLainer
|
|
|
|
{
|
|
|
|
public partial class LainerForm : Form
|
|
|
|
{
|
2023-12-08 20:11:31 +04:00
|
|
|
private DrawingLainer? _drawningLainer;
|
|
|
|
private AbstractStrategy? _abstractStrategy;
|
2023-12-08 21:15:40 +04:00
|
|
|
private AbstractStrategy? _strategy;
|
|
|
|
public DrawingLainer? SelectedLainer { get; private set; }
|
2023-12-03 18:15:35 +04:00
|
|
|
public LainerForm()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
2023-12-08 21:15:40 +04:00
|
|
|
_strategy = null;
|
|
|
|
SelectedLainer = null;
|
2023-12-03 18:15:35 +04:00
|
|
|
}
|
|
|
|
private void Draw()
|
|
|
|
{
|
|
|
|
if (_drawningLainer == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bitmap bmp = new(pictureBoxLainer.Width,
|
|
|
|
pictureBoxLainer.Height);
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
_drawningLainer.DrawTransport(gr);
|
|
|
|
pictureBoxLainer.Image = bmp;
|
|
|
|
}
|
2023-12-08 20:11:31 +04:00
|
|
|
private void ButtonCreateSuperLainer_Click(object sender, EventArgs e)
|
2023-12-03 18:15:35 +04:00
|
|
|
{
|
|
|
|
Random random = new();
|
2023-12-08 21:15:40 +04:00
|
|
|
Color mainColor = Color.FromArgb(random.Next(0, 256),
|
|
|
|
random.Next(0, 256), random.Next(0, 256));
|
|
|
|
Color additColor = Color.FromArgb(random.Next(0, 256),
|
|
|
|
random.Next(0, 256), random.Next(0, 256));
|
|
|
|
ColorDialog dialog = new();
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
{
|
|
|
|
mainColor = dialog.Color;
|
|
|
|
}
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
{
|
|
|
|
additColor = dialog.Color;
|
|
|
|
}
|
2023-12-08 20:11:31 +04:00
|
|
|
_drawningLainer = new DrawningSuperLainer(random.Next(100, 300),
|
2023-12-08 21:15:40 +04:00
|
|
|
random.Next(1000, 3000), mainColor, additColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
2023-12-03 18:15:35 +04:00
|
|
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
2023-12-08 21:15:40 +04:00
|
|
|
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
2023-12-03 18:15:35 +04:00
|
|
|
Draw();
|
|
|
|
}
|
2023-12-08 20:11:31 +04:00
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Random random = new();
|
2023-12-08 21:15:40 +04:00
|
|
|
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;
|
|
|
|
}
|
2023-12-08 20:11:31 +04:00
|
|
|
_drawningLainer = new DrawingLainer(random.Next(100, 300),
|
2023-12-08 21:15:40 +04:00
|
|
|
random.Next(1000, 3000), color,
|
2023-12-08 20:11:31 +04:00
|
|
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
2023-12-08 21:15:40 +04:00
|
|
|
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
2023-12-08 20:11:31 +04:00
|
|
|
Draw();
|
|
|
|
}
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
2023-12-03 18:15:35 +04:00
|
|
|
{
|
|
|
|
if (_drawningLainer == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "buttonUp":
|
|
|
|
_drawningLainer.MoveTransport(DirectionType.Up);
|
|
|
|
break;
|
|
|
|
case "buttonDown":
|
|
|
|
_drawningLainer.MoveTransport(DirectionType.Down);
|
|
|
|
break;
|
|
|
|
case "buttonLeft":
|
|
|
|
_drawningLainer.MoveTransport(DirectionType.Left);
|
|
|
|
break;
|
|
|
|
case "buttonRight":
|
|
|
|
_drawningLainer.MoveTransport(DirectionType.Right);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Draw();
|
|
|
|
}
|
2023-12-08 20:11:31 +04:00
|
|
|
private void ButtonStep_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (_drawningLainer == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
{
|
2023-12-08 21:15:40 +04:00
|
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
2023-12-08 20:11:31 +04:00
|
|
|
{
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
_ => null,
|
|
|
|
};
|
2023-12-08 21:15:40 +04:00
|
|
|
if (_strategy == null)
|
2023-12-08 20:11:31 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-12-08 21:15:40 +04:00
|
|
|
_strategy.SetData(_drawningLainer.GetMoveableObject,
|
|
|
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
2023-12-08 20:11:31 +04:00
|
|
|
}
|
2023-12-08 21:15:40 +04:00
|
|
|
if (_strategy == null)
|
2023-12-08 20:11:31 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-12-08 21:15:40 +04:00
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
_strategy.MakeStep();
|
2023-12-08 20:11:31 +04:00
|
|
|
Draw();
|
2023-12-08 21:15:40 +04:00
|
|
|
if (_strategy.GetStatus() == Status.Finish)
|
2023-12-08 20:11:31 +04:00
|
|
|
{
|
|
|
|
comboBoxStrategy.Enabled = true;
|
2023-12-08 21:15:40 +04:00
|
|
|
_strategy = null;
|
2023-12-08 20:11:31 +04:00
|
|
|
}
|
|
|
|
}
|
2023-12-08 21:15:40 +04:00
|
|
|
private void ButtonSelectLainer_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
SelectedLainer = _drawningLainer;
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
}
|
2023-12-03 18:15:35 +04:00
|
|
|
}
|
2023-12-08 21:15:40 +04:00
|
|
|
}
|