61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using ProjectStormtrooper.Drawnings;
|
||
|
||
namespace ProjectStormtrooper.MovementStrategy;
|
||
/// <summary>
|
||
/// Класс-реализации IMoveableObject с использованием DrawingStormtrooperBase
|
||
/// </summary>
|
||
public class MoveableStormtrooperBase : IMoveableObject
|
||
{
|
||
/// <summary>
|
||
/// Поле-объект класса DrawningStormtrooperBase или его наследников
|
||
/// </summary>
|
||
private readonly DrawningStormtrooperBase? _stormtrooper = null;
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
/// <param name="Stormtrooper">Объект класса DrawningStormtrooperBase</param>
|
||
public MoveableStormtrooperBase(DrawningStormtrooperBase Stormtrooper)
|
||
{
|
||
_stormtrooper = Stormtrooper;
|
||
}
|
||
public ObjectParameters? GetObjectPosition
|
||
{
|
||
get
|
||
{
|
||
if (_stormtrooper == null || _stormtrooper.EntityStormtrooperBase == null || !_stormtrooper.GetPosX.HasValue || !_stormtrooper.GetPosY.HasValue)
|
||
{
|
||
return null;
|
||
}
|
||
return new ObjectParameters(_stormtrooper.GetPosX.Value,_stormtrooper.GetPosY.Value,_stormtrooper.GetWidth,_stormtrooper.GetHeight);
|
||
}
|
||
}
|
||
|
||
public int GetStep => (int)(_stormtrooper?.EntityStormtrooperBase?.Step ?? 0);
|
||
|
||
public bool TryMoveObject(MovementDirection direction)
|
||
{
|
||
if (_stormtrooper == null || _stormtrooper.EntityStormtrooperBase == null)
|
||
{
|
||
return false;
|
||
}
|
||
return _stormtrooper.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,
|
||
|
||
};
|
||
}
|
||
}
|