2024-03-10 20:04:31 +04:00

68 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 ProjectAirFighter.Drawning;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAirFighter.MovementStrategy;
/// <summary>
/// класс реализация IMoveableObject с исользованием DrawningWarPlane
/// </summary>
public class MoveableWarPlane: IMoveableObject
{
/// <summary>
/// Полк объекта DrawningWarPlane или его наследника
/// </summary>
private readonly DrawningWarPlane? _warPlane = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="warPlane">Объект класса DrawningWarPlane</param>
public MoveableWarPlane(DrawningWarPlane warPlane)
{
_warPlane = warPlane;
}
public ObjectParameters? GetObjectPosition {
get
{
if (_warPlane == null || _warPlane.EntityWarPlane == null || !_warPlane.GetPosX.HasValue || !_warPlane.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_warPlane.GetPosX.Value, _warPlane.GetPosY.Value, _warPlane.GetWigdth, _warPlane.GetHeight);
}
}
public int GetStep => (int)(_warPlane?.EntityWarPlane?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_warPlane == null || _warPlane.EntityWarPlane == null)
{
return false;
}
return _warPlane.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,
};
}
}