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

37 lines
912 B
Java
Raw Permalink Normal View History

2024-05-09 20:09:37 +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();
}
}
}