63 lines
2.3 KiB
C#
Raw Permalink 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.

using SelfPropelledArtilleryUnit.Drawnings;
namespace SelfPropelledArtilleryUnit.MovementStrategy;
/// <summary>
/// Класс-реализация IMoveableObject с использованием DrawningPropelledArtillery
/// </summary>
public class MoveablePropelledArtillery : IMoveableObject
{
/// <summary>
/// Поле-объект класса DrawningPropelledArtillery или его наследника
/// </summary>
private readonly DrawningPropelledArtillery? _PropelledArtillery = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="PropelledArtillery">Объект класса DrawningPropelledArtillery</param>
public MoveablePropelledArtillery(DrawningPropelledArtillery PropelledArtillery)
{
_PropelledArtillery = PropelledArtillery;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_PropelledArtillery == null || _PropelledArtillery.EntityPropelledArtillery == null || !_PropelledArtillery.GetPosX.HasValue || !_PropelledArtillery.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_PropelledArtillery.GetPosX.Value, _PropelledArtillery.GetPosY.Value, _PropelledArtillery.GetWidth, _PropelledArtillery.GetHeight);
}
}
public int GetStep => (int)(_PropelledArtillery?.EntityPropelledArtillery?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_PropelledArtillery == null || _PropelledArtillery.EntityPropelledArtillery == null)
{
return false;
}
return _PropelledArtillery.MoveTransport(GetDirectionType(direction));
}
/// <summary>
/// Конвертация из MovementDirection в DirectionType
/// </summary>
/// <param name="direction">MovementDirection</param>
/// <returns>DirectionType</returns>
private static DirectionType GetDirectionType(MovementDirection direction)
{
return direction switch
{
MovementDirection.Left => DirectionType.Left,
MovementDirection.Right => DirectionType.Right,
MovementDirection.Up => DirectionType.Up,
MovementDirection.Down => DirectionType.Down,
_ => DirectionType.Unknow,
};
}
}