using System; namespace Cruiser { public partial class FormCruiser : Form { Bitmap bmp; /// /// Поле-объект для прорисовки объекта /// private DrawingCruiser? _drawningCruiser; /// /// Инициализация формы /// public FormCruiser() { InitializeComponent(); bmp = new(pictureBoxCruiser.Width, pictureBoxCruiser.Width); } /// /// Метод прорисовки крейсера /// private void Draw() { if (_drawningCruiser == null) { return; } Graphics gr = Graphics.FromImage(bmp); gr.Clear(Color.White); _drawningCruiser.DrawTransport(gr); pictureBoxCruiser.Image = bmp; } private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningCruiser == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { case "buttonUp": _drawningCruiser.MoveTransport(Direction.Up); break; case "buttonDown": _drawningCruiser.MoveTransport(Direction.Down); break; case "buttonLeft": _drawningCruiser.MoveTransport(Direction.Left); break; case "buttonRight": _drawningCruiser.MoveTransport(Direction.Right); break; } Draw(); } private void buttonCreate_Click(object sender, EventArgs e) { Random random = new(); _drawningCruiser = new DrawingCruiser(); _drawningCruiser.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)), 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)), pictureBoxCruiser.Width, pictureBoxCruiser.Height); _drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } } }