using ProjectBus.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBus.MovementStrategy;
///
/// Класс-реализация IMoveableObject с использованием DrawingSimpleBus
///
public class MoveableSimpleBus : IMoveableObject
{
//
/// Поле-объект класса DrawningTrans или его наследника
///
private readonly DrawningSimpleBus? _simplebus = null;
///
/// Конструктор
///
/// Объект класса DrawningSimpleBus
public MoveableSimpleBus(DrawningSimpleBus simplebus)
{
_simplebus = simplebus;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_simplebus == null || _simplebus.EntitySimpleBus == null || !_simplebus.GetPosX.HasValue || !_simplebus.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_simplebus.GetPosX.Value, _simplebus.GetPosY.Value, _simplebus.GetWidth, _simplebus.GetHeight);
}
}
public int GetStep => (int)(_simplebus?.EntitySimpleBus ?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_simplebus == null || _simplebus.EntitySimpleBus == null)
{
return false;
}
return _simplebus.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,
};
}
}