69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
using lab1.Drawnings;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace lab1.MovementStrategy;
|
||
/// <summary>
|
||
/// Класс-реализации IMoveableObject с использованием DrawingTrackedVenicle
|
||
/// </summary>
|
||
public class MoveableTrackedVehicle : IMoveableObject
|
||
{
|
||
/// <summary>
|
||
/// Поле-объект класса DrawningTrackedVehicle или его наследников
|
||
/// </summary>
|
||
private readonly DrawningTrackedVehicle? _trackedVehicle = null;
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
/// <param name="trackedVenicle">Объект класса DrawningStormtrooperBase</param>
|
||
public MoveableTrackedVehicle(DrawningTrackedVehicle trackedVehicle)
|
||
{
|
||
_trackedVehicle = trackedVehicle;
|
||
}
|
||
public ObjectParameters? GetObjectPosition
|
||
{
|
||
get
|
||
{
|
||
if (_trackedVehicle == null || _trackedVehicle.EntityTrackedVehicle == null || !_trackedVehicle.GetPosX.HasValue || !_trackedVehicle.GetPosY.HasValue)
|
||
{
|
||
return null;
|
||
}
|
||
return new ObjectParameters(_trackedVehicle.GetPosX.Value, _trackedVehicle.GetPosY.Value, _trackedVehicle.GetWidth, _trackedVehicle.GetHeight);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
public int GetStep => (int)(_trackedVehicle?.EntityTrackedVehicle?.Step ?? 0);
|
||
|
||
public bool TryMoveObject(MovementDirection direction)
|
||
{
|
||
if (_trackedVehicle == null || _trackedVehicle.EntityTrackedVehicle == null)
|
||
{
|
||
return false;
|
||
}
|
||
return _trackedVehicle.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,
|
||
|
||
};
|
||
}
|
||
|
||
}
|