2024-05-22 02:41:21 +04:00

63 lines
2.3 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 ProjectArtilleryUnit.Drawnings;
namespace ProjectArtilleryUnit.MovementStrategy
{
/// <summary>
/// класс реалтзация для IMoveableObject с использованием DrawningArtilleryUnit
/// </summary>
public class MoveableArtilleryUnit : IMoveableObject
{
/// <summary>
/// Поле-объект класса DrawningArtilleryUnit или его наследника
/// </summary>
private readonly DrawningArtilleryUnit? _tank = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="tank">Объект класса DrawningArtilleryUnit</param>
public MoveableArtilleryUnit(DrawningArtilleryUnit tank)
{
_tank = tank;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_tank == null || _tank.EntityArtilleryUnit == null ||
!_tank.GetPosX.HasValue || !_tank.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_tank.GetPosX.Value,
_tank.GetPosY.Value, _tank.GetWidth, _tank.GetHeight);
}
}
public int GetStep => (int)(_tank?.EntityArtilleryUnit?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_tank == null || _tank.EntityArtilleryUnit == null)
{
return false;
}
return _tank.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,
};
}
}
}