PIbd-22_Chernyshev_G.J._29_.../Trolleybus/MoveToBorder.java

50 lines
1.2 KiB
Java
Raw Normal View History

2023-11-13 22:25:33 +04:00
package Trolleybus;
public class MoveToBorder extends AbstractStrategy{
@Override
protected boolean IsTargetDestination()
{
var objParams = GetObjectParameters();
if (objParams == null)
{
return false;
}
return objParams.RightBorder() <= FieldWidth() &&
objParams.RightBorder() + GetStep() >= FieldWidth() &&
objParams.DownBorder() <= FieldHeight() &&
objParams.DownBorder() + GetStep() >= FieldHeight();
}
@Override
protected void MoveToTarget()
{
var objParams = GetObjectParameters();
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder() - FieldWidth();
if (Math.abs(diffX) >= GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.DownBorder() - FieldHeight();
if (Math.abs(diffY) >= GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}