2024-10-03 01:16:11 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-10-03 01:40:53 +04:00
|
|
|
|
namespace ProjectGasolineTanker.MovementStratg
|
2024-10-03 01:16:11 +04:00
|
|
|
|
{
|
2024-10-03 01:43:12 +04:00
|
|
|
|
|
2024-10-03 01:16:11 +04:00
|
|
|
|
public class MoveToCenter : AbstractStrategy
|
|
|
|
|
{
|
|
|
|
|
protected override bool IsTargetDestinaion()
|
|
|
|
|
{
|
|
|
|
|
var objParams = GetObjectParameters;
|
|
|
|
|
if (objParams == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
|
|
|
|
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
|
|
|
|
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
|
|
|
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
|
|
|
|
}
|
|
|
|
|
protected override void MoveToTarget()
|
|
|
|
|
{
|
|
|
|
|
var objParams = GetObjectParameters;
|
|
|
|
|
if (objParams == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
|
|
|
|
if (Math.Abs(diffX) > GetStep())
|
|
|
|
|
{
|
|
|
|
|
if (diffX > 0)
|
|
|
|
|
{
|
|
|
|
|
MoveLeft();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MoveRight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
|
|
|
|
if (Math.Abs(diffY) > GetStep())
|
|
|
|
|
{
|
|
|
|
|
if (diffY > 0)
|
|
|
|
|
{
|
|
|
|
|
MoveUp();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MoveDown();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-03 01:40:53 +04:00
|
|
|
|
}
|