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

37 lines
912 B
Java
Raw Permalink Normal View History

2024-06-10 13:56:47 +04:00
package MovementStrategy;
public class MoveToBorder extends AbstractStrategy{
@Override
protected boolean IsTargetDestinaion() {
ObjectParameters objParams = GetObjectParameters();
if (objParams == null)
{
return false;
}
return objParams.RightBorder + GetStep() >= FieldWidth - GetStep() &&
objParams.DownBorder + GetStep() >= FieldHeight - GetStep();
}
@Override
protected void MoveToTarget() {
ObjectParameters objParams = GetObjectParameters();
if (objParams == null)
{
return;
}
int diffX = FieldWidth - objParams.RightBorder;
if (Math.abs(diffX) > GetStep())
{
MoveRight();
}
int diffY = FieldHeight - objParams.DownBorder;
if (Math.abs(diffY) > GetStep())
{
MoveDown();
}
}
}