55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ProjectMonorail.MovementStrategy;
|
|
|
|
public class MoveToCenter : AbstractStrategy
|
|
{
|
|
protected override bool IsTargetDestination()
|
|
{
|
|
ObjectParameters? objParams = GetObjectParameters;
|
|
if (objParams == null)
|
|
{
|
|
return false;
|
|
}
|
|
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
|
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
|
}
|
|
|
|
protected override void MoveToTarget()
|
|
{
|
|
ObjectParameters? objParams = GetObjectParameters;
|
|
if (objParams == null)
|
|
{
|
|
return;
|
|
}
|
|
int diffx = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
|
if (Math.Abs(diffx) > GetStep())
|
|
{
|
|
if (diffx > 0)
|
|
{
|
|
MoveLeft();
|
|
}
|
|
else
|
|
{
|
|
MoveRight();
|
|
}
|
|
}
|
|
int diffy = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
|
if (Math.Abs(diffy) > GetStep())
|
|
{
|
|
if (diffy > 0)
|
|
{
|
|
MoveUp();
|
|
}
|
|
else
|
|
{
|
|
MoveDown();
|
|
}
|
|
}
|
|
}
|
|
}
|