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 WarmlyShip { /// /// Форма работы с объектом "Теплоход" /// public partial class FormWarmlyShip : Form { /// /// Поле-объект для прорисовки объекта /// private DrawningWarmlyShip? _drawningWarmlyShip; /// /// Инициализация формы /// public FormWarmlyShip() { InitializeComponent(); } /// /// Метод прорисовки теплохода /// private void Draw() { if (_drawningWarmlyShip == null) { return; } Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height); Graphics gr = Graphics.FromImage(bmp); _drawningWarmlyShip.DrawTransport(gr); pictureBoxWarmlyShip.Image = bmp; } /// /// Обработка нажатия кнопки "Создать" /// /// /// private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new(); _drawningWarmlyShip = new DrawningWarmlyShip(); _drawningWarmlyShip.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)), pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height); _drawningWarmlyShip.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } /// /// Изменение размеров формы /// /// /// private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningWarmlyShip == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { case "buttonUp": _drawningWarmlyShip.MoveTransport(DirectionType.Up); break; case "buttonDown": _drawningWarmlyShip.MoveTransport(DirectionType.Down); break; case "buttonLeft": _drawningWarmlyShip.MoveTransport(DirectionType.Left); break; case "buttonRight": _drawningWarmlyShip.MoveTransport(DirectionType.Right); break; } Draw(); } } }