275 lines
8.5 KiB
C#
275 lines
8.5 KiB
C#
using ProjectBus.Drawnings;
|
||
using ProjectBus.Entities;
|
||
|
||
namespace ProjectBus.Drawnings;
|
||
|
||
public class DrawningSimpleBus
|
||
{
|
||
/// <summary>
|
||
/// Класс-сущность
|
||
/// </summary>
|
||
public EntitySimpleBus? EntitySimpleBus { get; protected set; }
|
||
|
||
/// <summary>
|
||
/// Ширина окна
|
||
/// </summary>
|
||
private int? _pictureWidth;
|
||
|
||
/// <summary>
|
||
/// Высота окна
|
||
/// </summary>
|
||
private int? _pictureHeight;
|
||
|
||
/// <summary>
|
||
/// Левая координата прорисовки автобуса
|
||
/// </summary>
|
||
protected int? _startPosX;
|
||
|
||
/// <summary>
|
||
/// Верхняя кооридната прорисовки автобуса
|
||
/// </summary>
|
||
protected int? _startPosY;
|
||
|
||
/// <summary>
|
||
/// Ширина прорисовки автобуса
|
||
/// /// </summary>
|
||
private readonly int _drawningBusWidth = 310;
|
||
|
||
/// <summary>
|
||
/// Высота прорисовки автобуса
|
||
/// </summary>
|
||
private readonly int _drawningBusHeight = 52;
|
||
|
||
/// <summary>
|
||
/// Координата 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>
|
||
/// Пустой конструктор
|
||
/// </summary>
|
||
private DrawningSimpleBus()
|
||
{
|
||
_pictureWidth = null;
|
||
_pictureHeight = null;
|
||
_startPosX = null;
|
||
_startPosY = null;
|
||
|
||
}
|
||
|
||
/// <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;
|
||
}
|
||
|
||
/// <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)
|
||
{
|
||
if (EntitySimpleBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
switch (direction)
|
||
{
|
||
//влево
|
||
case DirectionType.Left:
|
||
if (_startPosX.Value - EntitySimpleBus.Step > 0)
|
||
{
|
||
_startPosX -= (int)EntitySimpleBus.Step;
|
||
}
|
||
return true;
|
||
//вверх
|
||
case DirectionType.Up:
|
||
if (_startPosY.Value - EntitySimpleBus.Step > 0)
|
||
{
|
||
_startPosY -= (int)EntitySimpleBus.Step;
|
||
}
|
||
return true;
|
||
// вправо
|
||
case DirectionType.Right:
|
||
if (_startPosX.Value + EntitySimpleBus.Step <_pictureWidth - _drawningBusWidth)
|
||
{
|
||
_startPosX += (int)EntitySimpleBus.Step;
|
||
}
|
||
return true;
|
||
//вниз
|
||
case DirectionType.Down:
|
||
if (_startPosY.Value + EntitySimpleBus.Step < _pictureHeight - _drawningBusHeight)
|
||
{
|
||
_startPosY += (int)EntitySimpleBus.Step;
|
||
}
|
||
return true;
|
||
default:
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Прорисовка объекта
|
||
/// </summary>
|
||
/// <param name="g"></param>
|
||
public virtual void DrawTransport(Graphics g)
|
||
{
|
||
if (EntitySimpleBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
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);
|
||
|
||
Brush br1 = new SolidBrush(EntitySimpleBus.BodyColor);
|
||
g.FillRectangle(br1, _startPosX.Value + 0, _startPosY.Value, 175, 50);
|
||
|
||
//окна
|
||
|
||
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);
|
||
|
||
|
||
//дверь
|
||
|
||
Brush br2 = new SolidBrush(EntitySimpleBus.BodyColor);
|
||
g.DrawRectangle(pen, _startPosX.Value + 49, _startPosY.Value + 9, 20, 40);
|
||
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 10, 20, 40);
|
||
g.FillRectangle(br2, _startPosX.Value + 50, _startPosY.Value + 10, 20, 40);
|
||
|
||
|
||
|
||
//колеса
|
||
|
||
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);
|
||
|
||
|
||
}
|
||
}
|
||
|
||
|