namespace ProjectLainer { public partial class LainerForm : Form { private DrawningLainer? _drawningLainer; public LainerForm() { InitializeComponent(); } private void Draw() { if (_drawningLainer == null) { return; } Bitmap bmp = new(pictureBoxLainer.Width, pictureBoxLainer.Height); Graphics gr = Graphics.FromImage(bmp); _drawningLainer.DrawTransport(gr); pictureBoxLainer.Image = bmp; } private void buttonCreate_Click(object sender, EventArgs e) { Random random = new(); _drawningLainer = new DrawningLainer(); _drawningLainer.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)), pictureBoxLainer.Width, pictureBoxLainer.Height); _drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void buttonMove_Click(object sender, EventArgs e) { if (_drawningLainer == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { case "buttonUp": _drawningLainer.MoveTransport(DirectionType.Up); break; case "buttonDown": _drawningLainer.MoveTransport(DirectionType.Down); break; case "buttonLeft": _drawningLainer.MoveTransport(DirectionType.Left); break; case "buttonRight": _drawningLainer.MoveTransport(DirectionType.Right); break; } Draw(); } } }