g
This commit is contained in:
parent
f6f10c7158
commit
97e3050cd2
@ -1,23 +0,0 @@
|
|||||||
namespace ProjectTank;
|
|
||||||
/// <summary>
|
|
||||||
/// Направление перемещения
|
|
||||||
/// </summary>
|
|
||||||
public enum DirectionType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Вверх
|
|
||||||
/// </summary>
|
|
||||||
Up = 1,
|
|
||||||
/// <summary>
|
|
||||||
/// Вниз
|
|
||||||
/// </summary>
|
|
||||||
Down = 2,
|
|
||||||
/// <summary>
|
|
||||||
/// Влево
|
|
||||||
/// </summary>
|
|
||||||
Left = 3,
|
|
||||||
/// <summary>
|
|
||||||
/// Вправо
|
|
||||||
/// </summary>
|
|
||||||
Right = 4
|
|
||||||
}
|
|
27
ProjectTank/ProjectTank/Drawnings/DirectionType.cs
Normal file
27
ProjectTank/ProjectTank/Drawnings/DirectionType.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
namespace ProjectTank.Drawnings;
|
||||||
|
/// <summary>
|
||||||
|
/// Направление перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum DirectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неизвестное направление
|
||||||
|
/// </summary>
|
||||||
|
Unknow = -1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
66
ProjectTank/ProjectTank/Drawnings/DrawningMilitaryTank.cs
Normal file
66
ProjectTank/ProjectTank/Drawnings/DrawningMilitaryTank.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using ProjectTank.Entities;
|
||||||
|
|
||||||
|
namespace ProjectTank.Drawnings
|
||||||
|
{
|
||||||
|
public class DrawningMilitaryTank : DrawningTank
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="helicopterArea">Признак наличия вертолетной площадки</param>
|
||||||
|
/// <param name="gun">Признак наличия шлюпок</param>
|
||||||
|
/// <param name="luke">Признак наличия пушки</param>
|
||||||
|
|
||||||
|
public DrawningMilitaryTank(int speed, double weight, Color bodyColor, Color additionalColor, bool helicopterArea, bool gun, bool luke)
|
||||||
|
: base(150, 50)
|
||||||
|
{
|
||||||
|
EntityTank = new EntityMilitaryTank(speed, weight, bodyColor, additionalColor, helicopterArea, gun, luke);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityTank == null || EntityTank is not EntityMilitaryTank entityMilitaryTank || !_startPosX.HasValue ||
|
||||||
|
!_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen2 = new(Color.Black, 2);
|
||||||
|
Brush Brush = new SolidBrush(Color.Black);
|
||||||
|
Brush Brush2 = new SolidBrush(entityMilitaryTank.AdditionalColor);
|
||||||
|
Brush additionalBrush = new SolidBrush(entityMilitaryTank.AdditionalColor);
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
g.FillRectangle(Brush2, _startPosX.Value + 7, _startPosY.Value + 15, 132, 10);
|
||||||
|
g.DrawRectangle(pen2, _startPosX.Value + 7, _startPosY.Value + 15, 132, 10);
|
||||||
|
|
||||||
|
if (entityMilitaryTank.Muzzle)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 5, 35, 3);
|
||||||
|
g.DrawRectangle(pen2, _startPosX.Value + 10, _startPosY.Value + 5, 35, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityMilitaryTank.Gun)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen2, _startPosX.Value + 100, _startPosY.Value + 15, _startPosX.Value + 110, _startPosY.Value + 10);
|
||||||
|
g.DrawLine(pen2, _startPosX.Value + 110, _startPosY.Value + 15, _startPosX.Value + 110, _startPosY.Value + 10);
|
||||||
|
g.DrawLine(pen2, _startPosX.Value + 120, _startPosY.Value + 15, _startPosX.Value + 110, _startPosY.Value + 10);
|
||||||
|
g.FillRectangle(Brush, _startPosX.Value + 100, _startPosY.Value + 3, 20, 7);
|
||||||
|
g.FillRectangle(Brush, _startPosX.Value + 120, _startPosY.Value + 5, 20, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityMilitaryTank.Luke)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen2, _startPosX.Value + 60, _startPosY.Value - 2, 25, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,6 @@
|
|||||||
using ProjectTank;
|
using ProjectTank.Entities;
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using System.Security.Cryptography.Xml;
|
|
||||||
|
|
||||||
namespace ProjectTank;
|
namespace ProjectTank.Drawnings;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -11,7 +9,7 @@ public class DrawningTank
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityTank? EntityTank { get; private set; }
|
public EntityTank? EntityTank { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -23,11 +21,11 @@ public class DrawningTank
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки автомобиля
|
/// Левая координата прорисовки автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosX;
|
protected int? _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки автомобиля
|
/// Верхняя кооридната прорисовки автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
protected int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки танка
|
/// Ширина прорисовки танка
|
||||||
@ -38,28 +36,56 @@ public class DrawningTank
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningTankHeight = 50;
|
private readonly int _drawningTankHeight = 50;
|
||||||
private readonly int _drawningEnginesWidth = 3;
|
private readonly int _drawningEnginesWidth = 3;
|
||||||
/// <summary>
|
|
||||||
/// Инициализация свойств
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="motor">Признак наличия вертолетной площадки</param>
|
|
||||||
/// <param name="boat">Признак наличия шлюпок</param>
|
|
||||||
/// <param name="glass">Признак наличия пушки</param>
|
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
/// <summary>
|
||||||
additionalColor, bool motor, bool boat, bool glass)
|
/// Координата X объекта
|
||||||
|
/// </summary>
|
||||||
|
public int? GetPosX => _startPosX;
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Y объекта
|
||||||
|
/// </summary>
|
||||||
|
public int? GetPosY => _startPosY;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetWidth => _drawningTankWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => _drawningTankHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Пустой онструктор
|
||||||
|
/// </summary>
|
||||||
|
private DrawningTank()
|
||||||
{
|
{
|
||||||
EntityTank = new EntityTank();
|
|
||||||
EntityTank.Init(speed, weight, bodyColor, additionalColor,
|
|
||||||
motor, boat, glass);
|
|
||||||
_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 DrawningTank(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityTank = new EntityTank(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор для наследников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningCarWidth">Ширина прорисовки автомобиля</param>
|
||||||
|
/// <param name="drawningCarHeight">Высота прорисовки автомобиля</param>
|
||||||
|
protected DrawningTank(int drawningCarWidth, int drawningCarHeight) : this()
|
||||||
|
{
|
||||||
|
_drawningTankWidth = drawningCarWidth;
|
||||||
|
_pictureHeight = drawningCarHeight;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -161,26 +187,23 @@ public class DrawningTank
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityTank == null || !_startPosX.HasValue ||
|
if (EntityTank == null || !_startPosX.HasValue ||
|
||||||
!_startPosY.HasValue)
|
!_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(EntityTank.BodyColor, 2);
|
|
||||||
Pen pen2 = new(Color.Black, 2);
|
Pen pen2 = new(Color.Black, 2);
|
||||||
Pen pen3 = new(Color.Black, 3);
|
Pen pen3 = new(Color.Black, 3);
|
||||||
Brush Brush = new SolidBrush(Color.Black);
|
Brush Brush = new SolidBrush(EntityTank.BodyColor);
|
||||||
Brush Brush2 = new SolidBrush(EntityTank.AdditionalColor);
|
|
||||||
Brush additionalBrush = new SolidBrush(EntityTank.AdditionalColor);
|
|
||||||
|
|
||||||
//границы танка
|
//границы танка
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value, 50, 15);
|
g.FillRectangle(Brush, _startPosX.Value + 45, _startPosY.Value, 50, 15);
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 45, _startPosY.Value, 50, 15);
|
g.DrawRectangle(pen2, _startPosX.Value + 45, _startPosY.Value, 50, 15);
|
||||||
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 7, _startPosY.Value + 15, 132, 10);
|
g.FillRectangle(Brush, _startPosX.Value + 7, _startPosY.Value + 15, 132, 10);
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 7, _startPosY.Value + 15, 132, 10);
|
g.DrawRectangle(pen2, _startPosX.Value + 7, _startPosY.Value + 15, 132, 10);
|
||||||
|
|
||||||
g.DrawArc(pen2, _startPosX.Value, _startPosY.Value + 22, 25, 25, 70, 200);
|
g.DrawArc(pen2, _startPosX.Value, _startPosY.Value + 22, 25, 25, 70, 200);
|
||||||
g.DrawArc(pen2, _startPosX.Value + 122, _startPosY.Value + 22, 25, 25, 260, 200);
|
g.DrawArc(pen2, _startPosX.Value + 122, _startPosY.Value + 22, 25, 25, 260, 200);
|
||||||
@ -196,26 +219,5 @@ public class DrawningTank
|
|||||||
g.DrawArc(pen2, _startPosX.Value + 70, _startPosY.Value + 18, 10, 10, 0, 170);
|
g.DrawArc(pen2, _startPosX.Value + 70, _startPosY.Value + 18, 10, 10, 0, 170);
|
||||||
g.DrawArc(pen2, _startPosX.Value + 93, _startPosY.Value + 18, 10, 10, 0, 170);
|
g.DrawArc(pen2, _startPosX.Value + 93, _startPosY.Value + 18, 10, 10, 0, 170);
|
||||||
|
|
||||||
//внутренности танка
|
|
||||||
|
|
||||||
if (EntityTank.Muzzle)
|
|
||||||
{
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 5, 35, 3);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 5, 35, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EntityTank.Gun)
|
|
||||||
{
|
|
||||||
g.DrawLine(pen2, _startPosX.Value + 100, _startPosY.Value + 15, _startPosX.Value + 110, _startPosY.Value + 10);
|
|
||||||
g.DrawLine(pen2, _startPosX.Value + 110, _startPosY.Value + 15, _startPosX.Value + 110, _startPosY.Value + 10);
|
|
||||||
g.DrawLine(pen2, _startPosX.Value + 120, _startPosY.Value + 15, _startPosX.Value + 110, _startPosY.Value + 10);
|
|
||||||
g.FillRectangle(Brush, _startPosX.Value + 100, _startPosY.Value + 3, 20, 7);
|
|
||||||
g.FillRectangle(Brush, _startPosX.Value + 120, _startPosY.Value + 5, 20, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EntityTank.Luke)
|
|
||||||
{
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value - 2, 25, 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
30
ProjectTank/ProjectTank/Entities/EntityMilitaryTank.cs
Normal file
30
ProjectTank/ProjectTank/Entities/EntityMilitaryTank.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
namespace ProjectTank.Entities
|
||||||
|
{
|
||||||
|
internal class EntityMilitaryTank : EntityTank
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличие пушка
|
||||||
|
/// </summary>
|
||||||
|
public bool Muzzle { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличие артелирийской пушки
|
||||||
|
/// </summary>
|
||||||
|
public bool Gun { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличие люка
|
||||||
|
/// </summary>
|
||||||
|
public bool Luke { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
|
/// </summary>
|
||||||
|
public Color AdditionalColor { get; private set; }
|
||||||
|
|
||||||
|
public EntityMilitaryTank(int speed, double weight, Color bodyColor, Color additionalColor, bool мuzzle, bool gun, bool luke) : base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Muzzle = мuzzle;
|
||||||
|
Gun = gun;
|
||||||
|
Luke = luke;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
ProjectTank/ProjectTank/Entities/EntityTank.cs
Normal file
38
ProjectTank/ProjectTank/Entities/EntityTank.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
namespace ProjectTank.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "танк"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityTank
|
||||||
|
{
|
||||||
|
//свойства
|
||||||
|
/// <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 EntityTank(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
@ -1,62 +0,0 @@
|
|||||||
namespace ProjectTank;
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-сущность "автобус"
|
|
||||||
/// </summary>
|
|
||||||
public class EntityTank
|
|
||||||
{
|
|
||||||
//свойства
|
|
||||||
/// <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 Muzzle { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак (опция) наличие лестницы
|
|
||||||
/// </summary>
|
|
||||||
public bool Gun { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак (опция) наличие фар
|
|
||||||
/// </summary>
|
|
||||||
public bool Luke { 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="motor">второй этаж</param>
|
|
||||||
/// <param name="oars">лестница</param>
|
|
||||||
/// <param name="glass">наличие фар</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, bool motor, bool oars, bool glass)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
Muzzle = motor;
|
|
||||||
Gun = oars;
|
|
||||||
Luke = glass;
|
|
||||||
}
|
|
||||||
}
|
|
80
ProjectTank/ProjectTank/FormTank.Designer.cs
generated
80
ProjectTank/ProjectTank/FormTank.Designer.cs
generated
@ -1,5 +1,4 @@
|
|||||||
|
namespace ProjectTank
|
||||||
namespace ProjectTank
|
|
||||||
{
|
{
|
||||||
partial class FormTank
|
partial class FormTank
|
||||||
{
|
{
|
||||||
@ -30,25 +29,28 @@ namespace ProjectTank
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormTank));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormTank));
|
||||||
pictureBox1 = new PictureBox();
|
pictureBoxTank = 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();
|
||||||
|
buttonCretaeTank = new Button();
|
||||||
|
buttonStrategyStep = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBox1
|
// pictureBoxTank
|
||||||
//
|
//
|
||||||
pictureBox1.Dock = DockStyle.Fill;
|
pictureBoxTank.Dock = DockStyle.Fill;
|
||||||
pictureBox1.Location = new Point(0, 0);
|
pictureBoxTank.Location = new Point(0, 0);
|
||||||
pictureBox1.Margin = new Padding(3, 2, 3, 2);
|
pictureBoxTank.Margin = new Padding(3, 2, 3, 2);
|
||||||
pictureBox1.Name = "pictureBox1";
|
pictureBoxTank.Name = "pictureBoxTank";
|
||||||
pictureBox1.Size = new Size(700, 338);
|
pictureBoxTank.Size = new Size(700, 338);
|
||||||
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
|
pictureBoxTank.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBox1.TabIndex = 0;
|
pictureBoxTank.TabIndex = 0;
|
||||||
pictureBox1.TabStop = false;
|
pictureBoxTank.TabStop = false;
|
||||||
//
|
//
|
||||||
// button1
|
// button1
|
||||||
//
|
//
|
||||||
@ -56,9 +58,9 @@ namespace ProjectTank
|
|||||||
button1.Location = new Point(10, 307);
|
button1.Location = new Point(10, 307);
|
||||||
button1.Margin = new Padding(3, 2, 3, 2);
|
button1.Margin = new Padding(3, 2, 3, 2);
|
||||||
button1.Name = "button1";
|
button1.Name = "button1";
|
||||||
button1.Size = new Size(82, 22);
|
button1.Size = new Size(186, 22);
|
||||||
button1.TabIndex = 1;
|
button1.TabIndex = 1;
|
||||||
button1.Text = "создать";
|
button1.Text = "создать военный танк";
|
||||||
button1.UseVisualStyleBackColor = true;
|
button1.UseVisualStyleBackColor = true;
|
||||||
button1.Click += ButtonCreateTank_Click;
|
button1.Click += ButtonCreateTank_Click;
|
||||||
//
|
//
|
||||||
@ -114,34 +116,74 @@ namespace ProjectTank
|
|||||||
buttonLeft.UseVisualStyleBackColor = true;
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
buttonLeft.Click += ButtonMove_Click;
|
buttonLeft.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к краю" });
|
||||||
|
comboBoxStrategy.Location = new Point(557, 9);
|
||||||
|
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(133, 23);
|
||||||
|
comboBoxStrategy.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// buttonCretaeTank
|
||||||
|
//
|
||||||
|
buttonCretaeTank.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCretaeTank.Location = new Point(210, 308);
|
||||||
|
buttonCretaeTank.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonCretaeTank.Name = "buttonCretaeTank";
|
||||||
|
buttonCretaeTank.Size = new Size(186, 22);
|
||||||
|
buttonCretaeTank.TabIndex = 7;
|
||||||
|
buttonCretaeTank.Text = "создать танк";
|
||||||
|
buttonCretaeTank.UseVisualStyleBackColor = true;
|
||||||
|
buttonCretaeTank.Click += buttonCretaeTank_Click;
|
||||||
|
//
|
||||||
|
// buttonStrategyStep
|
||||||
|
//
|
||||||
|
buttonStrategyStep.Location = new Point(607, 34);
|
||||||
|
buttonStrategyStep.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||||
|
buttonStrategyStep.Size = new Size(82, 22);
|
||||||
|
buttonStrategyStep.TabIndex = 8;
|
||||||
|
buttonStrategyStep.Text = "шаг";
|
||||||
|
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||||
|
//
|
||||||
// FormTank
|
// FormTank
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(700, 338);
|
ClientSize = new Size(700, 338);
|
||||||
|
Controls.Add(buttonStrategyStep);
|
||||||
|
Controls.Add(buttonCretaeTank);
|
||||||
|
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(pictureBoxTank);
|
||||||
Margin = new Padding(3, 2, 3, 2);
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
Name = "FormTank";
|
Name = "FormTank";
|
||||||
Text = "FormTank";
|
Text = "FormTank";
|
||||||
//Load += this.FormTank_Load_1;
|
|
||||||
Click += ButtonMove_Click;
|
Click += ButtonMove_Click;
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBox1;
|
private PictureBox pictureBoxTank;
|
||||||
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 buttonCretaeTank;
|
||||||
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
namespace ProjectTank
|
using ProjectTank.Drawnings;
|
||||||
|
using ProjectTank.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectTank
|
||||||
{
|
{
|
||||||
public partial class FormTank : Form
|
public partial class FormTank : Form
|
||||||
{
|
{
|
||||||
@ -6,10 +9,16 @@
|
|||||||
/// Поле-объект для прорисовки объекта
|
/// Поле-объект для прорисовки объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningTank? _drawningTank;
|
private DrawningTank? _drawningTank;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
public FormTank()
|
public FormTank()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -21,35 +30,64 @@
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBox1.Width,
|
Bitmap bmp = new(pictureBoxTank.Width,
|
||||||
pictureBox1.Height);
|
pictureBoxTank.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningTank.DrawTransport(gr);
|
_drawningTank.DrawTransport(gr);
|
||||||
pictureBox1.Image = bmp;
|
pictureBoxTank.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработка нажатия кнопки "Создать"
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningTank):
|
||||||
|
_drawningTank = new DrawningTank(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(DrawningMilitaryTank):
|
||||||
|
_drawningTank = new DrawningMilitaryTank(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;
|
||||||
|
}
|
||||||
|
_drawningTank.SetPictureSize(pictureBoxTank.Width,
|
||||||
|
pictureBoxTank.Height);
|
||||||
|
_drawningTank.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 ButtonCreateTank_Click(object sender, EventArgs e)
|
private void ButtonCreateTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryTank));
|
||||||
{
|
|
||||||
Random random = new();
|
/// <summary>
|
||||||
_drawningTank = new DrawningTank();
|
/// Обработка нажатия кнопки "Создать танк"
|
||||||
_drawningTank.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 buttonCretaeTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTank));
|
||||||
random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
_drawningTank.SetPictureSize(pictureBox1.Width,
|
|
||||||
pictureBox1.Height);
|
|
||||||
|
|
||||||
//начальное положение круисера
|
|
||||||
_drawningTank.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 (_drawningTank == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(new MoveableTank(_drawningTank), pictureBoxTank.Width, pictureBoxTank.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
|
||||||
vQAADr0BR/uQrQAAVu1JREFUeF7s3XHE5XXe//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
|
||||||
vQAADr0BR/uQrQAAVmJJREFUeF7s3XGk5nX+//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
|
||||||
vQAADr0BR/uQrQAASClJREFUeF7s3Q+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
|
||||||
vQAADr0BR/uQrQAAUVNJREFUeF7s3X/E34X+//F85DiSTDKTSSbJJEcySZIkSZJkkiTJ5EiSZJJIkiRJ
|
vAAADrwBlbxySQAAUVNJREFUeF7s3X/E34X+//F85DiSTDKTSSbJJEcySZIkSZJkkiTJ5EiSZJJIkiRJ
|
||||||
JpkkSZJMMpNM5pjMzMzMTGZmZmZmZuZymcv3+3idTufU9tyuX+8frx+3OzfO+bPrer9fF8+Hvd9XSZIk
|
JpkkSZJMMpNM5pjMzMzMTGZmZmZmZuZymcv3+3idTufU9tyuX+8frx+3OzfO+bPrer9fF8+Hvd9XSZIk
|
||||||
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
||||||
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk
|
||||||
|
123
ProjectTank/ProjectTank/MovementStrategy/AbstractStrategy.cs
Normal file
123
ProjectTank/ProjectTank/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
namespace ProjectTank.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
ProjectTank/ProjectTank/MovementStrategy/IMoveableObject.cs
Normal file
24
ProjectTank/ProjectTank/MovementStrategy/IMoveableObject.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
namespace ProjectTank.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
ProjectTank/ProjectTank/MovementStrategy/MoveToBorder.cs
Normal file
53
ProjectTank/ProjectTank/MovementStrategy/MoveToBorder.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
namespace ProjectTank.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
ProjectTank/ProjectTank/MovementStrategy/MoveToCenter.cs
Normal file
53
ProjectTank/ProjectTank/MovementStrategy/MoveToCenter.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
namespace ProjectTank.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
ProjectTank/ProjectTank/MovementStrategy/MoveableTank.cs
Normal file
62
ProjectTank/ProjectTank/MovementStrategy/MoveableTank.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using ProjectTank.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectTank.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// класс реалтзация для IMoveableObject с использованием DrawningTank
|
||||||
|
/// </summary>
|
||||||
|
public class MoveableTank : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поле-объект класса DrawningTank или его наследника
|
||||||
|
/// </summary>
|
||||||
|
private readonly DrawningTank? _cruiser = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cruiser">Объект класса DrawningTank</param>
|
||||||
|
public MoveableTank(DrawningTank cruiser)
|
||||||
|
{
|
||||||
|
_cruiser = cruiser;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_cruiser == null || _cruiser.EntityTank == 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?.EntityTank?.Step ?? 0);
|
||||||
|
public bool TryMoveObject(MovementDirection direction)
|
||||||
|
{
|
||||||
|
if (_cruiser == null || _cruiser.EntityTank == 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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
|||||||
|
namespace ProjectTank.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Направление перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum MovementDirection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
64
ProjectTank/ProjectTank/MovementStrategy/ObjectParameters.cs
Normal file
64
ProjectTank/ProjectTank/MovementStrategy/ObjectParameters.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
namespace ProjectTank.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
ProjectTank/ProjectTank/MovementStrategy/StrategyStatus.cs
Normal file
22
ProjectTank/ProjectTank/MovementStrategy/StrategyStatus.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
namespace ProjectTank.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Статус выполнения операции перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum StrategyStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Все готово к началу
|
||||||
|
/// </summary>
|
||||||
|
NotInit,
|
||||||
|
/// <summary>
|
||||||
|
/// Выполняется
|
||||||
|
/// </summary>
|
||||||
|
InProgress,
|
||||||
|
/// <summary>
|
||||||
|
/// Завершено
|
||||||
|
/// </summary>
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user