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 Sailboat { public partial class BoatForm : Form { private DrawingBoat _boat; public BoatForm() { InitializeComponent(); } /// /// Обработка нажатия кнопки "Создать" /// /// /// private void btn_create_Click(object sender, EventArgs e) { Random rnd = new(); _boat = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBoat.Width, pictureBoxBoat.Height); SetData(); Draw(); } /// /// Обработка нажатия кнопки "Создать парусник" /// /// /// private void btn_create_sailboat_Click(object sender, EventArgs e) { Random rnd = new(); _boat = new DrawingSailboat(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); _boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBoat.Width, pictureBoxBoat.Height); SetData(); Draw(); } /// /// Обработка нажатия стрелок /// /// /// private void btn_move_Click(object sender, EventArgs e) { //получаем имя кнопки string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { case "btn_up": _boat?.MoveTransport(Direction.Up); break; case "btn_down": _boat?.MoveTransport(Direction.Down); break; case "btn_left": _boat?.MoveTransport(Direction.Left); break; case "btn_right": _boat?.MoveTransport(Direction.Right); break; } Draw(); } /// /// Метод прорисовки машины /// private void Draw() { Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height); Graphics gr = Graphics.FromImage(bmp); _boat?.DrawTransport(gr); pictureBoxBoat.Image = bmp; } /// /// Изменение размеров формы /// /// /// private void PictureBoxCar_Resize(object sender, EventArgs e) { _boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height); Draw(); } /// /// Метод прорисовки машины /// private void SetData() { Random rnd = new(); toolStripLabel_color.Text = $"Скорость: {_boat.Boat.Speed}"; toolStripLabel_weight.Text = $"Вес: {_boat.Boat.Weight}"; toolStripLabel_color.Text = $"Цвет: { _boat.Boat.BodyColor.Name}"; } } }