64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
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
|
||
{
|
||
/// <summary>
|
||
/// Поле-объект класса DrawningBoat или его наследника
|
||
/// </summary>
|
||
private readonly DrawningAirPlane? _airPlane = null;
|
||
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
/// <param name="drawningAirPlane">Объект класса DrawningCar</param>
|
||
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));
|
||
}
|
||
|
||
/// <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,
|
||
};
|
||
}
|
||
}
|