2024-05-22 02:04:02 +04:00
|
|
|
|
using ProjectArtilleryUnit.Drawnings;
|
|
|
|
|
|
|
|
|
|
namespace ProjectArtilleryUnit.MovementStrategy
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// класс реалтзация для IMoveableObject с использованием DrawningArtilleryUnit
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MoveableArtilleryUnit : IMoveableObject
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Поле-объект класса DrawningArtilleryUnit или его наследника
|
|
|
|
|
/// </summary>
|
2024-05-22 02:41:21 +04:00
|
|
|
|
private readonly DrawningArtilleryUnit? _tank = null;
|
2024-05-22 02:04:02 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
2024-05-22 02:41:21 +04:00
|
|
|
|
/// <param name="tank">Объект класса DrawningArtilleryUnit</param>
|
|
|
|
|
public MoveableArtilleryUnit(DrawningArtilleryUnit tank)
|
2024-05-22 02:04:02 +04:00
|
|
|
|
{
|
2024-05-22 02:41:21 +04:00
|
|
|
|
_tank = tank;
|
2024-05-22 02:04:02 +04:00
|
|
|
|
}
|
|
|
|
|
public ObjectParameters? GetObjectPosition
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2024-05-22 02:41:21 +04:00
|
|
|
|
if (_tank == null || _tank.EntityArtilleryUnit == null ||
|
|
|
|
|
!_tank.GetPosX.HasValue || !_tank.GetPosY.HasValue)
|
2024-05-22 02:04:02 +04:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2024-05-22 02:41:21 +04:00
|
|
|
|
return new ObjectParameters(_tank.GetPosX.Value,
|
|
|
|
|
_tank.GetPosY.Value, _tank.GetWidth, _tank.GetHeight);
|
2024-05-22 02:04:02 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-22 02:41:21 +04:00
|
|
|
|
public int GetStep => (int)(_tank?.EntityArtilleryUnit?.Step ?? 0);
|
2024-05-22 02:04:02 +04:00
|
|
|
|
public bool TryMoveObject(MovementDirection direction)
|
|
|
|
|
{
|
2024-05-22 02:41:21 +04:00
|
|
|
|
if (_tank == null || _tank.EntityArtilleryUnit == null)
|
2024-05-22 02:04:02 +04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-05-22 02:41:21 +04:00
|
|
|
|
return _tank.MoveTransport(GetDirectionType(direction));
|
2024-05-22 02:04:02 +04:00
|
|
|
|
}
|
|
|
|
|
/// <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,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|