This commit is contained in:
gavrilov 2023-11-02 19:57:07 +04:00
parent eedea31350
commit 6a6d84cd58
13 changed files with 271 additions and 227 deletions

View File

@ -3,11 +3,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static DumpTruck.DrawningDumpTruck;
namespace DumpTruck.MovementStrategy
{
internal class AbstractStrategy
abstract class AbstractStrategy
{
/// <summary>
@ -104,12 +103,12 @@ namespace DumpTruck.MovementStrategy
/// <summary>
/// Перемещение к цели
/// </summary>
// protected abstract void MoveToTarget();
protected abstract void MoveToTarget();
/// <summary>
/// Достигнута ли цель
/// </summary>
/// <returns></returns>
// protected abstract bool IsTargetDestinaion();
protected abstract bool IsTargetDestinaion();
/// <summary>
/// Попытка перемещения в требуемом направлении
/// </summary>

View File

@ -3,39 +3,12 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DumpTruck.Entities;
namespace DumpTruck
namespace DumpTruck.DrawningObjects
{
internal class DrawningDumpTruck
internal class DrawningDumpTruck : DrawningTruck
{
/// <summary>
/// Класс-сущность
/// </summary>
public DumpTruck? DumpTruck { get; private set; }
/// <summary>
/// Ширина окна
/// </summary>
private int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки автомобиля
/// </summary>
private int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// </summary>
private int _startPosY;
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
private readonly int _DumpTruckWidth = 110;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _DumpTruckHeight = 85;
/// <summary>
/// Инициализация свойств
/// </summary>
@ -46,102 +19,24 @@ namespace DumpTruck
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <returns>true - объект создан, false - проверка не пройдена,
public bool Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool body, bool trailer, int width, int height)
{
if ((height < _DumpTruckHeight) || (width < _DumpTruckWidth))
{
return false;
}
_pictureWidth = width;
_pictureHeight = height;
DumpTruck = new DumpTruck();
DumpTruck.Init(speed, weight, bodyColor, additionalColor,
body, trailer);
return true;
public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color
additionalColor, bool trailer, int width, int height) : base (speed, weight, bodyColor, additionalColor, width, height,100, 55)
{
if (EntityTruck != null)
{
EntityTruck = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, trailer);
}
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
public override void DrawTransport(Graphics g)
{
if ((x < 0 || y < 0) || (x + _DumpTruckWidth > _pictureWidth || y + _DumpTruckHeight > _pictureHeight))
{
_startPosX = 0;
_startPosY = 0;
}
else
{
_startPosX = x;
_startPosY = y;
}
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (DumpTruck == null)
if (EntityTruck is not EntityDumpTruck dumpTruck
)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX - DumpTruck.Step > 0)
{
_startPosX -= (int)DumpTruck.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - DumpTruck.Step > 0)
{
_startPosY -= (int)DumpTruck.Step;
}
break;
// вправо
case DirectionType.Right:
if (_startPosX + _DumpTruckWidth + DumpTruck.Step < _pictureWidth)
{
_startPosX += (int)DumpTruck.Step;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + _DumpTruckHeight + DumpTruck.Step < _pictureHeight)
{
_startPosY += (int)DumpTruck.Step;
}
break;
}
}
public void DrawTransport(Graphics g)
{
if (DumpTruck == null)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(DumpTruck.AdditionalColor);
//грани
g.DrawRectangle(pen, _startPosX + 80, _startPosY, 30, 40);
g.DrawRectangle(pen, _startPosX, _startPosY + 40, 110, 20);
//кузов
Brush br = new SolidBrush(DumpTruck.BodyColor);
g.FillRectangle(br, _startPosX + 81, _startPosY + 1, 29, 40);
Brush br1 = new SolidBrush(DumpTruck.AdditionalColor);
g.FillRectangle(br1, _startPosX + 1, _startPosY + 41, 109, 19);
//колеса
Brush wheels = new SolidBrush(Color.Black);
g.FillEllipse(wheels, _startPosX, _startPosY + 63, 25, 25);
g.FillEllipse(wheels, _startPosX + 25, _startPosY + 63, 25, 25);
g.FillEllipse(wheels, _startPosX + 85, _startPosY + 63, 25, 25);
if (DumpTruck.Trailer)
base.DrawTransport(g);
if (dumpTruck.Trailer)
{
//прицеп
Brush trailer = new SolidBrush(Color.Black);

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DumpTruck.DrawningObjects;
namespace DumpTruck.MovementStrategy
{
internal class DrawningObjectTruck : IMoveableObject
{
private readonly DrawningTruck? _drawningTruck = null;
public DrawningObjectTruck(DrawningTruck drawningTruck)
{
_drawningTruck = drawningTruck;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningTruck == null || _drawningTruck.EntityTruck == null)
{
return null;
}
return new ObjectParameters(_drawningTruck.GetPosX, _drawningTruck.GetPosY, _drawningTruck.GetWidth, _drawningTruck.GetHeight);
}
}
public int GetStep => (int)(_drawningTruck?.EntityTruck?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) => _drawningTruck?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => _drawningTruck?.MoveTransport(direction);
}
}
}

View File

@ -15,7 +15,7 @@ namespace DumpTruck.DrawningObjects
/// <summary>
/// Класс-сущность
/// </summary>
public Truck? Truck { get; protected set; }
public EntityTruck? EntityTruck { get; protected set; }
/// <summary>
/// Ширина окна
/// </summary>
@ -40,6 +40,23 @@ namespace DumpTruck.DrawningObjects
/// Высота прорисовки автомобиля
/// </summary>
protected readonly int _truckHeight = 55;
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _truckWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _truckHeight;
/// <summary>
/// Конструктор
/// </summary>
@ -53,7 +70,7 @@ namespace DumpTruck.DrawningObjects
// TODO: Продумать проверки
_pictureWidth = width;
_pictureHeight = height;
Truck = new Truck(speed, weight, bodyColor, additionalColor);
EntityTruck = new EntityTruck(speed, weight, bodyColor, additionalColor);
}
/// <summary>
/// Конструктор
@ -72,7 +89,7 @@ namespace DumpTruck.DrawningObjects
_pictureHeight = height;
_truckWidth = truckWidth;
_truckHeight = truckHeight;
Truck = new Truck(speed, weight, bodyColor, additionalColor);
EntityTruck = new EntityTruck(speed, weight, bodyColor, additionalColor);
}
/// <summary>
/// Установка позиции
@ -81,17 +98,49 @@ namespace DumpTruck.DrawningObjects
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
// TODO: Изменение x, y, если при установке объект выходит за границы
if (x < 0 || x + _truckWidth > _pictureWidth)
{
x = Math.Max(0, _pictureWidth - _truckWidth);
}
if (y < 0 || y + _truckHeight > _pictureHeight)
{
y = Math.Max(0, _pictureHeight - _truckHeight);
}
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
public bool CanMove(DirectionType direction)
{
if (EntityTruck == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityTruck.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityTruck.Step > 0,
// вправо
DirectionType.Right => _startPosX + _truckWidth + EntityTruck.Step < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + _truckHeight + EntityTruck.Step < _pictureHeight,
_ => false,
};
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (Truck == null)
if (!CanMove(direction) || EntityTruck == null)
{
return;
}
@ -99,37 +148,37 @@ namespace DumpTruck.DrawningObjects
{
//влево
case DirectionType.Left:
if (_startPosX - Truck.Step > 0)
if (_startPosX - EntityTruck.Step > 0)
{
_startPosX -= (int)Truck.Step;
_startPosX -= (int)EntityTruck.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - Truck.Step > 0)
if (_startPosY - EntityTruck.Step > 0)
{
_startPosY -= (int)Truck.Step;
_startPosY -= (int)EntityTruck.Step;
}
break;
// вправо
case DirectionType.Right:
if (_startPosX + _truckWidth + Truck.Step < _pictureWidth)
if (_startPosX + _truckWidth + EntityTruck.Step < _pictureWidth)
{
_startPosX += (int)Truck.Step;
_startPosX += (int)EntityTruck.Step;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + _truckHeight + Truck.Step < _pictureHeight)
if (_startPosY + _truckHeight + EntityTruck.Step < _pictureHeight)
{
_startPosY += (int)Truck.Step;
_startPosY += (int)EntityTruck.Step;
}
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (Truck == null)
if (EntityTruck == null)
{
return;
}
@ -138,9 +187,9 @@ namespace DumpTruck.DrawningObjects
g.DrawRectangle(pen, _startPosX + 80, _startPosY, 30, 40);
g.DrawRectangle(pen, _startPosX, _startPosY + 40, 110, 20);
//кузов
Brush br = new SolidBrush(Truck.BodyColor);
Brush br = new SolidBrush(EntityTruck.BodyColor);
g.FillRectangle(br, _startPosX + 81, _startPosY + 1, 29, 40);
Brush br1 = new SolidBrush(Truck.AdditionalColor);
Brush br1 = new SolidBrush(EntityTruck.AdditionalColor);
g.FillRectangle(br1, _startPosX + 1, _startPosY + 41, 109, 19);
//колеса
Brush wheels = new SolidBrush(Color.Black);

View File

@ -1,57 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck
{
internal class DumpTruck
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия обвеса
/// </summary>
public bool Body { get; private set; }
/// <summary>
/// Признак (опция) наличия антикрыла
/// </summary>
public bool Trailer { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => (double)Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool body, bool trailer)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Body = body;
Trailer = trailer;
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck.Entities
{
public class EntityDumpTruck : EntityTruck
{
/// <summary>
/// Признак (опция) наличия антикрыла
/// </summary>
public bool Trailer { get; private set; }
/// Инициализация полей объекта-класса
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
public EntityDumpTruck(int speed, double weight, Color bodyColor, Color
additionalColor, bool trailer) : base (speed,weight, bodyColor,additionalColor)
{
Trailer = trailer;
}
}
}

View File

@ -9,7 +9,7 @@ namespace DumpTruck.Entities
/// <summary>
/// Класс-сущность "Автомобиль"
/// </summary>
public class Truck
public class EntityTruck
{
/// <summary>
/// Скорость
@ -36,7 +36,7 @@ namespace DumpTruck.Entities
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public Truck(int speed, double weight, Color bodyColor, Color additionalColor)
public EntityTruck(int speed, double weight, Color bodyColor,Color additionalColor)
{
Speed = speed;
Weight = weight;

View File

@ -29,7 +29,6 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDumpTruck));
this.pictureBoxDumpTruck = new System.Windows.Forms.PictureBox();
this.Button_Create = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
@ -46,16 +45,6 @@
this.pictureBoxDumpTruck.TabIndex = 0;
this.pictureBoxDumpTruck.TabStop = false;
//
// Button_Create
//
this.Button_Create.Location = new System.Drawing.Point(30, 407);
this.Button_Create.Name = "Button_Create";
this.Button_Create.Size = new System.Drawing.Size(75, 23);
this.Button_Create.TabIndex = 1;
this.Button_Create.Text = "Создать";
this.Button_Create.UseVisualStyleBackColor = true;
this.Button_Create.Click += new System.EventHandler(this.Button_Create_Click);
//
// buttonUp
//
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
@ -114,7 +103,6 @@
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.Button_Create);
this.Controls.Add(this.pictureBoxDumpTruck);
this.Name = "FormDumpTruck";
this.Text = "FormDumpTruck";
@ -126,7 +114,6 @@
#endregion
private PictureBox pictureBoxDumpTruck;
private Button Button_Create;
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;

View File

@ -7,6 +7,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DumpTruck.DrawningObjects;
using DumpTruck.MovementStrategy;
namespace DumpTruck
{
@ -35,16 +38,9 @@ namespace DumpTruck
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Create_Click(object sender, EventArgs e)
private void Butt1on_Create_Click(object sender, EventArgs e)
{
Random random = new();
_drawningDumpTruck = new DrawningDumpTruck();
_drawningDumpTruck.Init(130, 1000,
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), true,
Convert.ToBoolean(random.Next(0, 2)), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
_drawningDumpTruck.SetPosition(random.Next(30, 100), random.Next(30, 100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{

View File

@ -61,7 +61,7 @@
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOwAAADsABataJCQAAGRlJREFUeNrt3Vt26jy2huHg
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvgAADr4B6kKxwAAAGRlJREFUeNrt3Vt26jy2huHg
dCDC1QCTsu+jobUaALQgofrflkIHOySLEA4+aE69vvH49kX9yM/WXIEpyU/pql7jRZQaeRziI49DfORx
iI88DvGRxyE+8jjERx6H+MjjEB95HOIjj0N85HGIjzwO8ZHHIT7yOATHdG/S/50oLvI4xEfVI6z+10Ao
Ozb1B4SyY2teGgglx+q9/gOh6FgZaz8glBxbU7s1hILjsY66YyXVO8AntUPq47GOumMl1TvAJ7VD6mNn
@ -175,7 +175,7 @@
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvgAADr4B6kKxwAAAFy1JREFUeNrtnV2S6ka2RkFB
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvAAADrwBlbxySQAAFy1JREFUeNrtnV2S6ka2RkFB
v7ese98VCmkA6hwBlzsB4tjzn0qTPxLC5lBCKH++qsVDVy932yf5VmxD1lbmPnT+1R78C5RD4pBH4pBH
4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pBH4pDH6VWFvw6qInHII3HII3HII3HII3HII3HI
I3HII3HII3HII3HII3HII3HII3HII3EIY/hJ700WiUMeiUMeiUMeiUMeiUMeiUMeiUMeiUMeiUMeiUMe
@ -280,7 +280,7 @@
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOwAAADsABataJCQAAFlpJREFUeNrtndFy47h2RT36
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvgAADr4B6kKxwAAAFlpJREFUeNrtndFy47h2RT36
ArNov8tKfgAF3XdHlfueuCr//ysRQJCy3W7LkkUSC1p80aypm+45e+W0dRoE8LAbnu3D8Ig4NA48Ggce
jQOPxoFH48CjceDROPBoHHg0DjwaBx6NA4/GgUfjwKNx4HF8NuXfi1Q0DjwaBx6NA4/GgUfjwKNx4NE4
8GgceDQOPBoHHo0Dj8aBR+PAo3GAsXy69oZF48CjceDROPBoHHg0DjwaBx6NA4/GgUfjwKNx4NE48Ggc
@ -382,7 +382,7 @@
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOwAAADsABataJCQAAGBNJREFUeNrt3V9y+r7Vx3Fj
AQEB////AAAAa2trubm55kNtzgAAAAlwSFlzAAAOvgAADr4B6kKxwAAAGBNJREFUeNrt3V9y+r7Vx3Fj
NoARuTeacB9VYQGPM92A2f9eimTZSb5PSAD/05Hens7QTy/6i/WqjqFHkotwlbq7oosf1fWy3WWq7lo+
WvsW4+B8jRBCmDahglA6oYUQQgghhBBCCCGEEEIIIRwT+V0IIYQQQjg2KgilE1bqJV7C8FmH/zy2WH5c
i5gNI6rCkK4Qq5e6iHSsIIQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGE8K+oIJROaM/xEoaLfuGvka49

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static DumpTruck.DrawningDumpTruck;
namespace DumpTruck.MovementStrategy

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck.MovementStrategy
{
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 &&
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DumpTruck.MovementStrategy
{
internal 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();
}
}
}
}
}