PIbd-21_Putintsev_D.M._Road.../RoadTrain/DrawningObjectTrain.cs

37 lines
1.1 KiB
C#
Raw Permalink Normal View History

using RoadTrain.DrawningObjects;
using RoadTrain.MovementStrategy;
using RoadTrain;
namespace RoadTrain.MovementStrategy
{
/// <summary>
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningRoadTrain (паттерн Adapter)
/// </summary>
public class DrawningObjectTrain : IMoveableObject
{
private readonly DrawningRoadTrain? _drawningRoadTrain = null;
public DrawningObjectTrain (DrawningRoadTrain drawningRoadTrain)
{
_drawningRoadTrain = drawningRoadTrain;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningRoadTrain == null || _drawningRoadTrain.EntityRoadTrain ==
null)
{
return null;
}
return new ObjectParameters(_drawningRoadTrain.GetPosX,
_drawningRoadTrain.GetPosY, _drawningRoadTrain.GetWidth, _drawningRoadTrain.GetHeight);
}
}
public int GetStep => (int)(_drawningRoadTrain?.EntityRoadTrain?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningRoadTrain?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningRoadTrain?.MoveTransport(direction);
}
}