49 lines
1.7 KiB
Java
49 lines
1.7 KiB
Java
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;
|
|
}
|
|
}
|
|
}
|