diff --git a/DoubleDeckerBus/FormDoubleDeckerBus.cs b/DoubleDeckerBus/FormDoubleDeckerBus.cs new file mode 100644 index 0000000..ca8a7f2 --- /dev/null +++ b/DoubleDeckerBus/FormDoubleDeckerBus.cs @@ -0,0 +1,82 @@ +namespace DoubleDeckerBus +{ + public partial class FormDoubleDeckerBus : Form + { + /// + /// Поле-объект для прорисовки объекта + /// + private DrawingBus? _drawingBus; + /// + /// Инициализация формы + /// + public FormDoubleDeckerBus() + { + InitializeComponent(); + } + /// + /// Метод прорисовки автобуса + /// + private void Draw() + { + if (_drawingBus == null) + { + return; + } + Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawingBus.DrawTransport(gr); + pictureBoxBus.Image = bmp; + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingBus = new DrawingBus(); + EntityDoubleDeckerBus bus = new EntityDoubleDeckerBus(); + bus.Init(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))); + _drawingBus.Init(bus, pictureBoxBus.Width, pictureBoxBus.Height); + _drawingBus.SetPosition(random.Next(10, 100), + random.Next(10, 100)); + Draw(); + } + /// + /// Изменение размеров формы + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawingBus == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawingBus.MoveTransport(Direction.Up); + break; + case "buttonDown": + _drawingBus.MoveTransport(Direction.Down); + break; + case "buttonLeft": + _drawingBus.MoveTransport(Direction.Left); + break; + case "buttonRight": + _drawingBus.MoveTransport(Direction.Right); + break; + } + Draw(); + } + } +} \ No newline at end of file