PIbd-14_Pruidze_I.K_Simple_.../ProjectCruiser/MoveStrategy/MoveToBorder.cs

48 lines
1.1 KiB
C#
Raw Normal View History

2024-06-15 09:05:36 +04:00
namespace ProjectCruiser.MoveStrategy;
2024-06-12 19:21:59 +04:00
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestination()
{
ObjParameters? objP = GetObjectParameters;
if (objP == null)
{
return false;
}
return FieldWidth - GetStep() < objP.RightBorder
&& FieldHeight - GetStep() < objP.DownBorder;
}
protected override void MoveToTarget()
{
ObjParameters? objP = GetObjectParameters;
if (objP == null)
{
return;
}
int s = (int)GetStep();
int diffx = objP.RightBorder - FieldWidth;
if (Math.Abs(diffx) > GetStep())
{
if (diffx > 0)
{
MoveLeft();
}
else { MoveRight(); }
}
int diffy = objP.DownBorder - FieldHeight; // (... - s) - step unnecessary
if (Math.Abs(diffy) > GetStep())
{
if (diffy > 0)
{
MoveUp();
}
else { MoveDown(); }
}
}
}