PIBD14-BOYKO-M.S.SuperEasyS.../ProjectElectroTrans/MovementStrategy/MoveableTrans.cs
2024-02-28 23:06:50 +04:00

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