done lab2
This commit is contained in:
parent
86c2222509
commit
430bc0b3f3
@ -1,13 +1,17 @@
|
|||||||
namespace ProjectCruiser;
|
namespace ProjectCruiser.Drawnings;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum DirectionType
|
public enum DirectionType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ââĺđő
|
/// Неизвестное направление
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Up = 1,
|
Unknow = -1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вниз
|
/// Вниз
|
||||||
/// </summary>
|
/// </summary>
|
@ -1,6 +1,6 @@
|
|||||||
using System.Drawing.Drawing2D;
|
using ProjectCruiser.Entities;
|
||||||
|
|
||||||
namespace ProjectCruiser;
|
namespace ProjectCruiser.Drawnings;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -9,7 +9,7 @@ public class DrawningCruiser
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityCruiser? EntityCruiser { get; private set; }
|
public EntityCruiser? EntityCruiser { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -21,11 +21,11 @@ public class DrawningCruiser
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки автомобиля
|
/// Левая координата прорисовки автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosX;
|
protected int? _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки автомобиля
|
/// Верхняя кооридната прорисовки автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
protected int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки крейсера
|
/// Ширина прорисовки крейсера
|
||||||
@ -36,27 +36,56 @@ public class DrawningCruiser
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningCruiserHeight = 50;
|
private readonly int _drawningCruiserHeight = 50;
|
||||||
private readonly int _drawningEnginesWidth = 3;
|
private readonly int _drawningEnginesWidth = 3;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Координата X объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
public int? GetPosX => _startPosX;
|
||||||
/// <param name="weight">Вес</param>
|
/// <summary>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// Координата Y объекта
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
/// </summary>
|
||||||
/// <param name="helicopterArea">Признак наличия вертолетной площадки</param>
|
public int? GetPosY => _startPosY;
|
||||||
/// <param name="boat">Признак наличия шлюпок</param>
|
/// <summary>
|
||||||
/// <param name="wepon">Признак наличия пушки</param>
|
/// Ширина объекта
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
/// </summary>
|
||||||
additionalColor, bool helicopterArea, bool boat, bool wepon)
|
public int GetWidth => _drawningCruiserWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => _drawningCruiserHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Пустой онструктор
|
||||||
|
/// </summary>
|
||||||
|
private DrawningCruiser()
|
||||||
{
|
{
|
||||||
EntityCruiser = new EntityCruiser();
|
|
||||||
EntityCruiser.Init(speed, weight, bodyColor, additionalColor,
|
|
||||||
helicopterArea, boat, wepon);
|
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = null;
|
_startPosY = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public DrawningCruiser(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор для наследников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningCarWidth">Ширина прорисовки автомобиля</param>
|
||||||
|
/// <param name="drawningCarHeight">Высота прорисовки автомобиля</param>
|
||||||
|
protected DrawningCruiser(int drawningCarWidth, int drawningCarHeight) : this()
|
||||||
|
{
|
||||||
|
_drawningCruiserWidth = drawningCarWidth;
|
||||||
|
_pictureHeight = drawningCarHeight;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -96,7 +125,7 @@ public class DrawningCruiser
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x < 0 || x + _drawningCruiserWidth > _pictureWidth || y < 0 || y + _drawningCruiserHeight > _pictureHeight)
|
if (x < 0 || x + _drawningCruiserWidth > _pictureWidth || y < 0 || y + _drawningCruiserHeight > _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosX = _pictureWidth - _drawningCruiserWidth;
|
_startPosX = _pictureWidth - _drawningCruiserWidth;
|
||||||
_startPosY = _pictureHeight - _drawningCruiserHeight;
|
_startPosY = _pictureHeight - _drawningCruiserHeight;
|
||||||
@ -158,7 +187,7 @@ public class DrawningCruiser
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityCruiser == null || !_startPosX.HasValue ||
|
if (EntityCruiser == null || !_startPosX.HasValue ||
|
||||||
!_startPosY.HasValue)
|
!_startPosY.HasValue)
|
||||||
@ -167,10 +196,6 @@ public class DrawningCruiser
|
|||||||
}
|
}
|
||||||
Pen pen = new(EntityCruiser.BodyColor, 2);
|
Pen pen = new(EntityCruiser.BodyColor, 2);
|
||||||
Brush additionalBrush = new SolidBrush(Color.Black);
|
Brush additionalBrush = new SolidBrush(Color.Black);
|
||||||
Brush weaponBrush = new SolidBrush(Color.Black);
|
|
||||||
Brush weaponBrush2 = new SolidBrush(EntityCruiser.AdditionalColor);
|
|
||||||
Brush helicopterAreaBrush = new HatchBrush(HatchStyle.ZigZag, EntityCruiser.AdditionalColor, Color.FromArgb(163, 163, 163));
|
|
||||||
Brush boatBrush = new SolidBrush(EntityCruiser.AdditionalColor);
|
|
||||||
|
|
||||||
//границы круисера
|
//границы круисера
|
||||||
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value + 105, _startPosY.Value);
|
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value + 105, _startPosY.Value);
|
||||||
@ -191,28 +216,5 @@ public class DrawningCruiser
|
|||||||
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 7, 3, 14);
|
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 7, 3, 14);
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 26, 3, 14);
|
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 26, 3, 14);
|
||||||
|
|
||||||
if (EntityCruiser.HelicopterArea)
|
|
||||||
{
|
|
||||||
g.FillEllipse(helicopterAreaBrush, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EntityCruiser.Boat)
|
|
||||||
{
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
|
||||||
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
|
||||||
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
|
||||||
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EntityCruiser.Weapon)
|
|
||||||
{
|
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
|
||||||
g.FillEllipse(weaponBrush2, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
|
||||||
|
|
||||||
g.FillRectangle(weaponBrush, _startPosX.Value + 107, _startPosY.Value + 40, 15, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
67
ProjectCruiser/Drawnings/DrawningMilitaryCruiser.cs
Normal file
67
ProjectCruiser/Drawnings/DrawningMilitaryCruiser.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using ProjectCruiser.Entities;
|
||||||
|
|
||||||
|
namespace ProjectCruiser.Drawnings
|
||||||
|
{
|
||||||
|
public class DrawningMilitaryCruiser : DrawningCruiser
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="helicopterArea">Признак наличия вертолетной площадки</param>
|
||||||
|
/// <param name="boat">Признак наличия шлюпок</param>
|
||||||
|
/// <param name="weapon">Признак наличия пушки</param>
|
||||||
|
|
||||||
|
public DrawningMilitaryCruiser(int speed, double weight, Color bodyColor, Color additionalColor, bool helicopterArea, bool boat, bool weapon)
|
||||||
|
: base(150, 50)
|
||||||
|
{
|
||||||
|
EntityCruiser = new EntityMilitaryCruiser(speed, weight, bodyColor, additionalColor, helicopterArea, boat, weapon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityCruiser == null || EntityCruiser is not EntityMilitaryCruiser entityMilitaryCruiser || !_startPosX.HasValue ||
|
||||||
|
!_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(entityMilitaryCruiser.BodyColor, 2);
|
||||||
|
Brush additionalBrush = new SolidBrush(Color.Black);
|
||||||
|
Brush weaponBrush = new SolidBrush(Color.Black);
|
||||||
|
Brush weaponBrush2 = new SolidBrush(entityMilitaryCruiser.AdditionalColor);
|
||||||
|
Brush helicopterAreaBrush = new HatchBrush(HatchStyle.ZigZag, entityMilitaryCruiser.AdditionalColor, Color.FromArgb(163, 163, 163));
|
||||||
|
Brush boatBrush = new SolidBrush(entityMilitaryCruiser.AdditionalColor);
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
if (entityMilitaryCruiser.HelicopterArea)
|
||||||
|
{
|
||||||
|
g.FillEllipse(helicopterAreaBrush, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityMilitaryCruiser.Boat)
|
||||||
|
{
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
||||||
|
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
||||||
|
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
||||||
|
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityMilitaryCruiser.Weapon)
|
||||||
|
{
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
||||||
|
g.FillEllipse(weaponBrush2, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
||||||
|
|
||||||
|
g.FillRectangle(weaponBrush, _startPosX.Value + 107, _startPosY.Value + 40, 15, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
ProjectCruiser/Entities/EntityCruiser.cs
Normal file
38
ProjectCruiser/Entities/EntityCruiser.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
namespace ProjectCruiser.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "крейсер"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityCruiser
|
||||||
|
{
|
||||||
|
//свойства
|
||||||
|
/// <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 EntityCruiser(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
30
ProjectCruiser/Entities/EntityMilitaryCruiser.cs
Normal file
30
ProjectCruiser/Entities/EntityMilitaryCruiser.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
namespace ProjectCruiser.Entities
|
||||||
|
{
|
||||||
|
internal class EntityMilitaryCruiser : EntityCruiser
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличие вертолетной площадки
|
||||||
|
/// </summary>
|
||||||
|
public bool HelicopterArea { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличие шлюпок
|
||||||
|
/// </summary>
|
||||||
|
public bool Boat { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличие пушки
|
||||||
|
/// </summary>
|
||||||
|
public bool Weapon { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
|
/// </summary>
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
|
||||||
|
public EntityMilitaryCruiser(int speed, double weight, Color bodyColor, Color additionalColor, bool helicopterArea, bool boat, bool weapon) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
HelicopterArea = helicopterArea;
|
||||||
|
Boat = boat;
|
||||||
|
Weapon = weapon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,62 +0,0 @@
|
|||||||
namespace ProjectCruiser;
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-сущность "крейсер"
|
|
||||||
/// </summary>
|
|
||||||
public class EntityCruiser
|
|
||||||
{
|
|
||||||
//свойства
|
|
||||||
/// <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 HelicopterArea { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак (опция) наличие шлюпок
|
|
||||||
/// </summary>
|
|
||||||
public bool Boat { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак (опция) наличие пушки
|
|
||||||
/// </summary>
|
|
||||||
public bool Weapon { 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>
|
|
||||||
/// <param name="additionalColor">дополнительный цвет</param>
|
|
||||||
/// <param name="helicopterArea">вертолетная площадка</param>
|
|
||||||
/// <param name="boat">шлюпки</param>
|
|
||||||
/// <param name="wepon">наличие пушки</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, bool helicopterArea, bool boat, bool wepon)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
HelicopterArea = helicopterArea;
|
|
||||||
Boat = boat;
|
|
||||||
Weapon = wepon;
|
|
||||||
}
|
|
||||||
}
|
|
75
ProjectCruiser/FormCruiser.Designer.cs
generated
75
ProjectCruiser/FormCruiser.Designer.cs
generated
@ -29,33 +29,36 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCruiser));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCruiser));
|
||||||
pictureBox1 = new PictureBox();
|
pictureBoxCruiser = new PictureBox();
|
||||||
button1 = new Button();
|
button1 = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonCretaeCruiser = new Button();
|
||||||
|
buttonStrategyStep = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBox1
|
// pictureBoxCruiser
|
||||||
//
|
//
|
||||||
pictureBox1.Dock = DockStyle.Fill;
|
pictureBoxCruiser.Dock = DockStyle.Fill;
|
||||||
pictureBox1.Location = new Point(0, 0);
|
pictureBoxCruiser.Location = new Point(0, 0);
|
||||||
pictureBox1.Name = "pictureBox1";
|
pictureBoxCruiser.Name = "pictureBoxCruiser";
|
||||||
pictureBox1.Size = new Size(800, 450);
|
pictureBoxCruiser.Size = new Size(800, 450);
|
||||||
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
|
pictureBoxCruiser.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBox1.TabIndex = 0;
|
pictureBoxCruiser.TabIndex = 0;
|
||||||
pictureBox1.TabStop = false;
|
pictureBoxCruiser.TabStop = false;
|
||||||
//
|
//
|
||||||
// button1
|
// button1
|
||||||
//
|
//
|
||||||
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
button1.Location = new Point(12, 409);
|
button1.Location = new Point(12, 409);
|
||||||
button1.Name = "button1";
|
button1.Name = "button1";
|
||||||
button1.Size = new Size(94, 29);
|
button1.Size = new Size(213, 29);
|
||||||
button1.TabIndex = 1;
|
button1.TabIndex = 1;
|
||||||
button1.Text = "создать";
|
button1.Text = "создать военный крейсер";
|
||||||
button1.UseVisualStyleBackColor = true;
|
button1.UseVisualStyleBackColor = true;
|
||||||
button1.Click += ButtonCreateCruiser_Click;
|
button1.Click += ButtonCreateCruiser_Click;
|
||||||
//
|
//
|
||||||
@ -107,32 +110,70 @@
|
|||||||
buttonLeft.UseVisualStyleBackColor = true;
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
buttonLeft.Click += ButtonMove_Click;
|
buttonLeft.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// Form1
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к краю" });
|
||||||
|
comboBoxStrategy.Location = new Point(637, 12);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(151, 28);
|
||||||
|
comboBoxStrategy.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// buttonCretaeCruiser
|
||||||
|
//
|
||||||
|
buttonCretaeCruiser.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCretaeCruiser.Location = new Point(240, 410);
|
||||||
|
buttonCretaeCruiser.Name = "buttonCretaeCruiser";
|
||||||
|
buttonCretaeCruiser.Size = new Size(213, 29);
|
||||||
|
buttonCretaeCruiser.TabIndex = 7;
|
||||||
|
buttonCretaeCruiser.Text = "создать крейсер";
|
||||||
|
buttonCretaeCruiser.UseVisualStyleBackColor = true;
|
||||||
|
buttonCretaeCruiser.Click += buttonCretaeCruiser_Click;
|
||||||
|
//
|
||||||
|
// buttonStrategyStep
|
||||||
|
//
|
||||||
|
buttonStrategyStep.Location = new Point(694, 46);
|
||||||
|
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||||
|
buttonStrategyStep.Size = new Size(94, 29);
|
||||||
|
buttonStrategyStep.TabIndex = 8;
|
||||||
|
buttonStrategyStep.Text = "шаг";
|
||||||
|
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||||
|
//
|
||||||
|
// FormCruiser
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(buttonStrategyStep);
|
||||||
|
Controls.Add(buttonCretaeCruiser);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(button1);
|
Controls.Add(button1);
|
||||||
Controls.Add(pictureBox1);
|
Controls.Add(pictureBoxCruiser);
|
||||||
Name = "Form1";
|
Name = "FormCruiser";
|
||||||
Text = "FormCruiser";
|
Text = "FormCruiser";
|
||||||
Click += ButtonMove_Click;
|
Click += ButtonMove_Click;
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBox1;
|
private PictureBox pictureBoxCruiser;
|
||||||
private Button button1;
|
private Button button1;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonCretaeCruiser;
|
||||||
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
namespace ProjectCruiser
|
using ProjectCruiser.Drawnings;
|
||||||
|
using ProjectCruiser.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectCruiser
|
||||||
{
|
{
|
||||||
public partial class FormCruiser : Form
|
public partial class FormCruiser : Form
|
||||||
{
|
{
|
||||||
@ -6,10 +9,16 @@
|
|||||||
/// Поле-объект для прорисовки объекта
|
/// Поле-объект для прорисовки объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningCruiser? _drawningCruiser;
|
private DrawningCruiser? _drawningCruiser;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
public FormCruiser()
|
public FormCruiser()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -21,35 +30,64 @@
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBox1.Width,
|
Bitmap bmp = new(pictureBoxCruiser.Width,
|
||||||
pictureBox1.Height);
|
pictureBoxCruiser.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningCruiser.DrawTransport(gr);
|
_drawningCruiser.DrawTransport(gr);
|
||||||
pictureBox1.Image = bmp;
|
pictureBoxCruiser.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработка нажатия кнопки "Создать"
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningCruiser):
|
||||||
|
_drawningCruiser = new DrawningCruiser(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(DrawningMilitaryCruiser):
|
||||||
|
_drawningCruiser = new DrawningMilitaryCruiser(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;
|
||||||
|
}
|
||||||
|
_drawningCruiser.SetPictureSize(pictureBoxCruiser.Width,
|
||||||
|
pictureBoxCruiser.Height);
|
||||||
|
_drawningCruiser.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 ButtonCreateCruiser_Click(object sender, EventArgs e)
|
private void ButtonCreateCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryCruiser));
|
||||||
{
|
|
||||||
Random random = new();
|
/// <summary>
|
||||||
_drawningCruiser = new DrawningCruiser();
|
/// Обработка нажатия кнопки "Создать крейсер"
|
||||||
_drawningCruiser.Init(random.Next(100, 300), random.Next(1000, 3000),
|
/// </summary>
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
/// <param name="sender"></param>
|
||||||
random.Next(0, 256)),
|
/// <param name="e"></param>
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
private void buttonCretaeCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCruiser));
|
||||||
random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
_drawningCruiser.SetPictureSize(pictureBox1.Width,
|
|
||||||
pictureBox1.Height);
|
|
||||||
|
|
||||||
//начальное положение круисера
|
|
||||||
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -87,5 +125,50 @@
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// обработка нажатия кнопки шаг
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningCruiser == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(new MoveableCruiser(_drawningCruiser), pictureBoxCruiser.Width, pictureBoxCruiser.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAABGsAAAZACAYAAADO3c9BAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAABGsAAAZACAYAAADO3c9BAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
wAAADsABataJCQAAVu1JREFUeF7s3XHE5XXe//HcstZKkiRJMpIkSZIkSZJkJUmSlSRZK1lJxkokK0mS
|
vAAADrwBlbxySQAAVu1JREFUeF7s3XHE5XXe//HcstZKkiRJMpIkSZIkSZJkJUmSlSRZK1lJxkokK0mS
|
||||||
JGtkJUmSJEkykiRJMpIkyRgjY4wxxhhjjN/v9dnd7rutz3xmrus61/uc8z2PJw+/2++/na7rnO/3dZ3z
|
JGtkJUmSJEkykiRJMpIkyRgjY4wxxhhjjN/v9dnd7rutz3xmrus61/uc8z2PJw+/2++/na7rnO/3dZ3z
|
||||||
+Z4iSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
+Z4iSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
||||||
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
||||||
@ -498,7 +498,7 @@
|
|||||||
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAABGsAAAZACAYAAADO3c9BAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAABGsAAAZACAYAAADO3c9BAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
wAAADsABataJCQAAVmJJREFUeF7s3XGk5nX+//98ZK2VJEkykpEkSZKsJEmyspIkyUqSrJWsJGMlkpUk
|
vAAADrwBlbxySQAAVmJJREFUeF7s3XGk5nX+//98ZK2VJEkykpEkSZKsJEmyspIkyUqSrJWsJGMlkpUk
|
||||||
SZKVrCRZSVYyVpIkSZKRJEnGGBljjDHGGGP8fo/37mc/36199WzOnHOe531d1+3Ozf69zTnX9X4/znW9
|
SZKVrCRZSVYyVpIkSZKRJEnGGBljjDHGGGP8fo/37mc/36199WzOnHOe531d1+3Ozf69zTnX9X4/znW9
|
||||||
3qdJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJ
|
3qdJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJ
|
||||||
kiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJ
|
kiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJ
|
||||||
@ -873,7 +873,7 @@
|
|||||||
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAABkAAAARrCAYAAADb+Gp7AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAABkAAAARrCAYAAADb+Gp7AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
wAAADsABataJCQAASClJREFUeF7s3Q+k3vX///F85SNJJjMzk0ySyXwkk8nMJEkyyWQySSaZZGYmGUmS
|
vAAADrwBlbxySQAASClJREFUeF7s3Q+k3vX///F85SNJJjMzk0ySyXwkk8nMJEkyyWQySSaZZGYmGUmS
|
||||||
ZJJJZpLMJJlkJjOZj5mZmZmZyczMzBwzxxzHMcfv93hXq7ad/+d9Xdf7/Xrf7tx8vt+vjy/V2RXn4Xq+
|
ZJJJZpLMJJlkJjOZj5mZmZmZyczMzBwzxxzHMcfv93hXq7ad/+d9Xdf7/Xrf7tx8vt+vjy/V2RXn4Xq+
|
||||||
7pMkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
7pMkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
||||||
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
||||||
@ -1187,7 +1187,7 @@
|
|||||||
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAABkAAAARrCAYAAADb+Gp7AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAABkAAAARrCAYAAADb+Gp7AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
wAAADsABataJCQAAUVNJREFUeF7s3X/E34X+//F85DiSTDKTSSbJJEcySZIkSZJkkiTJ5EiSZJJIkiRJ
|
vAAADrwBlbxySQAAUVNJREFUeF7s3X/E34X+//F85DiSTDKTSSbJJEcySZIkSZJkkiTJ5EiSZJJIkiRJ
|
||||||
JpkkSZJMMpNM5pjMzMzMTGZmZmZmZuZymcv3+3idTufU9tyuX+8frx+3OzfO+bPrer9fF8+Hvd9XSZIk
|
JpkkSZJMMpNM5pjMzMzMTGZmZmZmZuZymcv3+3idTufU9tyuX+8frx+3OzfO+bPrer9fF8+Hvd9XSZIk
|
||||||
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
||||||
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
||||||
|
123
ProjectCruiser/MovementStrategy/AbstractStrategy.cs
Normal file
123
ProjectCruiser/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
namespace ProjectCruiser.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
ProjectCruiser/MovementStrategy/IMoveableObject.cs
Normal file
24
ProjectCruiser/MovementStrategy/IMoveableObject.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
namespace ProjectCruiser.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
ProjectCruiser/MovementStrategy/MoveToBorder.cs
Normal file
53
ProjectCruiser/MovementStrategy/MoveToBorder.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
namespace ProjectCruiser.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения объекта к краю экрана
|
||||||
|
/// </summary>
|
||||||
|
internal class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
ObjectParameters? objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder - GetStep() <= FieldWidth
|
||||||
|
&& objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||||
|
objParams.DownBorder - GetStep() <= 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
ProjectCruiser/MovementStrategy/MoveToCenter.cs
Normal file
53
ProjectCruiser/MovementStrategy/MoveToCenter.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
namespace ProjectCruiser.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
62
ProjectCruiser/MovementStrategy/MoveableCruiser.cs
Normal file
62
ProjectCruiser/MovementStrategy/MoveableCruiser.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using ProjectCruiser.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectCruiser.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// класс реалтзация для IMoveableObject с использованием DrawningCruiser
|
||||||
|
/// </summary>
|
||||||
|
public class MoveableCruiser : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поле-объект класса DrawningCruiser или его наследника
|
||||||
|
/// </summary>
|
||||||
|
private readonly DrawningCruiser? _cruiser = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cruiser">Объект класса DrawningCruiser</param>
|
||||||
|
public MoveableCruiser(DrawningCruiser cruiser)
|
||||||
|
{
|
||||||
|
_cruiser = cruiser;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_cruiser == null || _cruiser.EntityCruiser == null ||
|
||||||
|
!_cruiser.GetPosX.HasValue || !_cruiser.GetPosY.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_cruiser.GetPosX.Value,
|
||||||
|
_cruiser.GetPosY.Value, _cruiser.GetWidth, _cruiser.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_cruiser?.EntityCruiser?.Step ?? 0);
|
||||||
|
public bool TryMoveObject(MovementDirection direction)
|
||||||
|
{
|
||||||
|
if (_cruiser == null || _cruiser.EntityCruiser == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return _cruiser.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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
26
ProjectCruiser/MovementStrategy/MovementDirection.cs
Normal file
26
ProjectCruiser/MovementStrategy/MovementDirection.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
namespace ProjectCruiser.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Направление перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum MovementDirection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
64
ProjectCruiser/MovementStrategy/ObjectParameters.cs
Normal file
64
ProjectCruiser/MovementStrategy/ObjectParameters.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
namespace ProjectCruiser.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
22
ProjectCruiser/MovementStrategy/StrategyStatus.cs
Normal file
22
ProjectCruiser/MovementStrategy/StrategyStatus.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
namespace ProjectCruiser.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Статус выполнения операции перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum StrategyStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Все готово к началу
|
||||||
|
/// </summary>
|
||||||
|
NotInit,
|
||||||
|
/// <summary>
|
||||||
|
/// Выполняется
|
||||||
|
/// </summary>
|
||||||
|
InProgress,
|
||||||
|
/// <summary>
|
||||||
|
/// Завершено
|
||||||
|
/// </summary>
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user