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 Seaplane { public partial class FormSeaplane : Form { /// /// Поле объект для прорисовки объекта /// private DrawingSeaplane? _drawningSeaplane; /// /// конструктор формы /// public FormSeaplane() { InitializeComponent(); } /// /// Метод прорисовки транспорта /// private void Draw() { if (_drawningSeaplane == null) { return; } Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); Graphics gr = Graphics.FromImage(bmp); _drawningSeaplane.DrawTransport(gr); pictureBoxSeaplane.Image = bmp; } /// /// Обработка кнопик Создать /// /// /// private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new(); _drawningSeaplane = new DrawingSeaplane(); _drawningSeaplane.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); _drawningSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); _drawningSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } /// /// Перемещение объекта по форме /// /// /// private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningSeaplane == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; bool result = false; switch (name) { case "buttonUp": result = _drawningSeaplane.MoveTransport(DirectionType.Up); break; case "buttonDown": result = _drawningSeaplane.MoveTransport(DirectionType.Down); break; case "buttonRight": result = _drawningSeaplane.MoveTransport(DirectionType.Right); break; case "buttonLeft": result = _drawningSeaplane.MoveTransport(DirectionType.Left); break; } if (result) { Draw(); } } } }