PIbd-14_Rachek_A.S._Base/lab_0/MovementStrategy/MoveableSimpleBus.cs

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