132 lines
4.7 KiB
C#
132 lines
4.7 KiB
C#
using ProjectLainer.DrawningObjects;
|
|
using ProjectLainer.MovementStrategy;
|
|
namespace ProjectLainer
|
|
{
|
|
public partial class LainerForm : Form
|
|
{
|
|
private DrawingLainer? _drawningLainer;
|
|
private AbstractStrategy? _abstractStrategy;
|
|
private AbstractStrategy? _strategy;
|
|
public DrawingLainer? SelectedLainer { get; private set; }
|
|
public LainerForm()
|
|
{
|
|
InitializeComponent();
|
|
_strategy = null;
|
|
SelectedLainer = null;
|
|
}
|
|
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;
|
|
}
|
|
private void ButtonCreateSuperLainer_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
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;
|
|
}
|
|
_drawningLainer = new DrawningSuperLainer(random.Next(100, 300),
|
|
random.Next(1000, 3000), mainColor, additColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
|
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
private void ButtonCreate_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;
|
|
}
|
|
_drawningLainer = new DrawingLainer(random.Next(100, 300),
|
|
random.Next(1000, 3000), color,
|
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
|
_drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
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();
|
|
}
|
|
private void ButtonStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningLainer == null)
|
|
{
|
|
return;
|
|
}
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_strategy.SetData(_drawningLainer.GetMoveableObject,
|
|
pictureBoxLainer.Width, pictureBoxLainer.Height);
|
|
}
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
comboBoxStrategy.Enabled = false;
|
|
_strategy.MakeStep();
|
|
Draw();
|
|
if (_strategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_strategy = null;
|
|
}
|
|
}
|
|
private void ButtonSelectLainer_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedLainer = _drawningLainer;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
}
|