2024-03-02 13:16:19 +04:00
|
|
|
|
using ProjectAirFighter.Drawnings;
|
2024-03-07 11:14:56 +04:00
|
|
|
|
using ProjectAirFighter.MovementStrategy;
|
2024-03-02 13:16:19 +04:00
|
|
|
|
|
|
|
|
|
namespace ProjectAirFighter;
|
2024-02-22 13:12:50 +04:00
|
|
|
|
|
|
|
|
|
public partial class FormAirFighter : Form
|
|
|
|
|
{
|
2024-04-07 18:12:35 +04:00
|
|
|
|
private DrawningMilitaryAircraft? _drawningMilitaryAircraft;
|
2024-02-22 13:12:50 +04:00
|
|
|
|
|
2024-03-07 11:14:56 +04:00
|
|
|
|
private AbstractStrategy? _strategy;
|
|
|
|
|
|
2024-02-22 13:12:50 +04:00
|
|
|
|
public FormAirFighter()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-03-07 11:14:56 +04:00
|
|
|
|
_strategy = null;
|
2024-02-22 13:12:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 18:12:35 +04:00
|
|
|
|
public DrawningMilitaryAircraft SetAir
|
2024-02-22 13:12:50 +04:00
|
|
|
|
{
|
2024-04-07 18:12:35 +04:00
|
|
|
|
set
|
2024-02-22 13:12:50 +04:00
|
|
|
|
{
|
2024-04-07 18:12:35 +04:00
|
|
|
|
_drawningMilitaryAircraft = value;
|
|
|
|
|
_drawningMilitaryAircraft.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_strategy = null;
|
|
|
|
|
Draw();
|
2024-02-22 13:12:50 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 18:12:35 +04:00
|
|
|
|
private void Draw()
|
2024-02-22 13:12:50 +04:00
|
|
|
|
{
|
2024-04-07 18:12:35 +04:00
|
|
|
|
if (_drawningMilitaryAircraft == null)
|
2024-03-02 13:16:19 +04:00
|
|
|
|
{
|
2024-04-07 18:12:35 +04:00
|
|
|
|
return;
|
2024-03-02 13:16:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 18:12:35 +04:00
|
|
|
|
Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_drawningMilitaryAircraft.DrawTransport(gr);
|
|
|
|
|
pictureBoxAirFighter.Image = bmp;
|
2024-02-22 13:12:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-04-07 18:12:35 +04:00
|
|
|
|
if (_drawningMilitaryAircraft == null)
|
2024-02-22 13:12:50 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
bool result = false;
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
2024-04-07 18:12:35 +04:00
|
|
|
|
result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Up);
|
2024-02-22 13:12:50 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
2024-04-07 18:12:35 +04:00
|
|
|
|
result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Down);
|
2024-02-22 13:12:50 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
2024-04-07 18:12:35 +04:00
|
|
|
|
result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Left);
|
2024-02-22 13:12:50 +04:00
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
2024-04-07 18:12:35 +04:00
|
|
|
|
result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Right);
|
2024-02-22 13:12:50 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-07 11:14:56 +04:00
|
|
|
|
|
|
|
|
|
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-04-07 18:12:35 +04:00
|
|
|
|
if (_drawningMilitaryAircraft == null)
|
2024-03-07 11:14:56 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
|
{
|
|
|
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
|
|
|
{
|
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
if (_strategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-07 18:12:35 +04:00
|
|
|
|
_strategy.SetData(new MoveableMilitaryAircraft(_drawningMilitaryAircraft), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
2024-03-07 11:14:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_strategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
|
_strategy.MakeStep();
|
|
|
|
|
Draw();
|
|
|
|
|
|
|
|
|
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
|
|
|
{
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_strategy = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-22 13:12:50 +04:00
|
|
|
|
}
|