PIbd-23_Panina_A.D.Cruiser..../MoveToBorder.java

28 lines
923 B
Java
Raw Permalink Normal View History

2023-12-08 23:20:53 +04:00
public class MoveToBorder extends AbstractStrategy {
protected boolean IsTargetDestinaion()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return false;
}
return objParams.RightBorder() <= FieldWidth &&
objParams.RightBorder() + GetStep() >= FieldWidth &&
objParams.DownBorder() <= FieldHeight &&
objParams.DownBorder() + GetStep() >= FieldHeight;
}
protected void MoveToTarget()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return;
}
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal();
if (Math.abs(diffX) > GetStep()) {
MoveRight();
}
var diffY = FieldHeight - objParams.ObjectMiddleVertical();
if (Math.abs(diffY) > GetStep()) {
MoveDown();
}
}
2023-12-09 00:17:07 +04:00
}