119 lines
3.9 KiB
C#
119 lines
3.9 KiB
C#
using ProjectAirFighter.MovementStrategy;
|
|
using ProjectAirFighter.DrawningObjects;
|
|
|
|
namespace ProjectAirFighter
|
|
{
|
|
public partial class FormAirFighter : Form
|
|
{
|
|
private DrawningAirplane? _drawningAirplane;
|
|
private AbstractStrategy? _abstractStrategy;
|
|
|
|
public FormAirFighter()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
if (_drawningAirplane == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxAirFighter.Width,
|
|
pictureBoxAirFighter.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningAirplane.DrawTransport(gr);
|
|
pictureBoxAirFighter.Image = bmp;
|
|
}
|
|
|
|
private void ButtonCreateAirplane_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
_drawningAirplane = new DrawningAirplane(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
|
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(70, 100));
|
|
|
|
Draw();
|
|
}
|
|
private void ButtonCreateAirFighter_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
_drawningAirplane = new DrawningAirFighter (random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
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)),
|
|
pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
|
|
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(70, 100));
|
|
Draw();
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningAirplane == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawningAirplane.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawningAirplane.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawningAirplane.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawningAirplane.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
private void ButtonStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningAirplane == null)
|
|
{
|
|
return;
|
|
}
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.SetData(new
|
|
DrawningObjectAirplane(_drawningAirplane), pictureBoxAirFighter.Width,
|
|
pictureBoxAirFighter.Height);
|
|
comboBoxStrategy.Enabled = false;
|
|
}
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.MakeStep();
|
|
Draw();
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_abstractStrategy = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|