This commit is contained in:
Baryshev Dmitry 2024-03-14 20:48:51 +04:00
parent 9c13440d18
commit cd369bfe6e
5 changed files with 101 additions and 3 deletions

View File

@ -8,7 +8,10 @@ namespace ProjectDumpTruck.Drawnings
{
public enum DirectionType
{
/// <summary>
/// Неизвестное направление
/// </summary>
Unknow = -1,
/// <summary>
/// Вверх
/// </summary>

View File

@ -43,11 +43,11 @@ public class DrawningTruck
/// <summary>
/// Ширина объекта
/// </summary>
public int? GetWidth => _drawningTruckWidth;
public int GetWidth => _drawningTruckWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int? GetHeight => _drawningTruckHeight;
public int GetHeight => _drawningTruckHeight;
/// <summary>
/// Пустой конструктор

View File

@ -0,0 +1,19 @@

namespace ProjectDumpTruck.MovementStrategy;
/// <summary>
/// Стратегия перемещения объекта к углу
/// </summary>
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestination()
{
throw new NotImplementedException();
}
protected override bool MoveToTarget()
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,18 @@

namespace ProjectDumpTruck.MovementStrategy;
// <summary>
/// Стратегия перемещения объекта в центр
/// </summary>
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestination()
{
throw new NotImplementedException();
}
protected override bool MoveToTarget()
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,58 @@

using ProjectDumpTruck.Drawnings;
namespace ProjectDumpTruck.MovementStrategy;
/// <summary>
/// Класс-реализация IMoveableObject с использованием DrawningTruck
/// </summary>
public class MoveableTruck : IMoveableObject
{
private DrawningTruck? _truck=null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="truck">Объект класса DrawningTruck</param>
public MoveableTruck(DrawningTruck? truck)
{
_truck = truck;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_truck == null||_truck.EntityTruck == null|| !_truck.GetPosX.HasValue|| !_truck.GetPosY.HasValue)
return null;
return new ObjectParameters(_truck.GetPosX.Value, _truck.GetPosY.Value, _truck.GetWidth, _truck.GetHeight);
}
}
public int GetStep => (int)(_truck?.EntityTruck?.Step ?? 0);
/// <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.Unknow
};
}
public bool TryMoveableObject(MovementDirection direction)
{
if (_truck == null || _truck.EntityTruck == null) return false;
return _truck.MoveTransport(GetDirectionType(direction))
}
}