PIbd-23_Vrazhkin_S_A_Electr.../lab1/MoveToEdge.cs

39 lines
945 B
C#
Raw Normal View History

2023-10-03 11:53:51 +04:00
namespace ElectricLocomotive;
public class MoveToEdge: AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder < FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - (FieldWidth-1);
if (Math.Abs(diffX) > GetStep())
{
if (diffX < 0)
{
MoveRight();
}
}
var diffY = objParams.DownBorder - (FieldHeight-1);
if (Math.Abs(diffY) > GetStep())
{
if (diffY < 0)
{
MoveDown();
}
}
}
}