62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
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,
|
||
};
|
||
}
|
||
|
||
|
||
}
|