2024-04-18 14:03:03 +04:00
|
|
|
|
using ProjectBus.Drawnings;
|
2024-04-11 11:18:53 +04:00
|
|
|
|
using ProjectBus.Entities;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
2024-04-11 11:18:53 +04:00
|
|
|
|
namespace ProjectBus.Drawnings;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
2024-04-11 11:18:53 +04:00
|
|
|
|
public class DrawningSimpleBus
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-сущность
|
|
|
|
|
/// </summary>
|
2024-04-11 11:18:53 +04:00
|
|
|
|
public EntitySimpleBus? EntitySimpleBus { get; protected set; }
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureWidth;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureHeight;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Левая координата прорисовки автобуса
|
|
|
|
|
/// </summary>
|
2024-04-11 11:18:53 +04:00
|
|
|
|
protected int? _startPosX;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Верхняя кооридната прорисовки автобуса
|
|
|
|
|
/// </summary>
|
2024-04-11 11:18:53 +04:00
|
|
|
|
protected int? _startPosY;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-11 11:18:53 +04:00
|
|
|
|
/// Ширина прорисовки автобуса
|
2024-02-29 10:45:00 +04:00
|
|
|
|
/// /// </summary>
|
|
|
|
|
private readonly int _drawningBusWidth = 310;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота прорисовки автобуса
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly int _drawningBusHeight = 52;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-18 14:03:03 +04:00
|
|
|
|
/// Координата X объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? GetPosX => _startPosX;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Координата Y объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? GetPosY => _startPosY;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetWidth => _drawningBusWidth;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetHeight => _drawningBusHeight;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-11 11:18:53 +04:00
|
|
|
|
/// Пустой конструктор
|
2024-02-29 10:45:00 +04:00
|
|
|
|
/// </summary>
|
2024-04-11 11:18:53 +04:00
|
|
|
|
private DrawningSimpleBus()
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
_startPosX = null;
|
|
|
|
|
_startPosY = null;
|
2024-04-11 11:18:53 +04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес</param>
|
|
|
|
|
/// <param name="bodyColor">Основной цвет</param>
|
|
|
|
|
public DrawningSimpleBus(int speed, double weight, Color bodyColor) : this()
|
|
|
|
|
{
|
|
|
|
|
EntitySimpleBus = new EntitySimpleBus(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор для наследников
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="drawningBusWidth">Ширина прорисовки автобуса</param>
|
|
|
|
|
/// <param name="drawningBusHeight">Высота прорисовки автобуса</param>
|
|
|
|
|
protected DrawningSimpleBus(int drawningBusWidth, int drawningBusHeight) : this()
|
|
|
|
|
{
|
|
|
|
|
_drawningBusWidth = drawningBusWidth;
|
|
|
|
|
_drawningBusHeight= drawningBusHeight;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка границ поля
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="width">Ширина поля</param>
|
|
|
|
|
/// <param name="height">Высота поля</param>
|
|
|
|
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
|
|
|
|
public bool SetPictureSize(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
if (width >= _drawningBusWidth && height >= _drawningBusWidth)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
if (_startPosX.HasValue && _startPosY.HasValue)
|
|
|
|
|
{
|
|
|
|
|
SetPosition(_startPosX.Value, _startPosY.Value);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка позиции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x">Координата X</param>
|
|
|
|
|
/// <param name="y">Координата Y</param>
|
|
|
|
|
//public void SetPosition(int x, int y)
|
|
|
|
|
//{
|
|
|
|
|
// if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// _startPosX = x;
|
|
|
|
|
// _startPosY = y;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
|
{
|
|
|
|
|
x = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (x > _pictureWidth.Value - _drawningBusWidth)
|
|
|
|
|
{
|
|
|
|
|
x = _pictureWidth.Value - _drawningBusWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
|
{
|
|
|
|
|
y = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (y > _pictureHeight.Value - _drawningBusHeight)
|
|
|
|
|
{
|
|
|
|
|
y = _pictureHeight.Value - _drawningBusHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение направления перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
|
|
|
|
public bool MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
2024-04-11 11:18:53 +04:00
|
|
|
|
if (EntitySimpleBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
//влево
|
|
|
|
|
case DirectionType.Left:
|
2024-04-11 11:18:53 +04:00
|
|
|
|
if (_startPosX.Value - EntitySimpleBus.Step > 0)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
2024-04-11 11:18:53 +04:00
|
|
|
|
_startPosX -= (int)EntitySimpleBus.Step;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
//вверх
|
|
|
|
|
case DirectionType.Up:
|
2024-04-11 11:18:53 +04:00
|
|
|
|
if (_startPosY.Value - EntitySimpleBus.Step > 0)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
2024-04-11 11:18:53 +04:00
|
|
|
|
_startPosY -= (int)EntitySimpleBus.Step;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
// вправо
|
|
|
|
|
case DirectionType.Right:
|
2024-04-11 11:18:53 +04:00
|
|
|
|
if (_startPosX.Value + EntitySimpleBus.Step <_pictureWidth - _drawningBusWidth)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
2024-04-11 11:18:53 +04:00
|
|
|
|
_startPosX += (int)EntitySimpleBus.Step;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
//вниз
|
|
|
|
|
case DirectionType.Down:
|
2024-04-11 11:18:53 +04:00
|
|
|
|
if (_startPosY.Value + EntitySimpleBus.Step < _pictureHeight - _drawningBusHeight)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
2024-04-11 11:18:53 +04:00
|
|
|
|
_startPosY += (int)EntitySimpleBus.Step;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
2024-04-11 11:18:53 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
2024-04-11 11:18:53 +04:00
|
|
|
|
if (EntitySimpleBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-11 11:18:53 +04:00
|
|
|
|
|
2024-02-29 10:45:00 +04:00
|
|
|
|
Pen pen = new(Color.Black);
|
|
|
|
|
|
|
|
|
|
//корпус автобуса
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value, 175, 50);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value - 1, 175, 50);
|
|
|
|
|
|
2024-04-11 11:18:53 +04:00
|
|
|
|
Brush br1 = new SolidBrush(EntitySimpleBus.BodyColor);
|
|
|
|
|
g.FillRectangle(br1, _startPosX.Value + 0, _startPosY.Value, 175, 50);
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
|
|
|
|
//окна
|
|
|
|
|
|
|
|
|
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
|
|
|
|
g.FillEllipse(brBlue, _startPosX.Value + 80, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.FillEllipse(brBlue, _startPosX.Value + 105, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.FillEllipse(brBlue, _startPosX.Value + 130, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.FillEllipse(brBlue, _startPosX.Value + 155, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.FillEllipse(brBlue, _startPosX.Value + 25, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.FillEllipse(brBlue, _startPosX.Value + 5, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 105, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 130, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 155, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 6, 16, 25);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//дверь
|
|
|
|
|
|
2024-04-11 11:18:53 +04:00
|
|
|
|
Brush br2 = new SolidBrush(EntitySimpleBus.BodyColor);
|
2024-02-29 10:45:00 +04:00
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 49, _startPosY.Value + 9, 20, 40);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 10, 20, 40);
|
2024-04-11 11:18:53 +04:00
|
|
|
|
g.FillRectangle(br2, _startPosX.Value + 50, _startPosY.Value + 10, 20, 40);
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//колеса
|
|
|
|
|
|
|
|
|
|
Brush brGrey = new SolidBrush(Color.Gray);
|
|
|
|
|
g.FillEllipse(brGrey, _startPosX.Value + 15, _startPosY.Value + 40, 20, 20);
|
|
|
|
|
g.FillEllipse(brGrey, _startPosX.Value + 115, _startPosY.Value + 40, 20, 20);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 40, 20, 20);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 115, _startPosY.Value + 40, 20, 20);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-11 11:18:53 +04:00
|
|
|
|
}
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
|
|
|
|
|