135 lines
4.4 KiB
C#
135 lines
4.4 KiB
C#
using ProjectAirbus.Drawnings;
|
|
using ProjectAirbus.MovementStrategy;
|
|
using ProjectAirbus.Entities;
|
|
|
|
namespace ProjectAirbus
|
|
{
|
|
public partial class FormAirbus : Form
|
|
{
|
|
private DrawningAirbus? _drawningAirbus;
|
|
private AbstractStrategy? _abstractStrategy;
|
|
|
|
public FormAirbus()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
// прорисовка самолёта
|
|
private void Draw()
|
|
{
|
|
if (_drawningAirbus == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureAirBus.Width, pictureAirBus.Height);
|
|
Graphics g = Graphics.FromImage(bmp);
|
|
_drawningAirbus.DrawTransport(g);
|
|
pictureAirBus.Image = bmp;
|
|
}
|
|
|
|
private void buttonDown_Click(object sender, EventArgs e)
|
|
{
|
|
buttonMove_Click(sender, e);
|
|
}
|
|
|
|
private void buttonUp_Click(object sender, EventArgs e)
|
|
{
|
|
buttonMove_Click(sender, e);
|
|
}
|
|
|
|
private void buttonRight_Click(object sender, EventArgs e)
|
|
{
|
|
buttonMove_Click(sender, e);
|
|
}
|
|
|
|
private void buttonLeft_Click(object sender, EventArgs e)
|
|
{
|
|
buttonMove_Click(sender, e);
|
|
}
|
|
|
|
// кнопка "Создать самолёт"
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new Random();
|
|
_drawningAirbus = new DrawningAirbus(random.Next(200, 400), random.Next(1000, 3000),
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
pictureAirBus.Width, pictureAirBus.Height);
|
|
|
|
_drawningAirbus.SetPosition(random.Next(10, 200), random.Next(10, 200));
|
|
Draw();
|
|
|
|
}
|
|
|
|
// кнопка "Создать суперсамолёт"
|
|
private void buttonCreateSuperAirbus_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new Random();
|
|
_drawningAirbus = new DrawningPlane(random.Next(200, 400), 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)),
|
|
pictureAirBus.Width, pictureAirBus.Height);
|
|
|
|
_drawningAirbus.SetPosition(random.Next(10, 200), random.Next(10, 200));
|
|
Draw();
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningAirbus == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawningAirbus.MoveTransport(DirectionType.Up); break;
|
|
case "buttonDown":
|
|
_drawningAirbus.MoveTransport(DirectionType.Down); break;
|
|
case "buttonLeft":
|
|
_drawningAirbus.MoveTransport(DirectionType.Left); break;
|
|
case "buttonRight":
|
|
_drawningAirbus.MoveTransport(DirectionType.Right); break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
// Кнопка "Шаг"
|
|
private void buttonStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningAirbus == null)
|
|
{
|
|
return;
|
|
}
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.SetData(new DrawningObjectAirbus(_drawningAirbus), pictureAirBus.Width, pictureAirBus.Height);
|
|
comboBoxStrategy.Enabled = false;
|
|
}
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.MakeStep();
|
|
Draw();
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_abstractStrategy = null;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |