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

54 lines
1.2 KiB
C#
Raw Normal View History

2024-06-12 19:21:59 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser.MoveStrategy;
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(); }
}
}
}