2024-03-09 20:03:38 +04:00
|
|
|
|
using ProjectMonorail.Scripts.Monorail.Drawnings;
|
2024-03-10 13:50:57 +04:00
|
|
|
|
using ProjectMonorail.Scripts.Monorail.MovementStrategy;
|
2024-02-12 00:08:06 +04:00
|
|
|
|
|
|
|
|
|
namespace ProjectMonorail
|
|
|
|
|
{
|
2024-03-10 13:50:57 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с объектом "Монорельс"
|
|
|
|
|
/// </summary>
|
2024-02-12 00:08:06 +04:00
|
|
|
|
public partial class FormMonorail : Form
|
|
|
|
|
{
|
2024-03-10 13:50:57 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Поле-объект для прорисовки объекта
|
|
|
|
|
/// </summary>
|
2024-03-09 20:03:38 +04:00
|
|
|
|
private DrawingMonorail? _drawningMonorail;
|
2024-02-12 00:08:06 +04:00
|
|
|
|
|
2024-03-10 13:50:57 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Стратегия перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractStrategy? _strategy;
|
|
|
|
|
|
2024-03-10 19:05:31 +04:00
|
|
|
|
public DrawingMonorail SetMonorail
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_drawningMonorail = value;
|
|
|
|
|
_drawningMonorail.SetPictureSize(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
_drawningMonorail.SetPosition(random.Next(0, 100), random.Next(0, 100));
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_strategy = null;
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-10 13:50:57 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор формы
|
|
|
|
|
/// </summary>
|
2024-02-12 00:08:06 +04:00
|
|
|
|
public FormMonorail()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-03-10 13:50:57 +04:00
|
|
|
|
_strategy = null;
|
2024-02-12 00:08:06 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Метод для прорисовки автомобиля
|
|
|
|
|
/// </summary>
|
2024-03-09 20:03:38 +04:00
|
|
|
|
private void Draw()
|
2024-02-12 00:08:06 +04:00
|
|
|
|
{
|
|
|
|
|
if (_drawningMonorail == null) return;
|
|
|
|
|
|
|
|
|
|
Bitmap bmp = new(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_drawningMonorail.DrawTransport(gr);
|
|
|
|
|
pictureBoxMonorail.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка кнопок перемешения
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningMonorail == null) return;
|
|
|
|
|
|
|
|
|
|
string name = ((Button)sender).Name ?? string.Empty;
|
|
|
|
|
bool result = false;
|
2024-03-09 20:03:38 +04:00
|
|
|
|
switch (name)
|
2024-02-12 00:08:06 +04:00
|
|
|
|
{
|
|
|
|
|
case "buttonMove_Up":
|
2024-03-09 20:03:38 +04:00
|
|
|
|
result = _drawningMonorail.MoveTransport(DirectionType.Up);
|
2024-02-12 00:08:06 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonMove_Down":
|
2024-03-09 20:03:38 +04:00
|
|
|
|
result = _drawningMonorail.MoveTransport(DirectionType.Down);
|
2024-02-12 00:08:06 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonMove_Right":
|
2024-03-09 20:03:38 +04:00
|
|
|
|
result = _drawningMonorail.MoveTransport(DirectionType.Right);
|
2024-02-12 00:08:06 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonMove_Left":
|
2024-03-09 20:03:38 +04:00
|
|
|
|
result = _drawningMonorail.MoveTransport(DirectionType.Left);
|
2024-02-12 00:08:06 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result) Draw();
|
|
|
|
|
}
|
2024-03-09 20:03:38 +04:00
|
|
|
|
|
2024-03-10 13:50:57 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningMonorail == null) return;
|
|
|
|
|
|
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
|
{
|
|
|
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
|
|
|
{
|
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
|
1 => new MoveToRightDownBorder(),
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
if (_strategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_strategy.SetData(new MoveableMonorail(_drawningMonorail), pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_strategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
|
_strategy.MakeStep();
|
|
|
|
|
Draw();
|
|
|
|
|
|
|
|
|
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
|
|
|
{
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_strategy = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-12 00:08:06 +04:00
|
|
|
|
}
|
|
|
|
|
}
|