66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
using ProjectElectricLocomotive.Drawnings;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ProjectElectricLocomotive.MovementStrategy
|
|
{
|
|
public class MoveableLocomotive : IMovableObject
|
|
{
|
|
|
|
private readonly DrawningLocomotive? _locomotive = null;
|
|
|
|
public MoveableLocomotive(DrawningLocomotive locomotive)
|
|
{
|
|
_locomotive = locomotive;
|
|
}
|
|
|
|
public ObjectParameters? GetObjectPosition
|
|
{
|
|
get
|
|
{
|
|
if (_locomotive == null || _locomotive.EntityLocomotive == null || !_locomotive.GetPosX.HasValue || !_locomotive.GetPosY.HasValue)
|
|
{
|
|
return null;
|
|
}
|
|
return new ObjectParameters(_locomotive.GetPosX.Value, _locomotive.GetPosY.Value, _locomotive.GetWidth, _locomotive.GetHeight);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public int GetStep => (int)(_locomotive?.EntityLocomotive?.Step ?? 0);
|
|
|
|
|
|
|
|
public bool TryMoveObject(MovementDirection direction)
|
|
{
|
|
if (_locomotive == null || _locomotive.EntityLocomotive == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return _locomotive.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,
|
|
};
|
|
}
|
|
}
|
|
}
|