PIbd22_Kamcharova_K.A._Doub.../DoubleDeckerBus/Move_Strategy/MoveToBorder.cs

57 lines
1.5 KiB
C#
Raw Normal View History

2023-11-14 14:11:54 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-11-25 14:55:27 +04:00
namespace DoubleDeckerbus.Move_Strategy
2023-11-14 14:11:54 +04:00
{
internal class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
2023-11-25 14:55:27 +04:00
objParams.DownBorder + GetStep() >= FieldHeight;
2023-11-14 14:11:54 +04:00
}
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();
}
2023-11-25 15:23:25 +04:00
2023-11-14 14:11:54 +04:00
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}