PIBD-13_Fomichev_V.S._Simple_/AntiAircraftGun/MovementStrategy/MoveableAircraftGun.cs

59 lines
2.1 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.

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,
};
}
}