ISEbd-12_Paramonova_I.A._Si.../AirFighter/AirFighter/FormAirFighter.cs

111 lines
2.9 KiB
C#
Raw Normal View History

using ProjectAirFighter.Drawnings;
using ProjectAirFighter.MovementStrategy;
namespace ProjectAirFighter;
2024-02-22 13:12:50 +04:00
public partial class FormAirFighter : Form
{
private DrawningMilitaryAircraft? _drawningMilitaryAircraft;
2024-02-22 13:12:50 +04:00
private AbstractStrategy? _strategy;
2024-02-22 13:12:50 +04:00
public FormAirFighter()
{
InitializeComponent();
_strategy = null;
2024-02-22 13:12:50 +04:00
}
public DrawningMilitaryAircraft SetAir
2024-02-22 13:12:50 +04:00
{
set
2024-02-22 13:12:50 +04:00
{
_drawningMilitaryAircraft = value;
_drawningMilitaryAircraft.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
2024-02-22 13:12:50 +04:00
}
}
private void Draw()
2024-02-22 13:12:50 +04:00
{
if (_drawningMilitaryAircraft == null)
{
return;
}
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)
{
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":
result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Up);
2024-02-22 13:12:50 +04:00
break;
case "buttonDown":
result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Down);
2024-02-22 13:12:50 +04:00
break;
case "buttonLeft":
result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Left);
2024-02-22 13:12:50 +04:00
break;
case "buttonRight":
result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Right);
2024-02-22 13:12:50 +04:00
break;
}
if (result)
{
Draw();
}
}
private void ButtonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawningMilitaryAircraft == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_strategy == null)
{
return;
}
_strategy.SetData(new MoveableMilitaryAircraft(_drawningMilitaryAircraft), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
}
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
}