64 lines
1.9 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 ProjectMonorail.Drawings;
namespace ProjectMonorail.MovementStrategy;
/// <summary>
/// Класс-реализация IMoveableObject с использованием DrawingTrain
/// </summary>
public class MoveableTrain : IMovableObjects
{
/// <summary>
/// Поле-объект класса DrawingTrain или его наследника
/// </summary>
private readonly DrawingTrain? _train = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="train">Объект класса DrawingTrain</param>
public MoveableTrain(DrawingTrain train)
{
_train = train;
}
public ObjectParameters? GetObjectPosition
{
get
{
if(_train == null || _train.EntityTrain == null || !_train.GetPosX.HasValue || !_train.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_train.GetPosX.Value, _train.GetPosY.Value, _train.GetWidth, _train.GetHeight);
}
}
public int GetStep => (int)(_train?.EntityTrain?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_train == null || _train.EntityTrain == null)
{
return false;
}
return _train.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.Up => DirectionType.Up,
MovementDirection.Down => DirectionType.Down,
MovementDirection.Left => DirectionType.Left,
MovementDirection.Right => DirectionType.Right,
_ => DirectionType.Unknown,
};
}
}