using AirBomber.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber.MovementStrategy;
internal class MoveableAirPlane : IMoveableObject
{
///
/// Поле-объект класса DrawningBoat или его наследника
///
private readonly DrawningAirPlane? _airPlane = null;
///
/// Конструктор
///
/// Объект класса DrawningCar
public MoveableAirPlane(DrawningAirPlane drawningAirPlane)
{
_airPlane = drawningAirPlane;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_airPlane == null || _airPlane.EntityAirPlane == null || !_airPlane.GetPosX.HasValue || !_airPlane.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_airPlane.GetPosX.Value, _airPlane.GetPosY.Value, _airPlane.GetWidth, _airPlane.GetHeight);
}
}
public int GetStep => (int)(_airPlane?.EntityAirPlane?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_airPlane == null || _airPlane.EntityAirPlane == null)
{
return false;
}
return _airPlane.MoveTransport(GetDirectionType(direction));
}
///
/// Конвертация из MovementDirection в DirectionType
///
/// MovementDirection
/// DirectionType
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,
};
}
}