2023-11-23 01:37:55 +04:00
|
|
|
using ProjectBulldozer;
|
2023-11-30 02:09:48 +04:00
|
|
|
using ProjectBulldozer.Drawning;
|
2023-11-23 01:37:55 +04:00
|
|
|
using ProjectBulldozer.MovementStrategy;
|
|
|
|
namespace Bulldozer
|
2023-11-22 22:38:41 +04:00
|
|
|
{
|
2023-11-30 02:09:48 +04:00
|
|
|
public partial class FormBulldozer : Form
|
2023-11-22 22:38:41 +04:00
|
|
|
{
|
2023-11-23 01:37:55 +04:00
|
|
|
private DrawingTractor? _drawingTractor;
|
|
|
|
private AbstractStrategy? _abstractStrategy;
|
2023-11-30 02:09:48 +04:00
|
|
|
public DrawingTractor? SelectedTractor { get; private set; }
|
|
|
|
public FormBulldozer()
|
2023-11-22 22:38:41 +04:00
|
|
|
{
|
|
|
|
InitializeComponent();
|
2023-11-30 02:09:48 +04:00
|
|
|
_abstractStrategy = null;
|
|
|
|
SelectedTractor = null;
|
2023-11-22 22:38:41 +04:00
|
|
|
}
|
2023-11-22 23:04:45 +04:00
|
|
|
private void Draw()
|
|
|
|
{
|
2023-11-23 01:37:55 +04:00
|
|
|
if (_drawingTractor == null)
|
2023-11-22 23:04:45 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-11-23 01:37:55 +04:00
|
|
|
Bitmap bmp = new(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
2023-11-22 23:04:45 +04:00
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
2023-11-23 01:37:55 +04:00
|
|
|
_drawingTractor.DrawTransport(gr);
|
2023-11-22 23:04:45 +04:00
|
|
|
pictureBoxBulldozer.Image = bmp;
|
|
|
|
}
|
2023-11-23 01:37:55 +04:00
|
|
|
private void buttonCreateBulldozer_Click(object sender, EventArgs e)
|
2023-11-22 23:04:45 +04:00
|
|
|
{
|
2023-11-23 01:37:55 +04:00
|
|
|
Random random = new Random();
|
2023-11-30 02:09:48 +04:00
|
|
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
2023-11-30 03:15:19 +04:00
|
|
|
|
2023-11-30 02:09:48 +04:00
|
|
|
ColorDialog colorDialog = new ColorDialog();
|
2023-11-30 03:15:19 +04:00
|
|
|
|
2023-11-30 02:09:48 +04:00
|
|
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
{
|
|
|
|
color = colorDialog.Color;
|
|
|
|
}
|
|
|
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
|
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
{
|
|
|
|
dopColor = colorDialog.Color;
|
|
|
|
}
|
|
|
|
_drawingTractor = new DrawingBulldozer(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
2023-11-23 01:37:55 +04:00
|
|
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
2023-11-22 23:04:45 +04:00
|
|
|
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
2023-11-23 01:37:55 +04:00
|
|
|
_drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
|
|
Draw();
|
|
|
|
}
|
|
|
|
private void buttonCreateTractor_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Random rnd = new Random();
|
2023-11-30 02:09:48 +04:00
|
|
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
|
|
|
ColorDialog colorDialog = new ColorDialog();
|
|
|
|
if (colorDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
{
|
|
|
|
color = colorDialog.Color;
|
|
|
|
}
|
|
|
|
_drawingTractor = new DrawingTractor(rnd.Next(100, 300), rnd.Next(1000, 3000), color,
|
2023-11-23 01:37:55 +04:00
|
|
|
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
|
|
|
_drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
2023-11-22 23:04:45 +04:00
|
|
|
Draw();
|
|
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
|
|
{
|
2023-11-23 01:37:55 +04:00
|
|
|
if (_drawingTractor == null)
|
2023-11-22 23:04:45 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "buttonUp":
|
2023-11-23 01:37:55 +04:00
|
|
|
_drawingTractor.MoveTransport(DirectionType.Up);
|
2023-11-22 23:04:45 +04:00
|
|
|
break;
|
|
|
|
case "buttonDown":
|
2023-11-23 01:37:55 +04:00
|
|
|
_drawingTractor.MoveTransport(DirectionType.Down);
|
2023-11-22 23:04:45 +04:00
|
|
|
break;
|
|
|
|
case "buttonLeft":
|
2023-11-23 01:37:55 +04:00
|
|
|
_drawingTractor.MoveTransport(DirectionType.Left);
|
2023-11-22 23:04:45 +04:00
|
|
|
break;
|
|
|
|
case "buttonRight":
|
2023-11-23 01:37:55 +04:00
|
|
|
_drawingTractor.MoveTransport(DirectionType.Right);
|
2023-11-22 23:04:45 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Draw();
|
|
|
|
}
|
2023-11-23 01:37:55 +04:00
|
|
|
private void buttonStep_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (_drawingTractor == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
{
|
|
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
|
|
|
|
{
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
1 => new MoveToRightCorner(),
|
|
|
|
_ => null,
|
|
|
|
};
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-11-30 02:09:48 +04:00
|
|
|
_abstractStrategy.SetData(_drawingTractor.GetMoveableObject, pictureBoxBulldozer.Width,
|
2023-11-23 01:37:55 +04:00
|
|
|
pictureBoxBulldozer.Height);
|
|
|
|
}
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-11-30 02:09:48 +04:00
|
|
|
comboBoxStrategy.Enabled = false;
|
2023-11-23 01:37:55 +04:00
|
|
|
_abstractStrategy.MakeStep();
|
|
|
|
Draw();
|
|
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
|
|
{
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
_abstractStrategy = null;
|
|
|
|
}
|
|
|
|
}
|
2023-11-30 02:09:48 +04:00
|
|
|
private void ButtonSelect_Tractor_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
SelectedTractor = _drawingTractor;
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
}
|
2023-11-23 01:37:55 +04:00
|
|
|
}
|
|
|
|
}
|