144 lines
4.9 KiB
C#
144 lines
4.9 KiB
C#
using ProjectAirbus.Drawnings;
|
|
using ProjectAirbus.MovementStrategy;
|
|
using ProjectAirbus.Entities;
|
|
|
|
namespace ProjectAirbus
|
|
{
|
|
public partial class FormPlane : Form
|
|
{
|
|
private DrawningAirbus? _drawningAirbus;
|
|
private AbstractStrategy? _abstractStrategy;
|
|
|
|
// Выбранный автомобиль
|
|
public DrawningAirbus? SelectedAirbus { get; private set; }
|
|
|
|
public FormPlane()
|
|
{
|
|
InitializeComponent();
|
|
_abstractStrategy = null;
|
|
SelectedAirbus = null;
|
|
}
|
|
|
|
// прорисовка самолёта
|
|
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 buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new Random();
|
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
color = dialog.Color;
|
|
}
|
|
|
|
_drawningAirbus = new DrawningAirbus(random.Next(100, 300), random.Next(1000, 3000),
|
|
color, 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();
|
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
//выбор основного цвета
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
color = dialog.Color;
|
|
}
|
|
|
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
//TODO дополнительного цвета
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
dopColor = dialog.Color;
|
|
}
|
|
|
|
_drawningAirbus = new DrawningPlane(random.Next(200, 400), random.Next(1000, 3000),
|
|
color, dopColor, 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;
|
|
}
|
|
}
|
|
|
|
private void buttonSelectedAirbus_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedAirbus = _drawningAirbus;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
} |