2024-05-07 01:50:39 +04:00
|
|
|
|
using ProjectStormtrooper.Drawnings;
|
|
|
|
|
using ProjectStormtrooper.MovementStrategy;
|
2024-03-13 03:15:49 +04:00
|
|
|
|
|
|
|
|
|
namespace ProjectStormtrooper;
|
|
|
|
|
|
2024-05-07 01:50:39 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с объектом "Штурмовик"
|
|
|
|
|
/// </summary>
|
2024-03-13 03:15:49 +04:00
|
|
|
|
public partial class FormStormtrooper : Form
|
|
|
|
|
{
|
2024-05-07 01:50:39 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Поле-объект для прорисовки объекта
|
|
|
|
|
/// </summary>
|
2024-03-27 12:51:26 +04:00
|
|
|
|
private DrawningAirplane? _drawningAirplane;
|
|
|
|
|
|
2024-05-07 01:50:39 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Стратегия перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractStrategy? _strategy;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DrawningAirplane SetAirplane
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_drawningAirplane = value;
|
|
|
|
|
_drawningAirplane.SetPictureSize(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_strategy = null;
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор формы
|
|
|
|
|
/// </summary>
|
2024-03-13 03:15:49 +04:00
|
|
|
|
public FormStormtrooper()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-07 01:50:39 +04:00
|
|
|
|
_strategy = null;
|
2024-03-13 03:15:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Метод прорисовки машины
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
2024-03-27 12:51:26 +04:00
|
|
|
|
if (_drawningAirplane == null)
|
2024-03-13 03:15:49 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-27 12:51:26 +04:00
|
|
|
|
Bitmap bmp = new(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
2024-03-13 03:15:49 +04:00
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
2024-03-27 12:51:26 +04:00
|
|
|
|
_drawningAirplane.DrawTransport(gr);
|
2024-03-13 03:15:49 +04:00
|
|
|
|
pictureBoxStormtrooper.Image = bmp;
|
|
|
|
|
}
|
2024-03-27 12:51:26 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-13 03:15:49 +04:00
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-03-27 12:51:26 +04:00
|
|
|
|
if (_drawningAirplane == null)
|
2024-03-13 03:15:49 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
bool result = false;
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
|
|
|
|
result =
|
2024-03-27 12:51:26 +04:00
|
|
|
|
_drawningAirplane.MoveTransport(DirectionType.Up);
|
2024-03-13 03:15:49 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
|
|
|
|
result =
|
2024-03-27 12:51:26 +04:00
|
|
|
|
_drawningAirplane.MoveTransport(DirectionType.Down);
|
2024-03-13 03:15:49 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
|
|
|
|
result =
|
2024-03-27 12:51:26 +04:00
|
|
|
|
_drawningAirplane.MoveTransport(DirectionType.Left);
|
2024-03-13 03:15:49 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
|
|
|
|
result =
|
2024-03-27 12:51:26 +04:00
|
|
|
|
_drawningAirplane.MoveTransport(DirectionType.Right);
|
2024-03-13 03:15:49 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 12:51:26 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия кнопки "Шаг"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-05-07 01:50:39 +04:00
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningAirplane == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
|
{
|
|
|
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
|
|
|
{
|
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
if (_strategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_strategy.SetData(new MoveableAirplane(_drawningAirplane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_strategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
|
_strategy.MakeStep();
|
|
|
|
|
Draw();
|
2024-03-27 12:51:26 +04:00
|
|
|
|
|
2024-05-07 01:50:39 +04:00
|
|
|
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
|
|
|
{
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_strategy = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-13 03:15:49 +04:00
|
|
|
|
}
|