2023-10-11 22:38:57 +04:00
|
|
|
using DumpTruck.DrawingObjects;
|
|
|
|
using DumpTruck.MovementStrategy;
|
|
|
|
|
2023-10-11 21:22:18 +04:00
|
|
|
namespace DumpTruck
|
|
|
|
{
|
|
|
|
public partial class FormDumpTruck : Form
|
|
|
|
{
|
2023-10-11 22:38:57 +04:00
|
|
|
private DrawingTruck? _drawingTruck;
|
|
|
|
|
2023-11-04 16:22:00 +04:00
|
|
|
private AbstractStrategy? _strategy;
|
|
|
|
|
|
|
|
public DrawingTruck? SelectedTruck { get; private set; }
|
|
|
|
|
|
|
|
public FormDumpTruck()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
_strategy = null;
|
|
|
|
SelectedTruck = null;
|
|
|
|
}
|
2023-10-11 21:22:18 +04:00
|
|
|
|
|
|
|
private void Draw()
|
|
|
|
{
|
2023-10-11 22:38:57 +04:00
|
|
|
if (_drawingTruck == null)
|
2023-10-11 21:22:18 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bitmap bmp = new(pictureBoxDumpTruck.Width,
|
|
|
|
pictureBoxDumpTruck.Height);
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
2023-10-11 22:38:57 +04:00
|
|
|
_drawingTruck.DrawTransport(gr);
|
2023-10-11 21:22:18 +04:00
|
|
|
pictureBoxDumpTruck.Image = bmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
{
|
2023-10-11 22:38:57 +04:00
|
|
|
if (_drawingTruck == null)
|
2023-10-11 21:22:18 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "buttonUp":
|
2023-10-11 22:38:57 +04:00
|
|
|
_drawingTruck.MoveTransport(Direction.Up);
|
2023-10-11 21:22:18 +04:00
|
|
|
break;
|
|
|
|
case "buttonDown":
|
2023-10-11 22:38:57 +04:00
|
|
|
_drawingTruck.MoveTransport(Direction.Down);
|
2023-10-11 21:22:18 +04:00
|
|
|
break;
|
|
|
|
case "buttonLeft":
|
2023-10-11 22:38:57 +04:00
|
|
|
_drawingTruck.MoveTransport(Direction.Left);
|
2023-10-11 21:22:18 +04:00
|
|
|
break;
|
|
|
|
case "buttonRight":
|
2023-10-11 22:38:57 +04:00
|
|
|
_drawingTruck.MoveTransport(Direction.Right);
|
2023-10-11 21:22:18 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Draw();
|
|
|
|
}
|
2023-10-11 22:38:57 +04:00
|
|
|
|
|
|
|
private void ButtonCreateDumpTruck_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Random random = new();
|
2023-11-04 16:22:00 +04:00
|
|
|
Color bodyColor = 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color dumpBoxColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
|
|
ColorDialog secondDialog = new();
|
|
|
|
if (secondDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
{
|
2023-11-04 16:38:42 +04:00
|
|
|
dumpBoxColor = secondDialog.Color;
|
2023-11-04 16:22:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Color tentColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
|
|
ColorDialog thirdDialog = new();
|
|
|
|
if (thirdDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
{
|
2023-11-04 16:38:42 +04:00
|
|
|
tentColor = thirdDialog.Color;
|
2023-11-04 16:22:00 +04:00
|
|
|
}
|
|
|
|
|
2023-10-11 22:38:57 +04:00
|
|
|
_drawingTruck = new DrawingDumpTruck(random.Next(100, 300), random.Next(1000, 3000),
|
2023-11-04 16:22:00 +04:00
|
|
|
bodyColor,
|
2023-10-11 22:38:57 +04:00
|
|
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
2023-11-04 16:22:00 +04:00
|
|
|
tentColor,
|
|
|
|
dumpBoxColor,
|
2023-10-11 22:38:57 +04:00
|
|
|
pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
|
|
|
_drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
|
|
Draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonCreateTruck_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Random random = new();
|
2023-11-04 16:22:00 +04:00
|
|
|
Color bodyColor = 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;
|
|
|
|
}
|
|
|
|
_drawingTruck = new DrawingTruck(random.Next(100, 300), random.Next(1000, 3000), bodyColor,
|
2023-10-11 22:38:57 +04:00
|
|
|
pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
|
|
|
|
_drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
|
|
Draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonStep_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (_drawingTruck == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
{
|
2023-11-04 16:22:00 +04:00
|
|
|
_strategy = comboBoxStrategy.SelectedIndex
|
2023-10-11 22:38:57 +04:00
|
|
|
switch
|
|
|
|
{
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
_ => null,
|
|
|
|
};
|
2023-11-04 16:22:00 +04:00
|
|
|
if (_strategy == null)
|
2023-10-11 22:38:57 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-11-04 16:22:00 +04:00
|
|
|
_strategy.SetData(new
|
2023-10-11 22:38:57 +04:00
|
|
|
DrawningObjectTruck(_drawingTruck), pictureBoxDumpTruck.Width,
|
|
|
|
pictureBoxDumpTruck.Height);
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
}
|
2023-11-04 16:22:00 +04:00
|
|
|
if (_strategy == null)
|
2023-10-11 22:38:57 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-11-04 16:22:00 +04:00
|
|
|
_strategy.MakeStep();
|
2023-10-11 22:38:57 +04:00
|
|
|
Draw();
|
2023-11-04 16:22:00 +04:00
|
|
|
if (_strategy.GetStatus() == Status.Finish)
|
2023-10-11 22:38:57 +04:00
|
|
|
{
|
|
|
|
comboBoxStrategy.Enabled = true;
|
2023-11-04 16:22:00 +04:00
|
|
|
_strategy = null;
|
2023-10-11 22:38:57 +04:00
|
|
|
}
|
|
|
|
}
|
2023-11-04 16:22:00 +04:00
|
|
|
|
|
|
|
private void buttonSelectTruck_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
SelectedTruck = _drawingTruck;
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
}
|
2023-10-11 22:38:57 +04:00
|
|
|
}
|
2023-10-11 21:22:18 +04:00
|
|
|
}
|