2022-09-20 10:04:55 +04:00
|
|
|
|
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
|
|
|
|
|
{
|
2022-10-15 10:12:51 +04:00
|
|
|
|
public partial class FormBoat : System.Windows.Forms.Form
|
2022-09-20 10:04:55 +04:00
|
|
|
|
{
|
2022-10-15 14:07:57 +04:00
|
|
|
|
DrawingBoat _boat;
|
2022-09-20 10:04:55 +04:00
|
|
|
|
|
2022-10-15 10:12:51 +04:00
|
|
|
|
public FormBoat()
|
2022-09-20 10:04:55 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2022-10-15 14:07:57 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработчик нажатия кнопки "Создать"
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
2022-09-20 10:04:55 +04:00
|
|
|
|
{
|
2022-10-12 12:40:12 +04:00
|
|
|
|
Random rnd = new Random();
|
2022-09-20 10:04:55 +04:00
|
|
|
|
|
2022-10-15 14:07:57 +04:00
|
|
|
|
_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();
|
2022-09-20 10:04:55 +04:00
|
|
|
|
}
|
2022-10-15 14:07:57 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработчик нажатия кнопок передвижения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
2022-09-20 10:04:55 +04:00
|
|
|
|
{
|
2022-10-15 14:07:57 +04:00
|
|
|
|
if (_boat == null)
|
2022-09-20 10:04:55 +04:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
string btnName = ((Button)sender).Name;
|
|
|
|
|
|
|
|
|
|
switch (btnName)
|
|
|
|
|
{
|
2022-10-15 14:07:57 +04:00
|
|
|
|
case "ButtonUp":
|
2022-09-20 10:04:55 +04:00
|
|
|
|
{
|
2022-10-15 14:07:57 +04:00
|
|
|
|
_boat.MoveTransport(Direction.Up);
|
2022-09-20 10:04:55 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-10-15 14:07:57 +04:00
|
|
|
|
case "ButtonDown":
|
2022-09-20 10:04:55 +04:00
|
|
|
|
{
|
2022-10-15 14:07:57 +04:00
|
|
|
|
_boat.MoveTransport(Direction.Down);
|
2022-09-20 10:04:55 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-10-15 14:07:57 +04:00
|
|
|
|
case "ButtonLeft":
|
2022-09-20 10:04:55 +04:00
|
|
|
|
{
|
2022-10-15 14:07:57 +04:00
|
|
|
|
_boat.MoveTransport(Direction.Left);
|
2022-09-20 10:04:55 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-10-15 14:07:57 +04:00
|
|
|
|
case "ButtonRight":
|
2022-09-20 10:04:55 +04:00
|
|
|
|
{
|
2022-10-15 14:07:57 +04:00
|
|
|
|
_boat.MoveTransport(Direction.Right);
|
2022-09-20 10:04:55 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-10-15 14:07:57 +04:00
|
|
|
|
Draw();
|
2022-09-20 10:04:55 +04:00
|
|
|
|
}
|
2022-10-15 14:07:57 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Метод прорисовки лодки
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height);
|
|
|
|
|
Graphics g = Graphics.FromImage(bmp);
|
|
|
|
|
_boat?.DrawTransport(g);
|
|
|
|
|
pictureBoxBoat.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение размеров формы
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void PictureBoxBoat_Resize(object sender, EventArgs e)
|
2022-09-20 10:04:55 +04:00
|
|
|
|
{
|
2022-10-15 14:07:57 +04:00
|
|
|
|
_boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height - statusStrip.Height);
|
|
|
|
|
Draw();
|
2022-09-20 10:04:55 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|