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 PIbd_21_Potapov_N.S._Catamaran_Base
{
public partial class FormBoat : System.Windows.Forms.Form
{
DrawingBoat _boat;
public FormBoat()
{
InitializeComponent();
}
///
/// Обработчик нажатия кнопки "Создать"
///
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
_boat = new DrawingBoat();
_boat.Init(
rnd.Next(50, 100),
rnd.Next(50, 100),
Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255))
);
_boat.SetPosition(
rnd.Next(10, 50),
rnd.Next(10, 50),
pictureBoxBoat.Width,
pictureBoxBoat.Height - statusStrip.Height
);
toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}";
toolStripStatusLabelColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}";
Draw();
}
///
/// Обработчик нажатия кнопок передвижения
///
///
///
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_boat == null)
return;
string btnName = ((Button)sender).Name;
switch (btnName)
{
case "ButtonUp":
{
_boat.MoveTransport(Direction.Up);
}
break;
case "ButtonDown":
{
_boat.MoveTransport(Direction.Down);
}
break;
case "ButtonLeft":
{
_boat.MoveTransport(Direction.Left);
}
break;
case "ButtonRight":
{
_boat.MoveTransport(Direction.Right);
}
break;
default:
break;
}
Draw();
}
///
/// Метод прорисовки лодки
///
private void Draw()
{
Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height);
Graphics g = Graphics.FromImage(bmp);
_boat?.DrawTransport(g);
pictureBoxBoat.Image = bmp;
}
///
/// Изменение размеров формы
///
///
///
private void PictureBoxBoat_Resize(object sender, EventArgs e)
{
_boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height - statusStrip.Height);
Draw();
}
}
}