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