106 lines
3.3 KiB
C#
106 lines
3.3 KiB
C#
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();
|
||
}
|
||
/// <summary>
|
||
/// Обработчик нажатия кнопки "Создать"
|
||
/// </summary>
|
||
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();
|
||
}
|
||
/// <summary>
|
||
/// Обработчик нажатия кнопок передвижения
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
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();
|
||
}
|
||
/// <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)
|
||
{
|
||
_boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height - statusStrip.Height);
|
||
Draw();
|
||
}
|
||
}
|
||
}
|