2024-03-04 10:34:56 +04:00

261 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace SelfPropelledArtilleryUnit;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningSelfPropelledArtilleryUnit
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntitySelfPropelledArtilleryUnit? EntitySelfPropelledArtilleryUnit { get; private set; }
/// <summary>
/// Ширина окна
/// </summary>
private int? _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int? _pictureHeight;
/// <summary>
/// Левая координата прорисовки cамоходной арт. установки
/// </summary>
private int? _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки cамоходной арт. установки
/// </summary>
private int? _startPosY;
/// <summary>
/// Ширина прорисовки cамоходной арт. установки
/// </summary>
private readonly int _drawningSelfPropelledArtilleryUnitWidth = 135;
/// <summary>
/// Высота прорисовки cамоходной арт. установки
/// </summary>
private readonly int _drawningSelfPropelledArtilleryUnitHeight = 105;
/// <summary>
/// Инициализация полей объекта-класса Самоходная арт. установка
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="turretCannon">Признак наличия башни</param>
/// <param name="launchBattery">Признак наличия орудия</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool turretCannon, bool launchBattery)
{
EntitySelfPropelledArtilleryUnit = new EntitySelfPropelledArtilleryUnit();
EntitySelfPropelledArtilleryUnit.Init(speed, weight, bodyColor, additionalColor, turretCannon, launchBattery);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Установка границ поля
/// </summary>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
{
if (_drawningSelfPropelledArtilleryUnitWidth > width || _drawningSelfPropelledArtilleryUnitHeight > height)
{
return false;
}
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX.HasValue || _startPosY.HasValue)
{
if (_startPosX + _drawningSelfPropelledArtilleryUnitWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningSelfPropelledArtilleryUnitWidth;
}
else if (_startPosX < 0) _startPosX = 0;
if (_startPosY + _drawningSelfPropelledArtilleryUnitHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningSelfPropelledArtilleryUnitHeight;
}
else if (_startPosY < 0) _startPosY = 0;
}
return true;
}
/// <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;
}
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
// то надо изменить координаты, чтобы он оставался в этих границах
if (x + _drawningSelfPropelledArtilleryUnitWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningSelfPropelledArtilleryUnitWidth;
}
else if (x < 0) _startPosX = 0;
else _startPosX = x;
if (y + _drawningSelfPropelledArtilleryUnitHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningSelfPropelledArtilleryUnitHeight;
}
else if (y < 0) _startPosY = 0;
else _startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntitySelfPropelledArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntitySelfPropelledArtilleryUnit.Step > 0)
{
_startPosX -= (int)EntitySelfPropelledArtilleryUnit.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntitySelfPropelledArtilleryUnit.Step > 0)
{
_startPosY -= (int)EntitySelfPropelledArtilleryUnit.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX + _drawningSelfPropelledArtilleryUnitWidth + EntitySelfPropelledArtilleryUnit.Step < _pictureWidth)
{
_startPosX += (int)EntitySelfPropelledArtilleryUnit.Step;
}
return true;
// вниз
case DirectionType.Down:
if (_startPosY + _drawningSelfPropelledArtilleryUnitHeight + EntitySelfPropelledArtilleryUnit.Step < _pictureHeight)
{
_startPosY += (int)EntitySelfPropelledArtilleryUnit.Step;
}
return true;
default:
return false;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (EntitySelfPropelledArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntitySelfPropelledArtilleryUnit.AdditionalColor);
g.DrawEllipse(pen, _startPosX.Value + 0, _startPosY.Value + 75, 30, 30);
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 75, 30, 30);
g.DrawRectangle(pen, _startPosX.Value + 15, _startPosY.Value + 75, 90, 30);
//границы ЦВЕТ
Brush brOlive = new SolidBrush(Color.Olive);
g.FillRectangle(brOlive, _startPosX.Value + 25, _startPosY.Value + 40, 35, 30);//башня
g.FillEllipse(brOlive, _startPosX.Value +0, _startPosY.Value + 75, 30, 30);
g.FillEllipse(brOlive, _startPosX.Value + 90, _startPosY.Value + 75, 30, 30);
g.FillRectangle(brOlive, _startPosX.Value + 15, _startPosY.Value + 75, 90, 30);
// границы арт. установки
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 40, 35, 30);
g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value + 65, 120, 13);//крыша
// верхние катки ЦВЕТ
Brush brCadetBlue = new SolidBrush(Color.CadetBlue);
g.FillEllipse(brCadetBlue, _startPosX.Value + 30, _startPosY.Value + 70, 20, 20);
g.FillEllipse(brCadetBlue, _startPosX.Value + 50, _startPosY.Value + 70, 20, 20);
g.FillEllipse(brCadetBlue, _startPosX.Value + 70, _startPosY.Value + 70, 20, 20);
// верхние катки ОТРИСОВКА
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 70, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 70, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 70, 20, 20);
//нижние катки ЦВЕТ
Brush brDimGray = new SolidBrush(Color.DimGray);
g.FillEllipse(brDimGray, _startPosX.Value + 30, _startPosY.Value + 90, 15, 15);
g.FillEllipse(brDimGray, _startPosX.Value + 45, _startPosY.Value + 90, 15, 15);
g.FillEllipse(brDimGray, _startPosX.Value + 60, _startPosY.Value + 90, 15, 15);
g.FillEllipse(brDimGray, _startPosX.Value + 75, _startPosY.Value + 90, 15, 15);
//нижние катки ОТРИСОВКА
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 90, 15, 15);
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 90, 15, 15);
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 90, 15, 15);
g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 90, 15, 15);
//Большие катки ЦВЕТ
Brush brSlateGray = new SolidBrush(Color.SlateGray);
g.FillEllipse(brSlateGray, _startPosX.Value + 3, _startPosY.Value + 78, 24, 24);
g.FillEllipse(brSlateGray, _startPosX.Value + 93, _startPosY.Value + 78, 24, 24);
//Большие катки ОТРИСОВКА
g.DrawEllipse(pen, _startPosX.Value + 3, _startPosY.Value + 78, 24, 24);
g.DrawEllipse(pen, _startPosX.Value + 93, _startPosY.Value + 78, 24, 24);
g.FillRectangle(brOlive, _startPosX.Value + 0, _startPosY.Value + 65, 120, 13);//
if (EntitySelfPropelledArtilleryUnit.TurretCannon)
{
g.FillEllipse(additionalBrush, _startPosX.Value + 26, _startPosY.Value + 35, 50, 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 25, _startPosY.Value + 36, 20, 29);
g.FillRectangle(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 45, 60, 5);
g.FillEllipse(additionalBrush, _startPosX.Value + 113, _startPosY.Value + 42, 20, 10);
}
if (EntitySelfPropelledArtilleryUnit.LaunchBattery)
{
g.FillRectangle(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 45, 20, 20);
g.FillPolygon(additionalBrush, new Point[]
{
new Point(_startPosX.Value + 0, _startPosY.Value + 15), new Point(_startPosX.Value + 0, _startPosY.Value + 65),
new Point(_startPosX.Value + 20, _startPosY.Value + 65), new Point(_startPosX.Value + 20, _startPosY.Value + 45),
new Point(_startPosX.Value + 0, _startPosY.Value + 15)
});
g.FillEllipse(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 5, 10, 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 15, 20, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 25, 15, 5);
}
}
}