Compare commits
No commits in common. "ecfe3f3131795c7eb4b6f126e3e20de3b27862a8" and "bd746e928870a62316697671aa6adaffda9ad5ca" have entirely different histories.
ecfe3f3131
...
bd746e9288
@ -1,11 +1,9 @@
|
|||||||
namespace ProjectLiner.MovementStrategy;
|
namespace ProjectLiner;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum MovementDirection
|
public enum DirectionType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вверх
|
/// Вверх
|
||||||
@ -26,5 +24,4 @@ public enum MovementDirection
|
|||||||
/// Вправо
|
/// Вправо
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Right = 4
|
Right = 4
|
||||||
}
|
}
|
||||||
|
|
@ -1,17 +1,14 @@
|
|||||||
using ProjectLiner.Entities;
|
namespace ProjectLiner;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectLiner.Drawnings;
|
/// <summary>
|
||||||
public class DrawningCommonLiner
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningLiner
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityCommonLiner? EntityCommonLiner { get; protected set; }
|
public EntityLiner? EntityLiner { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
@ -26,12 +23,12 @@ public class DrawningCommonLiner
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки лайнера
|
/// Левая координата прорисовки лайнера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected int? _startPosX;
|
private int? _startPosX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки лайнера
|
/// Верхняя кооридната прорисовки лайнера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected int? _startPosY;
|
private int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки лайнера
|
/// Ширина прорисовки лайнера
|
||||||
@ -41,62 +38,25 @@ public class DrawningCommonLiner
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки лайнера
|
/// Высота прорисовки лайнера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningLinerHeight = 90;
|
private readonly int _drawningLinerHeight = 125;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Координата X объекта
|
/// Инициализация свойств
|
||||||
/// </summary>
|
|
||||||
public int? GetPosX => _startPosX;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Координата Y объекта
|
|
||||||
/// </summary>
|
|
||||||
public int? GetPosY => _startPosY;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int GetWidth => _drawningLinerWidth;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Высота объекта
|
|
||||||
/// </summary>
|
|
||||||
public int GetHeight => _drawningLinerHeight;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Пустой конструктор
|
|
||||||
/// </summary>
|
|
||||||
|
|
||||||
public DrawningCommonLiner()
|
|
||||||
{
|
|
||||||
_pictureWidth = null;
|
|
||||||
_pictureHeight = null;
|
|
||||||
_startPosX = null;
|
|
||||||
_startPosY = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// конструктор
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес</param>
|
/// <param name="weight">Вес</param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
public DrawningCommonLiner(int speed, double weight, Color bodycolor) : this()
|
/// <param name="anchor">Признак наличия якоря</param>
|
||||||
|
/// <param name="boats">Признак наличия шлюпок</param>
|
||||||
|
/// <param name="pipe">Признак наличия трубы</param>
|
||||||
|
public void Init(EntityLiner liner)
|
||||||
{
|
{
|
||||||
EntityCommonLiner = new EntityCommonLiner(speed, weight, bodycolor);
|
EntityLiner = liner;
|
||||||
}
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
/// <summary>
|
_startPosX = null;
|
||||||
/// конструктор для наследников
|
_startPosY = null;
|
||||||
/// </summary>
|
|
||||||
/// <param name="drawningLinerHeight">Высота</param>
|
|
||||||
/// <param name="drawningLinerWight">Длина</param>
|
|
||||||
|
|
||||||
protected DrawningCommonLiner(int drawningLinerWight, int drawningLinerHeight) : this()
|
|
||||||
{
|
|
||||||
_drawningLinerHeight = drawningLinerHeight;
|
|
||||||
_drawningLinerWidth = drawningLinerWight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -113,7 +73,7 @@ public class DrawningCommonLiner
|
|||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
if (_startPosX != null && _startPosY != null)
|
if (_startPosX != null && _startPosY != null)
|
||||||
{
|
{
|
||||||
if (_startPosX.Value < 0)
|
if (_startPosX.Value < 0)
|
||||||
_startPosX = 0;
|
_startPosX = 0;
|
||||||
if (_startPosY.Value < 0)
|
if (_startPosY.Value < 0)
|
||||||
_startPosY = 0;
|
_startPosY = 0;
|
||||||
@ -169,7 +129,7 @@ public class DrawningCommonLiner
|
|||||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityCommonLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -178,30 +138,30 @@ public class DrawningCommonLiner
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntityCommonLiner.Step > 0)
|
if (_startPosX.Value - EntityLiner.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityCommonLiner.Step;
|
_startPosX -= (int)EntityLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntityCommonLiner.Step > 0)
|
if (_startPosY.Value - EntityLiner.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityCommonLiner.Step;
|
_startPosY -= (int)EntityLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX.Value + EntityCommonLiner.Step < _pictureWidth - _drawningLinerWidth)
|
if (_startPosX.Value + EntityLiner.Step < _pictureWidth-_drawningLinerWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityCommonLiner.Step;
|
_startPosX += (int)EntityLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY.Value + EntityCommonLiner.Step < _pictureHeight - _drawningLinerHeight)
|
if (_startPosY.Value + EntityLiner.Step < _pictureHeight-_drawningLinerHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityCommonLiner.Step;
|
_startPosY += (int)EntityLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -213,33 +173,61 @@ public class DrawningCommonLiner
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public virtual void DrawTransport(Graphics g)
|
public void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityCommonLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush br = new SolidBrush(EntityCommonLiner.BodyColor);
|
Brush additionalBrush = new SolidBrush(EntityLiner.AdditionalColor);
|
||||||
|
Brush br = new SolidBrush(EntityLiner.BodyColor);
|
||||||
|
|
||||||
|
// якорь
|
||||||
|
if (EntityLiner.Anchor)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 85, _startPosX.Value + 45, _startPosY.Value + 115);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 30, _startPosY.Value + 95, _startPosX.Value + 60, _startPosY.Value + 95);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 25, _startPosY.Value + 100, _startPosX.Value + 45, _startPosY.Value + 115);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 115, _startPosX.Value + 65, _startPosY.Value + 100);
|
||||||
|
}
|
||||||
|
|
||||||
// кузов лайнера
|
// кузов лайнера
|
||||||
Point point1 = new Point(_startPosX.Value, _startPosY.Value + 40);
|
Point point1 = new Point(_startPosX.Value, _startPosY.Value + 80);
|
||||||
Point point2 = new Point(_startPosX.Value + 50, _startPosY.Value + 90);
|
Point point2 = new Point(_startPosX.Value + 50, _startPosY.Value + 130);
|
||||||
Point point3 = new Point(_startPosX.Value + 135, _startPosY.Value + 90);
|
Point point3 = new Point(_startPosX.Value + 135, _startPosY.Value + 130);
|
||||||
Point point4 = new Point(_startPosX.Value + 155, _startPosY.Value + 40);
|
Point point4 = new Point(_startPosX.Value + 155, _startPosY.Value + 80);
|
||||||
Point[] curvePoints = { point1, point2, point3, point4 };
|
Point[] curvePoints = { point1, point2, point3, point4 };
|
||||||
g.FillPolygon(br, curvePoints);
|
g.FillPolygon(br, curvePoints);
|
||||||
|
|
||||||
|
|
||||||
// борт лайнера
|
// борт лайнера
|
||||||
Point point5 = new Point(_startPosX.Value + 40, _startPosY.Value);
|
Point point5 = new Point(_startPosX.Value+40, _startPosY.Value + 40);
|
||||||
Point point6 = new Point(_startPosX.Value + 140, _startPosY.Value);
|
Point point6 = new Point(_startPosX.Value + 140, _startPosY.Value + 40);
|
||||||
Point point7 = new Point(_startPosX.Value + 140, _startPosY.Value + 40);
|
Point point7 = new Point(_startPosX.Value + 140, _startPosY.Value + 80);
|
||||||
Point point8 = new Point(_startPosX.Value + 40, _startPosY.Value + 40);
|
Point point8 = new Point(_startPosX.Value + 40, _startPosY.Value + 80);
|
||||||
Point[] curvePoints2 = { point5, point6, point7, point8 };
|
Point[] curvePoints2 = { point5, point6, point7, point8 };
|
||||||
g.FillPolygon(br, curvePoints2);
|
g.FillPolygon(additionalBrush, curvePoints2);
|
||||||
|
|
||||||
|
// шлюпки
|
||||||
|
if (EntityLiner.Boats)
|
||||||
|
{
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 85, 30, 15);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 85, 30, 15);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 85, 30, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
// труба
|
||||||
|
if (EntityLiner.Pipe)
|
||||||
|
{
|
||||||
|
|
||||||
|
Point point9 = new Point(_startPosX.Value + 90, _startPosY.Value + 10);
|
||||||
|
Point point10 = new Point(_startPosX.Value + 90, _startPosY.Value + 40);
|
||||||
|
Point point11 = new Point(_startPosX.Value + 115, _startPosY.Value + 40);
|
||||||
|
Point point12 = new Point(_startPosX.Value + 115, _startPosY.Value + 10);
|
||||||
|
Point[] curvePoints3 = { point9, point10, point11, point12 };
|
||||||
|
g.FillPolygon(br, curvePoints3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,32 +0,0 @@
|
|||||||
namespace ProjectLiner.Drawnings;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Направление перемещения
|
|
||||||
/// </summary>
|
|
||||||
public enum DirectionType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Неизвестное направление
|
|
||||||
/// </summary>
|
|
||||||
Unknow = -1,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вверх
|
|
||||||
/// </summary>
|
|
||||||
Up = 1,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вниз
|
|
||||||
/// </summary>
|
|
||||||
Down = 2,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Влево
|
|
||||||
/// </summary>
|
|
||||||
Left = 3,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вправо
|
|
||||||
/// </summary>
|
|
||||||
Right = 4
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
using ProjectLiner.Entities;
|
|
||||||
|
|
||||||
namespace ProjectLiner.Drawnings;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|
||||||
/// </summary>
|
|
||||||
public class DrawningLiner : DrawningCommonLiner
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodycolor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="anchor">Признак наличия якоря</param>
|
|
||||||
/// <param name="boats">Признак наличия шлюпок</param>
|
|
||||||
/// <param name="pipe">Признак наличия трубы</param>
|
|
||||||
public DrawningLiner(int speed, double weight, Color bodycolor, Color additionalColor, bool anchor, bool boats, bool pipe) : base(150, 125)
|
|
||||||
{
|
|
||||||
EntityCommonLiner = new EntityLiner(speed, weight, bodycolor, additionalColor, anchor, boats, pipe);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (EntityCommonLiner == null || EntityCommonLiner is not EntityLiner liner || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
|
||||||
Brush additionalBrush = new SolidBrush(liner.AdditionalColor);
|
|
||||||
Brush br = new SolidBrush(liner.BodyColor);
|
|
||||||
|
|
||||||
_startPosY += 40;
|
|
||||||
base.DrawTransport(g);
|
|
||||||
_startPosY -= 40;
|
|
||||||
|
|
||||||
|
|
||||||
// якорь
|
|
||||||
if (liner.Anchor)
|
|
||||||
{
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 85, _startPosX.Value + 45, _startPosY.Value + 115);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 30, _startPosY.Value + 95, _startPosX.Value + 60, _startPosY.Value + 95);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 25, _startPosY.Value + 100, _startPosX.Value + 45, _startPosY.Value + 115);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 115, _startPosX.Value + 65, _startPosY.Value + 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
// шлюпки
|
|
||||||
if (liner.Boats)
|
|
||||||
{
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 85, 30, 15);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 85, 30, 15);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 85, 30, 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
// труба
|
|
||||||
if (liner.Pipe)
|
|
||||||
{
|
|
||||||
|
|
||||||
Point point9 = new Point(_startPosX.Value + 90, _startPosY.Value + 10);
|
|
||||||
Point point10 = new Point(_startPosX.Value + 90, _startPosY.Value + 40);
|
|
||||||
Point point11 = new Point(_startPosX.Value + 115, _startPosY.Value + 40);
|
|
||||||
Point point12 = new Point(_startPosX.Value + 115, _startPosY.Value + 10);
|
|
||||||
Point[] curvePoints3 = { point9, point10, point11, point12 };
|
|
||||||
g.FillPolygon(additionalBrush, curvePoints3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-сущность обычного "Лайнера"
|
|
||||||
/// </summary>
|
|
||||||
|
|
||||||
namespace ProjectLiner.Entities
|
|
||||||
{
|
|
||||||
public class EntityCommonLiner
|
|
||||||
{
|
|
||||||
/// <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 double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор лайнера
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
|
|
||||||
public EntityCommonLiner(int speed, double weight, Color bodyColor)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,24 @@
|
|||||||
namespace ProjectLiner.Entities;
|
namespace ProjectLiner;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Лайнер"
|
/// Класс-сущность "Лайнер"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityLiner: EntityCommonLiner
|
public class EntityLiner
|
||||||
{
|
{
|
||||||
|
/// <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>
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
@ -26,17 +40,26 @@ public class EntityLiner: EntityCommonLiner
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Pipe { get; private set; }
|
public bool Pipe { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения автомобиля
|
||||||
|
/// </summary>
|
||||||
|
public double Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
/// <param name="anchor">Признак наличия якоря</param>
|
/// <param name="anchor">Признак наличия якоря</param>
|
||||||
/// <param name="boats">Признак наличия шлюпок</param>
|
/// <param name="boats">Признак наличия шлюпок</param>
|
||||||
/// <param name="pipe">Признак наличия трубы</param>
|
/// <param name="pipe">Признак наличия трубы</param>
|
||||||
public EntityLiner(int speed, double weight, Color bodyColor, Color additionalColor, bool anchor, bool boats, bool pipe) : base(speed, weight, bodyColor)
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool anchor, bool boats, bool pipe)
|
||||||
{
|
{
|
||||||
new EntityCommonLiner(speed, weight, bodyColor);
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
Anchor = anchor;
|
Anchor = anchor;
|
||||||
Boats = boats;
|
Boats = boats;
|
46
ProjectLiner/ProjectLiner/FormLiner.Designer.cs
generated
46
ProjectLiner/ProjectLiner/FormLiner.Designer.cs
generated
@ -34,9 +34,6 @@
|
|||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonCreateCommonLiner = new Button();
|
|
||||||
comboBoxStrategy = new ComboBox();
|
|
||||||
buttonStrategyStep = new Button();
|
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -53,11 +50,11 @@
|
|||||||
// buttonCreate
|
// buttonCreate
|
||||||
//
|
//
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreate.Location = new Point(12, 544);
|
buttonCreate.Location = new Point(12, 520);
|
||||||
buttonCreate.Name = "buttonCreate";
|
buttonCreate.Name = "buttonCreate";
|
||||||
buttonCreate.Size = new Size(203, 58);
|
buttonCreate.Size = new Size(150, 82);
|
||||||
buttonCreate.TabIndex = 1;
|
buttonCreate.TabIndex = 1;
|
||||||
buttonCreate.Text = "Создать Лайнер";
|
buttonCreate.Text = "Создать";
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
buttonCreate.Click += buttonCreate_Click;
|
buttonCreate.Click += buttonCreate_Click;
|
||||||
//
|
//
|
||||||
@ -109,45 +106,11 @@
|
|||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += ButtonMove_Click;
|
buttonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonCreateCommonLiner
|
|
||||||
//
|
|
||||||
buttonCreateCommonLiner.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreateCommonLiner.Location = new Point(221, 544);
|
|
||||||
buttonCreateCommonLiner.Name = "buttonCreateCommonLiner";
|
|
||||||
buttonCreateCommonLiner.Size = new Size(240, 58);
|
|
||||||
buttonCreateCommonLiner.TabIndex = 6;
|
|
||||||
buttonCreateCommonLiner.Text = "Создать Обычный Лайнер";
|
|
||||||
buttonCreateCommonLiner.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreateCommonLiner.Click += buttonCreateCommonLiner_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
|
||||||
//
|
|
||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxStrategy.FormattingEnabled = true;
|
|
||||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
|
||||||
comboBoxStrategy.Location = new Point(742, 12);
|
|
||||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
|
||||||
comboBoxStrategy.Size = new Size(194, 33);
|
|
||||||
comboBoxStrategy.TabIndex = 11;
|
|
||||||
//
|
|
||||||
// buttonStrategyStep
|
|
||||||
//
|
|
||||||
buttonStrategyStep.Location = new Point(816, 51);
|
|
||||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
|
||||||
buttonStrategyStep.Size = new Size(120, 37);
|
|
||||||
buttonStrategyStep.TabIndex = 12;
|
|
||||||
buttonStrategyStep.Text = "Шаг";
|
|
||||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
|
||||||
buttonStrategyStep.Click += buttonStrategyStep_Click;
|
|
||||||
//
|
|
||||||
// FormLiner
|
// FormLiner
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(11F, 25F);
|
AutoScaleDimensions = new SizeF(11F, 25F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(948, 614);
|
ClientSize = new Size(948, 614);
|
||||||
Controls.Add(buttonStrategyStep);
|
|
||||||
Controls.Add(comboBoxStrategy);
|
|
||||||
Controls.Add(buttonCreateCommonLiner);
|
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
@ -168,8 +131,5 @@
|
|||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonCreateCommonLiner;
|
|
||||||
private ComboBox comboBoxStrategy;
|
|
||||||
private Button buttonStrategyStep;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,20 +7,15 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using ProjectLiner.Drawnings;
|
|
||||||
using ProjectLiner.MovementStrategy;
|
|
||||||
|
|
||||||
namespace ProjectLiner
|
namespace ProjectLiner
|
||||||
{
|
{
|
||||||
public partial class FormLiner : Form
|
public partial class FormLiner : Form
|
||||||
{
|
{
|
||||||
private DrawningCommonLiner? _drawningCommonLiner;
|
private DrawningLiner? _drawningLiner;
|
||||||
|
|
||||||
private AbstractStrategy? _strategy;
|
|
||||||
public FormLiner()
|
public FormLiner()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_strategy = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -28,67 +23,35 @@ namespace ProjectLiner
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningCommonLiner == null)
|
if (_drawningLiner == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
Bitmap bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningCommonLiner.DrawTransport(gr);
|
_drawningLiner.DrawTransport(gr);
|
||||||
pictureBoxLiner.Image = bmp;
|
pictureBoxLiner.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создание объекта класса-перемещения
|
/// Обработка нажатия кнопки "Создать"
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">Тип создаваемого объекта</param>
|
|
||||||
private void CreateObject(string type)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case nameof(DrawningCommonLiner):
|
|
||||||
_drawningCommonLiner = new DrawningCommonLiner(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
|
||||||
break;
|
|
||||||
case nameof(DrawningLiner):
|
|
||||||
_drawningCommonLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
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)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
_drawningCommonLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
|
||||||
_drawningCommonLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
_strategy = null;
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Создать Лайнер"
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
CreateObject(nameof(DrawningLiner));
|
Random random = new();
|
||||||
}
|
EntityLiner liner = new EntityLiner();
|
||||||
|
liner.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
/// <summary>
|
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)),
|
||||||
/// </summary>
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
/// <param name="sender"></param>
|
_drawningLiner = new DrawningLiner();
|
||||||
/// <param name="e"></param>
|
_drawningLiner.Init(liner);
|
||||||
|
_drawningLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
|
||||||
private void buttonCreateCommonLiner_Click(object sender, EventArgs e)
|
_drawningLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
{
|
Draw();
|
||||||
CreateObject(nameof(DrawningCommonLiner));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -98,7 +61,7 @@ namespace ProjectLiner
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningCommonLiner == null)
|
if (_drawningLiner == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -108,16 +71,16 @@ namespace ProjectLiner
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result = _drawningCommonLiner.MoveTransport(DirectionType.Up);
|
result = _drawningLiner.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result = _drawningCommonLiner.MoveTransport(DirectionType.Down);
|
result = _drawningLiner.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result = _drawningCommonLiner.MoveTransport(DirectionType.Left);
|
result = _drawningLiner.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result = _drawningCommonLiner.MoveTransport(DirectionType.Right);
|
result = _drawningLiner.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,48 +89,5 @@ namespace ProjectLiner
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Шаг"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_drawningCommonLiner == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comboBoxStrategy.Enabled)
|
|
||||||
{
|
|
||||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
||||||
{
|
|
||||||
0 => new MoveToCenter(),
|
|
||||||
1 => new MoveToBorder(),
|
|
||||||
_ => null,
|
|
||||||
};
|
|
||||||
if (_strategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_strategy.SetData(new MoveableLiner(_drawningCommonLiner), pictureBoxLiner.Width, pictureBoxLiner.Height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_strategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
comboBoxStrategy.Enabled = false;
|
|
||||||
_strategy.MakeStep();
|
|
||||||
Draw();
|
|
||||||
|
|
||||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
||||||
{
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
_strategy = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,145 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectLiner.MovementStrategy;
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-стратегия перемещения объекта
|
|
||||||
/// </summary>
|
|
||||||
public abstract class AbstractStrategy
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещаемый объект
|
|
||||||
/// </summary>
|
|
||||||
private IMoveableObject? _moveableObject;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Статус перемещения
|
|
||||||
/// </summary>
|
|
||||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина поля
|
|
||||||
/// </summary>
|
|
||||||
protected int FieldWidth { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Высота поля
|
|
||||||
/// </summary>
|
|
||||||
protected int FieldHeight { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Статус перемещения
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public StrategyStatus GetStatus() { return _state; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Установка данных
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
|
||||||
/// <param name="width">Ширина поля</param>
|
|
||||||
/// <param name="height">Высота поля</param>
|
|
||||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
|
||||||
{
|
|
||||||
if (moveableObject == null)
|
|
||||||
{
|
|
||||||
_state = StrategyStatus.NotInit;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_state = StrategyStatus.InProgress;
|
|
||||||
_moveableObject = moveableObject;
|
|
||||||
FieldWidth = width;
|
|
||||||
FieldHeight = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения
|
|
||||||
/// </summary>
|
|
||||||
public void MakeStep()
|
|
||||||
{
|
|
||||||
if (_state != StrategyStatus.InProgress)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsTargetDestination())
|
|
||||||
{
|
|
||||||
_state = StrategyStatus.Finish;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MoveToTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение влево
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вправо
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вверх
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вниз
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Параметры объекта
|
|
||||||
/// </summary>
|
|
||||||
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected int? GetStep()
|
|
||||||
{
|
|
||||||
if (_state != StrategyStatus.InProgress)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return _moveableObject?.GetStep;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение к цели
|
|
||||||
/// </summary>
|
|
||||||
protected abstract void MoveToTarget();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Достигнута ли цель
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected abstract bool IsTargetDestination();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Попытка перемещения в требуемом направлении
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="movementDirection">Направление</param>
|
|
||||||
/// <returns>Результат попытки (true - удалось, false - неудача)</returns>
|
|
||||||
private bool MoveTo(MovementDirection movementDirection)
|
|
||||||
{
|
|
||||||
if (_state != StrategyStatus.InProgress)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectLiner.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Интерфейс для работы с перемещаемым объектом
|
|
||||||
/// </summary>
|
|
||||||
public interface IMoveableObject
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Получение координаты объекта
|
|
||||||
/// </summary>
|
|
||||||
ObjectParameters? GetObjectPosition { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг объекта
|
|
||||||
/// </summary>
|
|
||||||
int GetStep { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Попытка переместить объект в указанном направлении
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction">Направление</param>
|
|
||||||
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
|
||||||
bool TryMoveObject(MovementDirection direction);
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectLiner.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Стратегия перемещения объекта к правой нижней границы
|
|
||||||
/// </summary>
|
|
||||||
public class MoveToBorder : AbstractStrategy
|
|
||||||
{
|
|
||||||
protected override bool IsTargetDestination()
|
|
||||||
{
|
|
||||||
ObjectParameters? 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()
|
|
||||||
{
|
|
||||||
ObjectParameters? objParams = GetObjectParameters;
|
|
||||||
if (objParams == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int diffX = objParams.RightBorder - FieldWidth;
|
|
||||||
if (Math.Abs(diffX) > GetStep())
|
|
||||||
{
|
|
||||||
if (diffX > 0)
|
|
||||||
{
|
|
||||||
MoveLeft();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MoveRight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int diffY = objParams.DownBorder - FieldHeight;
|
|
||||||
if (Math.Abs(diffY) > GetStep())
|
|
||||||
{
|
|
||||||
if (diffY > 0)
|
|
||||||
{
|
|
||||||
MoveUp();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MoveDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectLiner.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Стратегия перемещения объекта в центр экрана
|
|
||||||
/// </summary>
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
using ProjectLiner.Drawnings;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectLiner.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-реализация IMoveableObject с использованием DrawningCommonLiner
|
|
||||||
/// </summary>
|
|
||||||
public class MoveableLiner : IMoveableObject
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Поле-объект класса DrawningCommonLiner или его наследника
|
|
||||||
/// </summary>
|
|
||||||
private readonly DrawningCommonLiner? _CommonLiner = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="CommonLiner">Объект класса DrawningCommonLiner</param>
|
|
||||||
public MoveableLiner(DrawningCommonLiner CommonLiner)
|
|
||||||
{
|
|
||||||
_CommonLiner = CommonLiner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectParameters? GetObjectPosition
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_CommonLiner == null || _CommonLiner.EntityCommonLiner == null || !_CommonLiner.GetPosX.HasValue || !_CommonLiner.GetPosY.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new ObjectParameters(_CommonLiner.GetPosX.Value, _CommonLiner.GetPosY.Value, _CommonLiner.GetWidth, _CommonLiner.GetHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetStep => (int)(_CommonLiner?.EntityCommonLiner?.Step ?? 0);
|
|
||||||
|
|
||||||
public bool TryMoveObject(MovementDirection direction)
|
|
||||||
{
|
|
||||||
if (_CommonLiner == null || _CommonLiner.EntityCommonLiner == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _CommonLiner.MoveTransport(GetDirectionType(direction));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Конвертация из MovementDirection в DirectionType
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction">MovementDirection</param>
|
|
||||||
/// <returns>DirectionType</returns>
|
|
||||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
|
||||||
{
|
|
||||||
return direction switch
|
|
||||||
{
|
|
||||||
MovementDirection.Left => DirectionType.Left,
|
|
||||||
MovementDirection.Right => DirectionType.Right,
|
|
||||||
MovementDirection.Up => DirectionType.Up,
|
|
||||||
MovementDirection.Down => DirectionType.Down,
|
|
||||||
_ => DirectionType.Unknow,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectLiner.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Параметры-координаты объекта
|
|
||||||
/// </summary>
|
|
||||||
public class ObjectParameters
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Координата X
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _x;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Координата Y
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _y;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина объекта
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _width;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Высота объекта
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _height;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Левая граница
|
|
||||||
/// </summary>
|
|
||||||
public int LeftBorder => _x;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Верхняя граница
|
|
||||||
/// </summary>
|
|
||||||
public int TopBorder => _y;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Правая граница
|
|
||||||
/// </summary>
|
|
||||||
public int RightBorder => _x + _width;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Нижняя граница
|
|
||||||
/// </summary>
|
|
||||||
public int DownBorder => _y + _height;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Середина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Середина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int ObjectMiddleVertical => _y + _height / 2;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">Координата X</param>
|
|
||||||
/// <param name="y">Координата Y</param>
|
|
||||||
/// <param name="width">Ширина объекта</param>
|
|
||||||
/// <param name="height">Высота объекта</param>
|
|
||||||
public ObjectParameters(int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
_x = x;
|
|
||||||
_y = y;
|
|
||||||
_width = width;
|
|
||||||
_height = height;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectLiner.MovementStrategy;
|
|
||||||
/// <summary>
|
|
||||||
/// Статус выполнения операции перемещения
|
|
||||||
/// </summary>
|
|
||||||
public enum StrategyStatus
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Все готово к началу
|
|
||||||
/// </summary>
|
|
||||||
NotInit,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Выполняется
|
|
||||||
/// </summary>
|
|
||||||
InProgress,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Завершено
|
|
||||||
/// </summary>
|
|
||||||
Finish
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user