59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using AntiAircraftGun.Drawnings;
|
||
|
||
namespace AntiAircraftGun.MovementStrategy;
|
||
|
||
public class MoveableAircraftGun: IMoveableObject
|
||
{
|
||
/// <summary>
|
||
/// Поле-объект класса DrawningAircraftGun или его наследника
|
||
/// </summary>
|
||
private readonly DrawningAircraftGun? _drawningAircraftGun = null;
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
/// <param name="trans">Объект класса DrawningTrans</param>
|
||
public MoveableAircraftGun(DrawningAircraftGun trans)
|
||
{
|
||
_drawningAircraftGun = trans;
|
||
}
|
||
|
||
public ObjectParameters? GetObjectPosition
|
||
{
|
||
get
|
||
{
|
||
if (_drawningAircraftGun == null || _drawningAircraftGun.EntityAircraftGun == null ||
|
||
!_drawningAircraftGun.GetPosX.HasValue || !_drawningAircraftGun.GetPosY.HasValue)
|
||
{
|
||
return null;
|
||
}
|
||
return new ObjectParameters(_drawningAircraftGun.GetPosX.Value,
|
||
_drawningAircraftGun.GetPosY.Value, _drawningAircraftGun.GetWidth, _drawningAircraftGun.GetHeight);
|
||
}
|
||
}
|
||
public int GetStep => (int)(_drawningAircraftGun?.EntityAircraftGun?.Step ?? 0);
|
||
public bool TryMoveObject(MovementDirection direction)
|
||
{
|
||
if (_drawningAircraftGun == null || _drawningAircraftGun.EntityAircraftGun == null)
|
||
{
|
||
return false;
|
||
}
|
||
return _drawningAircraftGun.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,
|
||
};
|
||
}
|
||
}
|