Compare commits
No commits in common. "d33425108d8d230135725c282ba12d8b8b5be7b1" and "749f810416c7ae97b2de4dcb5a5cc0b6cd1ad305" have entirely different histories.
d33425108d
...
749f810416
@ -1,4 +1,4 @@
|
|||||||
namespace MotorBoat.Drawnings
|
namespace MotorBoat
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -6,10 +6,6 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public enum DirectionType
|
public enum DirectionType
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Неизвестное направление
|
|
||||||
/// </summary>
|
|
||||||
Unknow = -1,
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вверх
|
/// Вверх
|
||||||
/// </summary>
|
/// </summary>
|
@ -1,18 +1,14 @@
|
|||||||
using MotorBoat.Entities;
|
namespace MotorBoat
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MotorBoat.Drawnings
|
|
||||||
{
|
{
|
||||||
public class DrawningBoat
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningMotorBoat
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityBoat? EntityBoat { get; protected set; }
|
public EntityMotorBoat? EntityMotorBoat { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -24,65 +20,37 @@ namespace MotorBoat.Drawnings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки лодки
|
/// Левая координата прорисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected int? _startPosX;
|
private int? _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки лодки
|
/// Верхняя кооридната прорисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected int? _startPosY;
|
private int? _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки лодки
|
/// Ширина прорисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningBoatWidth = 143;
|
private readonly int _drawningBoatWidth = 153;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки лодки
|
/// Высота прорисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningBoatHeight = 38;
|
private readonly int _drawningBoatHeight = 75;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Координата Х объекта
|
/// Инициализация свойств
|
||||||
/// </summary>
|
|
||||||
public int? GetPosX => _startPosX;
|
|
||||||
/// <summary>
|
|
||||||
/// Координата Y объекта
|
|
||||||
/// </summary>
|
|
||||||
public int? GetPosY => _startPosY;
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int GetWidth => _drawningBoatWidth;
|
|
||||||
/// <summary>
|
|
||||||
/// Высота объекта
|
|
||||||
/// </summary>
|
|
||||||
public int GetHeight => _drawningBoatHeight;
|
|
||||||
/// <summary>
|
|
||||||
/// Пустой конструктор
|
|
||||||
/// </summary>
|
|
||||||
private DrawningBoat()
|
|
||||||
{
|
|
||||||
_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>
|
||||||
public DrawningBoat(int speed, double weight, Color bodyColor) : this()
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="protectiveGlass">Признак наличия защитного стекла</param>
|
||||||
|
/// <param name="engine">Признак наличия мотора</param>
|
||||||
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||||
|
bool protectiveGlass, bool engine)
|
||||||
{
|
{
|
||||||
EntityBoat = new EntityBoat(speed, weight, bodyColor);
|
EntityMotorBoat = new EntityMotorBoat();
|
||||||
}
|
EntityMotorBoat.Init(speed, weight, bodyColor, additionalColor, protectiveGlass, engine);
|
||||||
|
_pictureWidth = null;
|
||||||
/// <summary>
|
_pictureHeight = null;
|
||||||
/// Конструктор для наследников
|
_startPosX = null;
|
||||||
/// </summary>
|
_startPosY = null;
|
||||||
/// <param name="drawningBoatWidth">Ширина прорисовки лодки</param>
|
|
||||||
/// <param name="drawningBoatHeight">Высота прорисовки лодки</param>
|
|
||||||
protected DrawningBoat(int drawningBoatWidth, int drawningBoatHeight) : this()
|
|
||||||
{
|
|
||||||
_drawningBoatWidth = drawningBoatWidth;
|
|
||||||
_drawningBoatHeight = drawningBoatHeight;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
@ -158,7 +126,7 @@ namespace MotorBoat.Drawnings
|
|||||||
/// невозможно</returns>
|
/// невозможно</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityMotorBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -166,30 +134,30 @@ namespace MotorBoat.Drawnings
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntityBoat.Step > 0)
|
if (_startPosX.Value - EntityMotorBoat.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityBoat.Step;
|
_startPosX -= (int)EntityMotorBoat.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntityBoat.Step > 0)
|
if (_startPosY.Value - EntityMotorBoat.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityBoat.Step;
|
_startPosY -= (int)EntityMotorBoat.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вправо
|
//вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX.Value + _drawningBoatWidth + EntityBoat.Step < _pictureWidth)
|
if (_startPosX.Value + _drawningBoatWidth + EntityMotorBoat.Step < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityBoat.Step;
|
_startPosX += (int)EntityMotorBoat.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY.Value + _drawningBoatHeight + EntityBoat.Step < _pictureHeight)
|
if (_startPosY.Value + _drawningBoatHeight + EntityMotorBoat.Step < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityBoat.Step;
|
_startPosY += (int)EntityMotorBoat.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -201,25 +169,26 @@ namespace MotorBoat.Drawnings
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public virtual void DrawTransport(Graphics g)
|
public void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityBoat == null || !_startPosX.HasValue ||
|
if (EntityMotorBoat == null || !_startPosX.HasValue ||
|
||||||
!_startPosY.HasValue)
|
!_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush brushBodyColor = new SolidBrush(EntityBoat.BodyColor);
|
Brush brushBodyColor = new SolidBrush(EntityMotorBoat.BodyColor);
|
||||||
|
Brush brushAdditionalColor = new SolidBrush(EntityMotorBoat.AdditionalColor);
|
||||||
|
|
||||||
Point[] body =
|
Point[] body =
|
||||||
{
|
{
|
||||||
new Point(_startPosX.Value, _startPosY.Value),
|
new Point(_startPosX.Value + 10, _startPosY.Value + 25),
|
||||||
new Point(_startPosX.Value + 100, _startPosY.Value),
|
new Point(_startPosX.Value + 110, _startPosY.Value + 25),
|
||||||
new Point(_startPosX.Value + 145, _startPosY.Value + 20),
|
new Point(_startPosX.Value + 155, _startPosY.Value + 45),
|
||||||
new Point(_startPosX.Value + 100, _startPosY.Value + 40),
|
new Point(_startPosX.Value + 110, _startPosY.Value + 65),
|
||||||
new Point(_startPosX.Value, _startPosY.Value + 40),
|
new Point(_startPosX.Value + 10, _startPosY.Value + 65),
|
||||||
new Point(_startPosX.Value, _startPosY.Value)
|
new Point(_startPosX.Value + 10, _startPosY.Value + 25)
|
||||||
};
|
};
|
||||||
|
|
||||||
// корпус
|
// корпус
|
||||||
@ -227,11 +196,34 @@ namespace MotorBoat.Drawnings
|
|||||||
g.DrawPolygon(pen, body);
|
g.DrawPolygon(pen, body);
|
||||||
|
|
||||||
//боковина лодки
|
//боковина лодки
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 5, 30, 30);
|
g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 30, 30, 30);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 5, 30, 30);
|
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 30, 30, 30);
|
||||||
g.DrawLine(pen, _startPosX.Value + 27, _startPosY.Value + 5, _startPosX.Value + 73, _startPosY.Value + 5);
|
g.DrawLine(pen, _startPosX.Value + 37, _startPosY.Value + 30, _startPosX.Value + 83, _startPosY.Value + 30);
|
||||||
g.DrawLine(pen, _startPosX.Value + 27, _startPosY.Value + 35, _startPosX.Value + 73, _startPosY.Value + 35);
|
g.DrawLine(pen, _startPosX.Value + 37, _startPosY.Value + 60, _startPosX.Value + 83, _startPosY.Value + 60);
|
||||||
g.FillRectangle(brushBodyColor, _startPosX.Value + 27, _startPosY.Value + 6, 50, 29);
|
g.FillRectangle(brushBodyColor, _startPosX.Value + 37, _startPosY.Value + 31, 50, 29);
|
||||||
|
|
||||||
|
|
||||||
|
//защитное стекло спереди
|
||||||
|
if (EntityMotorBoat.ProtectiveGlass)
|
||||||
|
{
|
||||||
|
Point[] glass =
|
||||||
|
{
|
||||||
|
new Point(_startPosX.Value + 105, _startPosY.Value + 25),
|
||||||
|
new Point(_startPosX.Value + 100, _startPosY.Value),
|
||||||
|
new Point(_startPosX.Value + 90, _startPosY.Value),
|
||||||
|
new Point(_startPosX.Value + 90, _startPosY.Value + 25),
|
||||||
|
new Point(_startPosX.Value + 105, _startPosY.Value + 25)
|
||||||
|
};
|
||||||
|
g.FillPolygon(brushAdditionalColor, glass);
|
||||||
|
g.DrawPolygon(pen, glass);
|
||||||
|
}
|
||||||
|
|
||||||
|
//мотор
|
||||||
|
if (EntityMotorBoat.Engine)
|
||||||
|
{
|
||||||
|
g.FillRectangle(brushAdditionalColor, _startPosX.Value, _startPosY.Value + 50, 10, 25);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 50, 10, 25);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,65 +0,0 @@
|
|||||||
using MotorBoat.Entities;
|
|
||||||
|
|
||||||
namespace MotorBoat.Drawnings
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|
||||||
/// </summary>
|
|
||||||
public class DrawningMotorBoat : DrawningBoat
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="protectiveGlass">Признак наличия защитного стекла</param>
|
|
||||||
/// <param name="engine">Признак наличия мотора</param>
|
|
||||||
public DrawningMotorBoat(int speed, double weight, Color bodyColor, Color additionalColor,
|
|
||||||
bool protectiveGlass, bool engine) : base(153, 75)
|
|
||||||
{
|
|
||||||
EntityBoat = new EntityMotorBoat(speed, weight, bodyColor, additionalColor, protectiveGlass, engine);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Прорисовка объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
public override void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (EntityBoat == null || EntityBoat is not EntityMotorBoat motorBoat
|
|
||||||
|| !_startPosX.HasValue || !_startPosY.HasValue)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Pen pen = new(Color.Black);
|
|
||||||
Brush brushAdditionalColor = new SolidBrush(motorBoat.AdditionalColor);
|
|
||||||
|
|
||||||
//защитное стекло спереди
|
|
||||||
if (motorBoat.ProtectiveGlass)
|
|
||||||
{
|
|
||||||
Point[] glass =
|
|
||||||
{
|
|
||||||
new Point(_startPosX.Value + 105, _startPosY.Value + 25),
|
|
||||||
new Point(_startPosX.Value + 100, _startPosY.Value),
|
|
||||||
new Point(_startPosX.Value + 90, _startPosY.Value),
|
|
||||||
new Point(_startPosX.Value + 90, _startPosY.Value + 25),
|
|
||||||
new Point(_startPosX.Value + 105, _startPosY.Value + 25)
|
|
||||||
};
|
|
||||||
g.FillPolygon(brushAdditionalColor, glass);
|
|
||||||
g.DrawPolygon(pen, glass);
|
|
||||||
}
|
|
||||||
_startPosX += 10;
|
|
||||||
_startPosY += 25;
|
|
||||||
base.DrawTransport(g);
|
|
||||||
_startPosX -= 10;
|
|
||||||
_startPosY -= 25;
|
|
||||||
//мотор
|
|
||||||
if (motorBoat.Engine)
|
|
||||||
{
|
|
||||||
g.FillRectangle(brushAdditionalColor, _startPosX.Value, _startPosY.Value + 50, 10, 25);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 50, 10, 25);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MotorBoat.Entities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-сущность "Лодка"
|
|
||||||
/// </summary>
|
|
||||||
public class EntityBoat
|
|
||||||
{
|
|
||||||
/// <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 EntityBoat(int speed, double weight, Color bodyColor)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,22 @@
|
|||||||
namespace MotorBoat.Entities
|
namespace MotorBoat
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Моторная лодка"
|
/// Класс-сущность "Моторная лодка"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityMotorBoat : EntityBoat
|
public class EntityMotorBoat
|
||||||
{
|
{
|
||||||
|
/// <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>
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -30,9 +42,12 @@
|
|||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
/// <param name="protectiveGlass">Признак наличия защитного стекла</param>
|
/// <param name="protectiveGlass">Признак наличия защитного стекла</param>
|
||||||
/// <param name="engine">Признак наличия мотора</param>
|
/// <param name="engine">Признак наличия мотора</param>
|
||||||
public EntityMotorBoat(int speed, double weight, Color bodyColor, Color additionalColor,
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||||
bool protectiveGlass, bool engine) : base(speed, weight, bodyColor)
|
bool protectiveGlass, bool engine)
|
||||||
{
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
ProtectiveGlass = protectiveGlass;
|
ProtectiveGlass = protectiveGlass;
|
||||||
Engine = engine;
|
Engine = engine;
|
64
MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
generated
64
MotorBoat/MotorBoat/FormMotorBoat.Designer.cs
generated
@ -29,14 +29,11 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxMotorBoat = new PictureBox();
|
pictureBoxMotorBoat = new PictureBox();
|
||||||
buttonCreateMotorBoat = new Button();
|
buttonCreate = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonCreateBoat = new Button();
|
|
||||||
comboBoxStrategy = new ComboBox();
|
|
||||||
buttonStrategyStep = new Button();
|
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -49,16 +46,16 @@
|
|||||||
pictureBoxMotorBoat.TabIndex = 0;
|
pictureBoxMotorBoat.TabIndex = 0;
|
||||||
pictureBoxMotorBoat.TabStop = false;
|
pictureBoxMotorBoat.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreateMotorBoat
|
// buttonCreate
|
||||||
//
|
//
|
||||||
buttonCreateMotorBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateMotorBoat.Location = new Point(12, 412);
|
buttonCreate.Location = new Point(12, 412);
|
||||||
buttonCreateMotorBoat.Name = "buttonCreateMotorBoat";
|
buttonCreate.Name = "buttonCreate";
|
||||||
buttonCreateMotorBoat.Size = new Size(174, 23);
|
buttonCreate.Size = new Size(75, 23);
|
||||||
buttonCreateMotorBoat.TabIndex = 1;
|
buttonCreate.TabIndex = 1;
|
||||||
buttonCreateMotorBoat.Text = "Создать моторную лодку";
|
buttonCreate.Text = "Создать";
|
||||||
buttonCreateMotorBoat.UseVisualStyleBackColor = true;
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
buttonCreateMotorBoat.Click += ButtonCreateMotorBoat_Click;
|
buttonCreate.Click += ButtonCreateMotorBoat_Click;
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
@ -108,50 +105,16 @@
|
|||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += ButtonMove_Click;
|
buttonUp.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonCreateBoat
|
|
||||||
//
|
|
||||||
buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreateBoat.Location = new Point(203, 412);
|
|
||||||
buttonCreateBoat.Name = "buttonCreateBoat";
|
|
||||||
buttonCreateBoat.Size = new Size(174, 23);
|
|
||||||
buttonCreateBoat.TabIndex = 6;
|
|
||||||
buttonCreateBoat.Text = "Создать лодку";
|
|
||||||
buttonCreateBoat.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreateBoat.Click += ButtonCreateBoat_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
|
||||||
//
|
|
||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxStrategy.FormattingEnabled = true;
|
|
||||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
|
||||||
comboBoxStrategy.Location = new Point(724, 12);
|
|
||||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
|
||||||
comboBoxStrategy.Size = new Size(121, 23);
|
|
||||||
comboBoxStrategy.TabIndex = 7;
|
|
||||||
//
|
|
||||||
// buttonStrategyStep
|
|
||||||
//
|
|
||||||
buttonStrategyStep.Location = new Point(774, 41);
|
|
||||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
|
||||||
buttonStrategyStep.Size = new Size(75, 23);
|
|
||||||
buttonStrategyStep.TabIndex = 8;
|
|
||||||
buttonStrategyStep.Text = "Шаг";
|
|
||||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
|
||||||
buttonStrategyStep.Click += buttonStrategyStep_Click;
|
|
||||||
//
|
|
||||||
// FormMotorBoat
|
// FormMotorBoat
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(861, 447);
|
ClientSize = new Size(861, 447);
|
||||||
Controls.Add(buttonStrategyStep);
|
|
||||||
Controls.Add(comboBoxStrategy);
|
|
||||||
Controls.Add(buttonCreateBoat);
|
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonCreateMotorBoat);
|
Controls.Add(buttonCreate);
|
||||||
Controls.Add(pictureBoxMotorBoat);
|
Controls.Add(pictureBoxMotorBoat);
|
||||||
Name = "FormMotorBoat";
|
Name = "FormMotorBoat";
|
||||||
Text = "Моторная лодка";
|
Text = "Моторная лодка";
|
||||||
@ -162,13 +125,10 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxMotorBoat;
|
private PictureBox pictureBoxMotorBoat;
|
||||||
private Button buttonCreateMotorBoat;
|
private Button buttonCreate;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonCreateBoat;
|
|
||||||
private ComboBox comboBoxStrategy;
|
|
||||||
private Button buttonStrategyStep;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,91 +7,62 @@ 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 MotorBoat.Drawnings;
|
|
||||||
using MotorBoat.MovementStrategy;
|
|
||||||
|
|
||||||
namespace MotorBoat
|
namespace MotorBoat
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Форма работы с объектом "Моторная лодка"
|
|
||||||
/// </summary>
|
|
||||||
public partial class FormMotorBoat : Form
|
public partial class FormMotorBoat : Form
|
||||||
{
|
{
|
||||||
/// <summary>
|
private DrawningMotorBoat? _drawningMotorBoat;
|
||||||
/// Поле для прорисовки объекта
|
|
||||||
/// </summary>
|
|
||||||
private DrawningBoat? _drawningBoat;
|
|
||||||
/// <summary>
|
|
||||||
/// Стратегия перемещения
|
|
||||||
/// </summary>
|
|
||||||
private AbstractStrategy? _strategy;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор формы
|
/// Конструктор формы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormMotorBoat()
|
public FormMotorBoat()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_strategy = null;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод прорисовки катера
|
/// Метод прорисовки катера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningBoat == null)
|
if (_drawningMotorBoat == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxMotorBoat.Width,
|
Bitmap bmp = new(pictureBoxMotorBoat.Width,
|
||||||
pictureBoxMotorBoat.Height);
|
pictureBoxMotorBoat.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningBoat.DrawTransport(gr);
|
_drawningMotorBoat.DrawTransport(gr);
|
||||||
pictureBoxMotorBoat.Image = bmp;
|
pictureBoxMotorBoat.Image = bmp;
|
||||||
}
|
}
|
||||||
private void CreateObject(string type)
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreateMotorBoat_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new();
|
||||||
switch (type)
|
_drawningMotorBoat = new DrawningMotorBoat();
|
||||||
{
|
_drawningMotorBoat.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
case nameof(DrawningBoat):
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
_drawningBoat = new DrawningBoat(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)),
|
||||||
break;
|
Convert.ToBoolean(random.Next(0, 2)));
|
||||||
case nameof(DrawningMotorBoat):
|
_drawningMotorBoat.SetPictureSize(pictureBoxMotorBoat.Width,
|
||||||
_drawningBoat = new DrawningMotorBoat(random.Next(100, 300), random.Next(1000, 3000),
|
pictureBoxMotorBoat.Height);
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
_drawningMotorBoat.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
100));
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_drawningBoat.SetPictureSize(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
|
||||||
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
_strategy = null;
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработка нажатия кнопки "Создать моторную лодку"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonCreateMotorBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMotorBoat));
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Создать лодку"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonCreateBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat));
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <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 (_drawningBoat == null)
|
if (_drawningMotorBoat == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -101,19 +72,19 @@ namespace MotorBoat
|
|||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result =
|
result =
|
||||||
_drawningBoat.MoveTransport(DirectionType.Up);
|
_drawningMotorBoat.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result =
|
result =
|
||||||
_drawningBoat.MoveTransport(DirectionType.Down);
|
_drawningMotorBoat.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result =
|
result =
|
||||||
_drawningBoat.MoveTransport(DirectionType.Left);
|
_drawningMotorBoat.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result =
|
result =
|
||||||
_drawningBoat.MoveTransport(DirectionType.Right);
|
_drawningMotorBoat.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (result)
|
if (result)
|
||||||
@ -121,46 +92,5 @@ namespace MotorBoat
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_drawningBoat == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (comboBoxStrategy.Enabled)
|
|
||||||
{
|
|
||||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
||||||
{
|
|
||||||
0 => new MoveToCenter(),
|
|
||||||
1 => new MoveToBorder(),
|
|
||||||
_ => null,
|
|
||||||
};
|
|
||||||
if (_strategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_strategy.SetData(new MoveableBoat(_drawningBoat),
|
|
||||||
pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
|
||||||
}
|
|
||||||
if (_strategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
comboBoxStrategy.Enabled = false;
|
|
||||||
_strategy.MakeStep();
|
|
||||||
Draw();
|
|
||||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
||||||
{
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
_strategy = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,119 +0,0 @@
|
|||||||
namespace MotorBoat.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>
|
|
||||||
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 (IsTargetDestinaion())
|
|
||||||
{
|
|
||||||
_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 IsTargetDestinaion();
|
|
||||||
/// <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,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MotorBoat.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,44 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MotorBoat.MovementStrategy;
|
|
||||||
/// <summary>
|
|
||||||
/// Стратегия перемещения объекта к краю экрана
|
|
||||||
/// </summary>
|
|
||||||
public class MoveToBorder : AbstractStrategy
|
|
||||||
{
|
|
||||||
protected override bool IsTargetDestinaion()
|
|
||||||
{
|
|
||||||
ObjectParameters? objParams = GetObjectParameters;
|
|
||||||
if (objParams == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return objParams.RightBorder + GetStep() >= FieldWidth &&
|
|
||||||
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())
|
|
||||||
{
|
|
||||||
MoveRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
int diffY = objParams.DownBorder - FieldHeight;
|
|
||||||
if (Math.Abs(diffY) > GetStep())
|
|
||||||
{
|
|
||||||
MoveDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MotorBoat.MovementStrategy;
|
|
||||||
/// <summary>
|
|
||||||
/// Стратегия перемещения объекта в центр экрана
|
|
||||||
/// </summary>
|
|
||||||
public class MoveToCenter : AbstractStrategy
|
|
||||||
{
|
|
||||||
protected override bool IsTargetDestinaion()
|
|
||||||
{
|
|
||||||
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,59 +0,0 @@
|
|||||||
using MotorBoat.Drawnings;
|
|
||||||
|
|
||||||
namespace MotorBoat.MovementStrategy;
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-реализация IMoveableObject с использованием DrawningBoat
|
|
||||||
/// </summary>
|
|
||||||
public class MoveableBoat : IMoveableObject
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Поле-объект класса DrawningBoat или его наследника
|
|
||||||
/// </summary>
|
|
||||||
private readonly DrawningBoat? _boat = null;
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="car">Объект класса DrawningBoat</param>
|
|
||||||
public MoveableBoat(DrawningBoat boat)
|
|
||||||
{
|
|
||||||
_boat = boat;
|
|
||||||
}
|
|
||||||
public ObjectParameters? GetObjectPosition
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_boat == null || _boat.EntityBoat == null ||
|
|
||||||
!_boat.GetPosX.HasValue || !_boat.GetPosY.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new ObjectParameters(_boat.GetPosX.Value,
|
|
||||||
_boat.GetPosY.Value, _boat.GetWidth, _boat.GetHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public int GetStep => (int)(_boat?.EntityBoat?.Step ?? 0);
|
|
||||||
public bool TryMoveObject(MovementDirection direction)
|
|
||||||
{
|
|
||||||
if (_boat == null || _boat.EntityBoat == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return _boat.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,24 +0,0 @@
|
|||||||
namespace MotorBoat.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Направление перемещения
|
|
||||||
/// </summary>
|
|
||||||
public enum MovementDirection
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Вверх
|
|
||||||
/// </summary>
|
|
||||||
Up = 1,
|
|
||||||
/// <summary>
|
|
||||||
/// Вниз
|
|
||||||
/// </summary>
|
|
||||||
Down = 2,
|
|
||||||
/// <summary>
|
|
||||||
/// Влево
|
|
||||||
/// </summary>
|
|
||||||
Left = 3,
|
|
||||||
/// <summary>
|
|
||||||
/// Вправо
|
|
||||||
/// </summary>
|
|
||||||
Right = 4
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
namespace MotorBoat.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,19 +0,0 @@
|
|||||||
namespace MotorBoat.MovementStrategy;
|
|
||||||
/// <summary>
|
|
||||||
/// Статус выполнения операции перемещения
|
|
||||||
/// </summary>
|
|
||||||
public enum StrategyStatus
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Все готово к началу
|
|
||||||
/// </summary>
|
|
||||||
NotInit,
|
|
||||||
/// <summary>
|
|
||||||
/// Выполняется
|
|
||||||
/// </summary>
|
|
||||||
InProgress,
|
|
||||||
/// <summary>
|
|
||||||
/// Завершено
|
|
||||||
/// </summary>
|
|
||||||
Finish
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user