ISEbd-11_Rozhkova_D.S./ProjectStormtrooper/MovementStrategy/MoveableAirplane.cs
2024-04-10 01:14:09 +04:00

70 lines
2.0 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 ProjectStormtrooper.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormtrooper.MovementStrategy;
/// <summary>
/// Класс-реализация IMoveableObject с использованием DrawningCar
/// </summary>
public class MoveableCar : IMoveableObject
{
/// <summary>
/// Поле-объект класса DrawningCar или его наследника
/// </summary>
private readonly DrawningAirplane? _car = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="car">Объект класса DrawningCar</param>
public MoveableCar(DrawningAirplane car)
{
_car = car;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_car == null || _car.EntityAirplane == null || !_car.GetPosX.HasValue || !_car.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_car.GetPosX.Value, _car.GetPosY.Value, _car.GetWidth, _car.GetHeight);
}
}
public int GetStep => (int)(_car?.EntityAirplane?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_car == null || _car.EntityAirplane == null)
{
return false;
}
return _car.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,
};
}
}