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;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Стратегия перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractStrategy? _strategy;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор формы
|
|
|
|
|
/// </summary>
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-03-05 09:00:55 +04:00
|
|
|
|
/// Создание объекта класса-перемещения
|
2024-02-18 18:45:41 +04:00
|
|
|
|
/// </summary>
|
2024-03-05 09:00:55 +04:00
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
private void CreateObject(string type)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
|
|
|
|
Random random = new();
|
2024-03-05 09:00:55 +04:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case nameof(DrawingStormtrooper):
|
|
|
|
|
_drawningStormtrooperBase = new DrawingStormtrooper(random.Next(100, 300), random.Next(1000, 3000),
|
2024-02-18 18:45:41 +04:00
|
|
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
|
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
|
|
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
2024-03-05 09:00:55 +04:00
|
|
|
|
break;
|
2024-03-09 20:45:03 +04:00
|
|
|
|
case nameof(DrawningStormtrooperBase):
|
|
|
|
|
_drawningStormtrooperBase = new DrawningStormtrooperBase(random.Next(100, 300), random.Next(1000, 3000),
|
2024-03-05 09:00:55 +04:00
|
|
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
|
2024-03-05 09:00:55 +04:00
|
|
|
|
}
|
|
|
|
|
_drawningStormtrooperBase.SetPictureSize(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
|
|
|
|
_drawningStormtrooperBase.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
2024-03-09 20:45:03 +04:00
|
|
|
|
_strategy = null;
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
Draw();
|
2024-03-05 09:00:55 +04:00
|
|
|
|
|
2024-02-18 18:45:41 +04:00
|
|
|
|
}
|
2024-03-05 09:00:55 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия кнопки "Создать штурмовик"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCreateStormtrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingStormtrooper));
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия кнопки "Создать базовый штурмовик"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-09 20:45:03 +04:00
|
|
|
|
private void ButtonCreateStormtrooperBase_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooperBase));
|
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-03-09 20:45:03 +04:00
|
|
|
|
|