122 lines
3.0 KiB
C#
Raw Normal View History

2024-03-12 13:36:12 +04:00
using AirBomber.Drawnings;
using AirBomber.MovementStrategy;
namespace AirBomber;
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public partial class FormAirBomber : Form
2024-02-27 13:03:57 +04:00
{
2024-03-12 13:36:12 +04:00
/// <summary>
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private DrawningAirPlane? _drawningAirPlane;
2024-04-09 13:54:43 +04:00
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
2024-03-12 13:36:12 +04:00
private AbstractStrategy? _strategy;
2024-04-09 13:54:43 +04:00
public DrawningAirPlane SetAirPlane
{
set
{
_drawningAirPlane = value;
_drawningAirPlane.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
2024-03-12 13:36:12 +04:00
public FormAirBomber()
2024-02-27 13:03:57 +04:00
{
2024-03-12 13:36:12 +04:00
InitializeComponent();
_strategy = null;
}
private void Draw()
{
if (_drawningAirPlane == null)
{
return;
}
if (pictureBoxAirBomber.Width == 0 || pictureBoxAirBomber.Height == 0)
2024-02-27 13:03:57 +04:00
{
2024-03-12 13:36:12 +04:00
return;
2024-02-27 13:03:57 +04:00
}
2024-03-12 13:36:12 +04:00
Bitmap bpm = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
Graphics gr = Graphics.FromImage(bpm);
_drawningAirPlane?.DrawTransport(gr);
pictureBoxAirBomber.Image = bpm;
}
2024-02-27 13:03:57 +04:00
2024-03-12 13:36:12 +04:00
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningAirPlane == null)
2024-02-27 13:03:57 +04:00
{
2024-03-12 13:36:12 +04:00
return;
}
2024-02-27 13:03:57 +04:00
2024-03-12 13:36:12 +04:00
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "ButtonUp":
result = _drawningAirPlane.MoveTransport(DirectionType.Up);
break;
case "ButtonDown":
result = _drawningAirPlane.MoveTransport(DirectionType.Down);
break;
case "ButtonLeft":
result = _drawningAirPlane.MoveTransport(DirectionType.Left);
break;
case "ButtonRight":
result = _drawningAirPlane.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
2024-02-27 13:03:57 +04:00
Draw();
}
2024-03-12 13:36:12 +04:00
}
2024-02-27 13:03:57 +04:00
2024-03-12 13:36:12 +04:00
private void buttonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawningAirPlane == null)
2024-02-27 13:03:57 +04:00
{
2024-03-12 13:36:12 +04:00
return;
}
2024-02-27 13:03:57 +04:00
2024-03-12 13:36:12 +04:00
if (comboBoxStrategy.Enabled)
{
_strategy = comboBoxStrategy.SelectedIndex switch
2024-02-27 13:03:57 +04:00
{
2024-03-12 13:36:12 +04:00
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_strategy == null)
2024-02-27 13:03:57 +04:00
{
2024-03-12 13:36:12 +04:00
return;
2024-02-27 13:03:57 +04:00
}
2024-03-12 13:36:12 +04:00
_strategy.SetData(new MoveableAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
2024-02-27 13:03:57 +04:00
}
2024-03-12 13:36:12 +04:00
if (_strategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == StrategyStatus.Finish)
{
comboBoxStrategy.Enabled = true;
_strategy = null;
2024-02-27 13:03:57 +04:00
}
}
}