using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WinFormsApp1 { public partial class FormTractor : Form { private TractorDraw _Tractor; public TractorDraw SelectedTractor { get; private set; } public FormTractor() { InitializeComponent(); } private void Draw() { Bitmap bmp = new Bitmap(pictureBoxTractor.Width, pictureBoxTractor.Height); Graphics gr = Graphics.FromImage(bmp); _Tractor?.DrawEntity(gr); pictureBoxTractor.Image = bmp; } private void SetData() { Random random = new(); _Tractor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTractor.Width, pictureBoxTractor.Height); toolStripStatusLabelSpeed.Text = $"Скорость: {_Tractor.Tractor.Speed}"; toolStripStatusLabelWeight.Text = $"Вес: {_Tractor.Tractor.Weight}"; toolStripStatusLabelBodyColor.Text = $"Цвет кузова: {_Tractor.Tractor.BodyColor.Name}"; } 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; } _Tractor = new TractorDraw(random.Next(100, 300), random.Next(1000, 2000), color); SetData(); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) { string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { case "buttonUp": _Tractor?.MoveTransport(Direction.Up); break; case "buttonDown": _Tractor?.MoveTransport(Direction.Down); break; case "buttonLeft": _Tractor?.MoveTransport(Direction.Left); break; case "buttonRight": _Tractor?.MoveTransport(Direction.Right); break; } Draw(); } private void pictureBoxTractor_Resize(object sender, EventArgs e) { _Tractor?.ChangeBorders(pictureBoxTractor.Width, pictureBoxTractor.Height); Draw(); } private void buttonCreateModif_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)); ColorDialog dialogDop = new(); if (dialogDop.ShowDialog() == DialogResult.OK) { dopColor = dialogDop.Color; } _Tractor = new MultiTraktorDraw(random.Next(100, 300), random.Next(1000, 2000), color, dopColor); SetData(); Draw(); } private void buttonSelectedTractor_Click(object sender, EventArgs e) { SelectedTractor = _Tractor; DialogResult = DialogResult.OK; } } }