PIbd-14_Antonova_A.A.__Hard/MovementStrategy/MoveableTruck.java

49 lines
1.7 KiB
Java
Raw Normal View History

2024-05-09 20:09:37 +04:00
package MovementStrategy;
import Drawnings.CanvasDumpTruck;
import Drawnings.DirectionType;
import Drawnings.DrawningTruck;
public class MoveableTruck implements IMoveableObject {
private CanvasDumpTruck canvas = new CanvasDumpTruck();
public MoveableTruck(DrawningTruck drawningTruck)
{
canvas._drawningTruck = drawningTruck;
}
@Override
public ObjectParameters GetObjectPosition() {
if (canvas._drawningTruck == null || canvas._drawningTruck.EntityTruck == null ||
canvas._drawningTruck.GetPosX() == null || canvas._drawningTruck.GetPosY() == null)
{
return null;
}
return new ObjectParameters(canvas._drawningTruck.GetPosX(), canvas._drawningTruck.GetPosY(),
canvas._drawningTruck.GetWidth(), canvas._drawningTruck.GetHeight());
}
@Override
public int GetStep() {
return (int)(canvas._drawningTruck.EntityTruck.Step);
}
@Override
public Boolean TryMoveObject(MovementDirection direction) {
if (canvas._drawningTruck == null || canvas._drawningTruck.EntityTruck == null)
{
return false;
}
return canvas._drawningTruck.MoveTransport(GetDirectionType(direction));
}
private static DirectionType GetDirectionType(MovementDirection direction)
{
switch (direction) {
case MovementDirection.Left: return DirectionType.Left;
case MovementDirection.Right: return DirectionType.Right;
case MovementDirection.Up: return DirectionType.Up;
case MovementDirection.Down: return DirectionType.Down;
default: return DirectionType.Unknow;
}
}
}