2024-04-18 14:03:03 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ProjectBus.MovementStrategy;
|
|
|
|
|
public class MoveToBorder : AbstractStrategy
|
|
|
|
|
{
|
|
|
|
|
protected override bool IsTargetDestinaion()
|
|
|
|
|
{
|
|
|
|
|
ObjectParameters? objParams = GetObjectParameters;
|
|
|
|
|
if (objParams == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-05-20 14:22:37 +04:00
|
|
|
|
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth
|
|
|
|
|
&& objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth &&
|
|
|
|
|
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight
|
|
|
|
|
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
|
2024-04-18 14:03:03 +04:00
|
|
|
|
}
|
2024-05-20 14:22:37 +04:00
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
protected override void MoveToTarget()
|
|
|
|
|
{
|
|
|
|
|
ObjectParameters? objParams = GetObjectParameters;
|
|
|
|
|
if (objParams == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
|
|
|
|
|
if (Math.Abs(diffX) > GetStep())
|
|
|
|
|
{
|
|
|
|
|
if (diffX > 0)
|
|
|
|
|
{
|
|
|
|
|
MoveLeft();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MoveRight();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int diffY = objParams.ObjectMiddleVertical - FieldHeight;
|
|
|
|
|
if (Math.Abs(diffY) > GetStep())
|
|
|
|
|
{
|
|
|
|
|
if (diffY > 0)
|
|
|
|
|
{
|
|
|
|
|
MoveUp();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MoveDown();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|