2024-03-12 13:36:12 +04:00

64 lines
2.0 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 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,
};
}
}