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-03 18:15:35 +04:00
|
|
|
public LainerForm()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
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 20:11:31 +04:00
|
|
|
_drawningLainer = new DrawningSuperLainer(random.Next(100, 300),
|
2023-12-03 18:15:35 +04:00
|
|
|
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)),
|
|
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
|
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
2023-12-08 20:11:31 +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();
|
|
|
|
_drawningLainer = new DrawingLainer(random.Next(100, 300),
|
|
|
|
random.Next(1000, 3000),
|
|
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
|
|
|
random.Next(0, 256)),
|
|
|
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
|
|
|
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10,
|
|
|
|
100));
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
|
|
switch
|
|
|
|
{
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
_ => null,
|
|
|
|
};
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_abstractStrategy.SetData(new
|
|
|
|
DrawningObjectLainer(_drawningLainer), pictureBoxLainer.Width,
|
|
|
|
pictureBoxLainer.Height);
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
}
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_abstractStrategy.MakeStep();
|
|
|
|
Draw();
|
|
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
|
|
{
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
_abstractStrategy = null;
|
|
|
|
}
|
|
|
|
}
|
2023-12-03 18:15:35 +04:00
|
|
|
}
|
|
|
|
}
|