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

37 lines
1.1 KiB
C#
Raw Permalink 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 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);
}
}