PIbd-23-Radaev-A.V.-20/Catamaran/MoveToRightBorder.cs
Аркадий Радаев eda14d9810 res
2023-10-31 12:27:43 +04:00

41 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran
{
public class MoveToRightBorder : AbstractStrategy
{
protected override bool 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 override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null) return;
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0) MoveLeft();
else MoveRight();
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0) MoveUp();
else MoveDown();
}
}
}
}