2023-10-06 21:35:14 +04:00
|
|
|
|
using RoadTrain.MovementStrategy;
|
|
|
|
|
using RoadTrain.DrawningObjects;
|
2023-10-10 22:08:33 +04:00
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
2023-10-06 21:35:14 +04:00
|
|
|
|
|
|
|
|
|
|
2023-10-05 21:52:23 +04:00
|
|
|
|
namespace RoadTrain
|
|
|
|
|
{
|
|
|
|
|
public partial class FormRoadTrain : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private DrawningRoadTrain? _drawningRoadTrain;
|
2023-10-06 21:35:14 +04:00
|
|
|
|
|
|
|
|
|
private AbstractStrategy? _abstractStrategy;
|
2023-10-10 22:08:33 +04:00
|
|
|
|
public DrawningRoadTrain? SelectedTrain { get; private set; }
|
|
|
|
|
|
2023-10-05 21:52:23 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormRoadTrain()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-10-10 22:08:33 +04:00
|
|
|
|
_abstractStrategy = null;
|
|
|
|
|
SelectedTrain = null;
|
2023-10-05 21:52:23 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
|
|
|
|
if (_drawningRoadTrain == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Bitmap bmp = new(pictureBoxRoadTrain.Width,
|
|
|
|
|
pictureBoxRoadTrain.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_drawningRoadTrain.DrawTransport(gr);
|
|
|
|
|
pictureBoxRoadTrain.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningRoadTrain == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
|
|
|
|
_drawningRoadTrain.MoveTransport(DirectionType.Up);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
|
|
|
|
_drawningRoadTrain.MoveTransport(DirectionType.Down);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
|
|
|
|
_drawningRoadTrain.MoveTransport(DirectionType.Left);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
|
|
|
|
_drawningRoadTrain.MoveTransport(DirectionType.Right);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-06 21:35:14 +04:00
|
|
|
|
|
2023-10-05 21:52:23 +04:00
|
|
|
|
|
|
|
|
|
|
2023-10-06 21:35:14 +04:00
|
|
|
|
private void ButtonStep_Click_1(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningRoadTrain == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
|
{
|
|
|
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
|
|
|
switch
|
|
|
|
|
{
|
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_abstractStrategy.SetData(new
|
|
|
|
|
DrawningObjectTrain(_drawningRoadTrain), pictureBoxRoadTrain.Width,
|
|
|
|
|
pictureBoxRoadTrain.Height);
|
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_abstractStrategy.MakeStep();
|
|
|
|
|
Draw();
|
|
|
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
|
|
|
{
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_abstractStrategy = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-10 22:08:33 +04:00
|
|
|
|
|
|
|
|
|
private void ButtonCreateRoadTrain_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;
|
|
|
|
|
}
|
|
|
|
|
_drawningRoadTrain = new DrawningRoadTrain(random.Next(100, 300),
|
|
|
|
|
random.Next(1000, 3000), color,
|
|
|
|
|
pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
|
|
|
|
|
_drawningRoadTrain.SetPosition(random.Next(10, 100), random.Next(10,
|
|
|
|
|
100));
|
|
|
|
|
Draw();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonCreateTrain_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;
|
|
|
|
|
}
|
|
|
|
|
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
|
|
|
|
random.Next(0, 256), random.Next(0, 256));
|
|
|
|
|
ColorDialog dialog2 = new();
|
|
|
|
|
if (dialog2.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
color = dialog2.Color;
|
|
|
|
|
}
|
|
|
|
|
_drawningRoadTrain = new DrawningTrain(random.Next(100, 300),
|
|
|
|
|
random.Next(1000, 3000), color,
|
|
|
|
|
dopColor, Convert.ToBoolean(random.Next(0, 2)),
|
|
|
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
|
|
|
pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
|
|
|
|
|
_drawningRoadTrain.SetPosition(random.Next(10, 100), random.Next(10,
|
|
|
|
|
100));
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonSelectTrain_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SelectedTrain = _drawningRoadTrain;
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
2023-10-05 21:52:23 +04:00
|
|
|
|
}
|
2023-10-06 21:35:14 +04:00
|
|
|
|
}
|