This commit is contained in:
marusya 2023-11-05 21:14:17 +04:00
parent 1028b61ec9
commit d82b23e1f4
15 changed files with 1054 additions and 378 deletions

View File

@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SelfPropelledArtilleryUnit.Drawnings;
namespace SelfPropelledArtilleryUnit.MovementStrategy
{
/// <summary>
/// Класс-стратегия перемещения объекта
/// </summary>
public abstract class AbstractStrategy
{
/// <summary>
/// Перемещаемый объект
/// </summary>
private IMoveableObject? _moveableObject;
/// <summary>
/// Статус перемещения
/// </summary>
private Status _state = Status.NotInit;
/// <summary>
/// Ширина поля
/// </summary>
protected int FieldWidth { get; private set; }
/// <summary>
/// Высота поля
/// </summary>
protected int FieldHeight { get; private set; }
/// <summary>
/// Статус перемещения
/// </summary>
public Status 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 = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
/// <summary>
/// Шаг перемещения
/// </summary>
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
/// <summary>
/// Перемещение влево
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveLeft() => MoveTo(DirectionType.Left);
/// <summary>
/// Перемещение вправо
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveRight() => MoveTo(DirectionType.Right);
/// <summary>
/// Перемещение вверх
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveUp() => MoveTo(DirectionType.Up);
/// <summary>
/// Перемещение вниз
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveDown() => MoveTo(DirectionType.Down);
/// <summary>
/// Параметры объекта
/// </summary>
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
/// <summary>
/// Шаг объекта
/// </summary>
/// <returns></returns>
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
/// <summary>
/// Перемещение к цели
/// </summary>
protected abstract void MoveToTarget();
/// <summary>
/// Достигнута ли цель
/// </summary>
/// <returns></returns>
protected abstract bool IsTargetDestinaion();
/// <summary>
/// Попытка перемещения в требуемом направлении
/// </summary>
/// <param name="directionType">Направление</param>
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@ -4,8 +4,11 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit namespace SelfPropelledArtilleryUnit.Drawnings
{ {
/// <summary>
/// Направление перемещения
/// </summary>
public enum DirectionType public enum DirectionType
{ {
@ -17,5 +20,4 @@ namespace SelfPropelledArtilleryUnit
Right = 4 Right = 4
} }
} }

View File

@ -1,126 +1,195 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit using SelfPropelledArtilleryUnit.Entities;
using SelfPropelledArtilleryUnit.Drawnings;
using System.Drawing.Drawing2D;
namespace SelfPropelledArtilleryUnit.DrawningObjects
{ {
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningUsta public class DrawningUsta
{ {
private int lineWidth; /// <summary>
/// Класс-сущность /// Класс-сущность
public EntityUsta? EntityUsta { get; private set; } /// </summary>
public EntityUsta? EntityUsta { get; protected set; }
/// <summary>
/// Ширина окна /// Ширина окна
/// </summary>
private int _pictureWidth; private int _pictureWidth;
/// <summary>
/// Высота окна /// Высота окна
/// </summary>
private int _pictureHeight; private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки установки /// Левая координата прорисовки установки
private int _startPosX; /// </summary>
protected int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки установки /// Верхняя кооридната прорисовки установки
private int _startPosY; /// </summary>
protected int _startPosY;
/// <summary>
/// Ширина прорисовки установки /// Ширина прорисовки установки
private readonly int _ustaWidth = 140; /// </summary>
protected readonly int _ustaWidth = 140;
/// <summary>
/// Высота прорисовки установки /// Высота прорисовки установки
private readonly int _ustaHeight = 90; /// </summary>
/// Инициализация свойств protected readonly int _ustaHeight = 90;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param> /// <param name="weight">Вес</param>
/// <param name="bodyColor">Общий цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия батареи</param>
/// <param name="pushka">Признак наличия пушки</param>
/// <param name="width">Ширина картинки</param> /// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param> /// <param name="height">Высота картинки</param>
/// <returns>true - объект создан, false - проверка не пройдена, public DrawningUsta(int speed, double weight, Color bodyColor, int
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool pushka, int width, int height){ width, int height)
if (width < _pictureWidth || height < _pictureHeight)
{ {
return false; // TODO: Продумать проверки
}
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
EntityUsta = new EntityUsta(); EntityUsta = new EntityUsta(speed, weight, bodyColor);
EntityUsta.Init(speed, weight, bodyColor, additionalColor,
bodyKit, pushka);
return true;
} }
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <param name="ustaWidth">Ширина прорисовки установки</param>
/// <param name="ustaHeight">Высота прорисовки установки</param>
protected DrawningUsta(int speed, double weight, Color bodyColor, int
width, int height, int ustaWidth, int ustaHeight)
{
// TODO: Продумать проверки
if (width <= _pictureWidth || height <= _pictureHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_ustaWidth = ustaWidth;
_ustaHeight = ustaHeight;
EntityUsta = new EntityUsta(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции /// Установка позиции
/// </summary>
/// <param name="x">Координата X</param> /// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param> /// <param name="y">Координата Y</param>
public void SetPosition(int x, int y) public void SetPosition(int x, int y)
{ {
// TODO: Изменение x, y // TODO: Изменение x, y, если при установке объект выходит за границы
if (x <= _pictureWidth - _ustaWidth && y <= _pictureHeight - _ustaHeight) if (x < 0 || y < 0 || x + _ustaWidth > _pictureWidth || y + _ustaHeight > _pictureHeight)
{ {
x = 10;
y = 10;
}
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
} }
protected int PictureWidth
{
get { return _pictureWidth; }
} }
protected int PictureHeight
{
get { return _pictureHeight; }
}
/// <summary>
/// Изменение направления перемещения /// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param> /// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _ustaWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _ustaHeight;
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
public virtual bool CanMove(DirectionType direction)
{ {
if (EntityUsta == null) if (EntityUsta == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityUsta.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityUsta.Step > 7,
// вправо
DirectionType.Right => _startPosX + EntityUsta.Step + _ustaWidth < _pictureWidth,// TODO: Продумать логику
//вниз
DirectionType.Down => _startPosY + EntityUsta.Step + _ustaHeight < _pictureHeight,// TODO: Продумать логику
_ => false,
};
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public virtual void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityUsta == null)
{ {
return; return;
} }
switch (direction) switch (direction)
{ {
//влево
case DirectionType.Left: case DirectionType.Left:
if (_startPosX - EntityUsta.Step > 0)
{
_startPosX -= (int)EntityUsta.Step; _startPosX -= (int)EntityUsta.Step;
}
if (_startPosX - EntityUsta.Step < 0)
{
_startPosX -= _startPosX;
}
break; break;
//вверх
case DirectionType.Up: case DirectionType.Up:
if (_startPosY - EntityUsta.Step > 5)
{
_startPosY -= (int)EntityUsta.Step; _startPosY -= (int)EntityUsta.Step;
}
else if (_startPosY + 7 - EntityUsta.Step < 0)
{
_startPosY = _startPosY - _startPosY + 10;
}
break; break;
// вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX + EntityUsta.Step + _ustaWidth < _pictureWidth)
{
_startPosX += (int)EntityUsta.Step; _startPosX += (int)EntityUsta.Step;
break;
case DirectionType.Down:
_startPosY += (int)EntityUsta.Step;
break;
} }
else if (_startPosX + EntityUsta.Step + _ustaWidth > _pictureWidth)
{
_startPosX += _pictureWidth - _startPosX - _ustaWidth;
} }
break; public virtual void DrawTransport(Graphics g)
//вниз
case DirectionType.Down:
if (_startPosY + EntityUsta.Step + _ustaHeight < _pictureHeight)
{
_startPosY += (int)EntityUsta.Step;
}
else if (_startPosY + EntityUsta.Step + _ustaHeight > _pictureHeight)
{
_startPosY += _pictureHeight - _startPosY - _ustaHeight;
}
break;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{ {
if (EntityUsta == null) if (EntityUsta == null)
{ {
@ -128,11 +197,11 @@ namespace SelfPropelledArtilleryUnit
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityUsta.AdditionalColor);
Brush BodyColor = new SolidBrush(EntityUsta.BodyColor); Brush BodyColor = new SolidBrush(EntityUsta.BodyColor);
//зеленый темнее //зеленый темнее
lineWidth = 10; int lineWidth = 10;
Color color1 = Color.FromArgb(65, 72, 51); Color color1 = Color.FromArgb(65, 72, 51);
Brush pen1 = new SolidBrush(color1); Brush pen1 = new SolidBrush(color1);
@ -182,126 +251,7 @@ namespace SelfPropelledArtilleryUnit
g.FillEllipse(pen3, _startPosX + 10, _startPosY + 52, 26, 26); g.FillEllipse(pen3, _startPosX + 10, _startPosY + 52, 26, 26);
g.FillEllipse(pen3, _startPosX + 105, _startPosY + 52, 26, 26); g.FillEllipse(pen3, _startPosX + 105, _startPosY + 52, 26, 26);
// батарея
if (EntityUsta.BodyKit)
{
GraphicsPath path1 = new GraphicsPath();
path1.AddLine(_startPosX + 15, _startPosY + 40, _startPosX + 15, _startPosY + 30);
path1.AddLine(_startPosX + 15, _startPosY + 30, _startPosX + 15, _startPosY + 35);
path1.AddLine(_startPosX + 15, _startPosY + 35, _startPosX + 25, _startPosY + 35);
path1.AddLine(_startPosX + 25, _startPosY + 35, _startPosX + 30, _startPosY + 30);
path1.AddLine(_startPosX + 30, _startPosY + 30, _startPosX + 35, _startPosY + 40);
path1.CloseFigure();
g.DrawPath(pen, path1);
g.FillPath(BodyColor, path1);
GraphicsPath path2 = new GraphicsPath();
path2.AddLine(_startPosX + 15, _startPosY + 30, _startPosX + 40, _startPosY + 20);
path2.AddLine(_startPosX + 40, _startPosY + 20, _startPosX + 40, _startPosY + 25);
path2.AddLine(_startPosX + 40, _startPosY + 25, _startPosX + 25, _startPosY + 35);
path2.AddLine(_startPosX + 25, _startPosY + 35, _startPosX + 15, _startPosY + 35);
path2.CloseFigure();
g.DrawPath(pen, path2);
g.FillPath(additionalBrush, path2);
GraphicsPath path3 = new GraphicsPath();
path3.AddLine(_startPosX + 10, _startPosY + 32, _startPosX, _startPosY + 10);
path3.AddLine(_startPosX, _startPosY + 10, _startPosX + 40, _startPosY - 7);
path3.AddLine(_startPosX + 40, _startPosY - 7, _startPosX + 50, _startPosY + 16);
path3.CloseFigure();
g.DrawPath(pen, path3);
g.FillPath(pen3, path3);
GraphicsPath path4 = new GraphicsPath();
path4.AddLine(_startPosX, _startPosY + 10, _startPosX + 40, _startPosY - 7);
path4.AddLine(_startPosX + 40, _startPosY - 7, _startPosX + 43, _startPosY - 5);
path4.AddLine(_startPosX + 43, _startPosY - 5, _startPosX + 41, _startPosY - 3);
path4.AddLine(_startPosX + 41, _startPosY - 3, _startPosX + 2, _startPosY + 13);
path4.CloseFigure();
g.DrawPath(pen, path4);
g.FillPath(additionalBrush, path4);
GraphicsPath path5 = new GraphicsPath();
path5.AddLine(_startPosX + 3, _startPosY + 15, _startPosX + 45, _startPosY - 2);
path5.AddLine(_startPosX + 46, _startPosY - 2, _startPosX + 49, _startPosY - 1);
path5.AddLine(_startPosX + 49, _startPosY - 1, _startPosX + 46, _startPosY + 3);
path5.AddLine(_startPosX + 46, _startPosY + 3, _startPosX + 6, _startPosY + 20);
path5.CloseFigure();
g.DrawPath(pen, path5);
g.FillPath(BodyColor, path5);
GraphicsPath path6 = new GraphicsPath();
path6.AddLine(_startPosX + 5, _startPosY + 22, _startPosX + 47, _startPosY + 5);
path6.AddLine(_startPosX + 47, _startPosY + 5, _startPosX + 51, _startPosY + 5);
path6.AddLine(_startPosX + 51, _startPosY + 5, _startPosX + 53, _startPosY + 7);
path6.AddLine(_startPosX + 53, _startPosY + 7, _startPosX + 8, _startPosY + 25);
path6.CloseFigure();
g.DrawPath(pen, path6);
g.FillPath(additionalBrush, path6);
GraphicsPath path7 = new GraphicsPath();
path7.AddLine(_startPosX + 7, _startPosY + 27, _startPosX + 46, _startPosY + 11);
path7.AddLine(_startPosX + 46, _startPosY + 11, _startPosX + 51, _startPosY + 9);
path7.AddLine(_startPosX + 51, _startPosY + 9, _startPosX + 56, _startPosY + 11);
path7.AddLine(_startPosX + 56, _startPosY + 11, _startPosX + 10, _startPosY + 31);
path7.CloseFigure();
g.DrawPath(pen, path7);
g.FillPath(BodyColor, path7);
}
// пушка
if (EntityUsta.Pushka)
{
g.FillRectangle(pen2, _startPosX + 80, _startPosY + 25, 10, 10);
g.DrawRectangle(pen, _startPosX + 80, _startPosY + 25, 10, 10);
g.FillRectangle(additionalBrush, _startPosX + 90, _startPosY + 28, 40, 5);
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 28, 40, 5);
g.FillRectangle(additionalBrush, _startPosX + 130, _startPosY + 27, 5, 7);
g.DrawRectangle(pen, _startPosX + 130, _startPosY + 27, 5, 7);
}
} }
} }
} }

View File

@ -0,0 +1,176 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SelfPropelledArtilleryUnit.Drawnings;
using SelfPropelledArtilleryUnit.Entities;
namespace SelfPropelledArtilleryUnit.DrawningObjects
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningUstaBat : DrawningUsta
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия батареи</param>
/// <param name="pushka">Признак наличия пушки</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningUstaBat(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool pushka, int width, int height) :
base(speed, weight, bodyColor, width, height, 140, 90)
{
if (EntityUsta != null)
{
EntityUsta = new EntityUstaBat(speed, weight, bodyColor,
additionalColor, bodyKit, pushka);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityUsta is not EntityUstaBat ustaBat)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(ustaBat.AdditionalColor);
Brush BodyColor = new SolidBrush(EntityUsta.BodyColor);
//зеленый темнее
Color color1 = Color.FromArgb(65, 72, 51);
Brush pen1 = new SolidBrush(color1);
//black
Color color3 = Color.FromArgb(0, 0, 0);
Brush pen3 = new SolidBrush(color3);
//зеленый мох
Color color2 = Color.FromArgb(47, 69, 56);
Brush pen2 = new SolidBrush(color1);
// батарея
if (ustaBat.BodyKit)
{
GraphicsPath path1 = new GraphicsPath();
path1.AddLine(_startPosX + 15, _startPosY + 40, _startPosX + 15, _startPosY + 30);
path1.AddLine(_startPosX + 15, _startPosY + 30, _startPosX + 15, _startPosY + 35);
path1.AddLine(_startPosX + 15, _startPosY + 35, _startPosX + 25, _startPosY + 35);
path1.AddLine(_startPosX + 25, _startPosY + 35, _startPosX + 30, _startPosY + 30);
path1.AddLine(_startPosX + 30, _startPosY + 30, _startPosX + 35, _startPosY + 40);
path1.CloseFigure();
g.DrawPath(pen, path1);
g.FillPath(BodyColor, path1);
GraphicsPath path2 = new GraphicsPath();
path2.AddLine(_startPosX + 15, _startPosY + 30, _startPosX + 40, _startPosY + 20);
path2.AddLine(_startPosX + 40, _startPosY + 20, _startPosX + 40, _startPosY + 25);
path2.AddLine(_startPosX + 40, _startPosY + 25, _startPosX + 25, _startPosY + 35);
path2.AddLine(_startPosX + 25, _startPosY + 35, _startPosX + 15, _startPosY + 35);
path2.CloseFigure();
g.DrawPath(pen, path2);
g.FillPath(additionalBrush, path2);
GraphicsPath path3 = new GraphicsPath();
path3.AddLine(_startPosX + 10, _startPosY + 32, _startPosX, _startPosY + 10);
path3.AddLine(_startPosX, _startPosY + 10, _startPosX + 40, _startPosY - 7);
path3.AddLine(_startPosX + 40, _startPosY - 7, _startPosX + 50, _startPosY + 16);
path3.CloseFigure();
g.DrawPath(pen, path3);
g.FillPath(pen3, path3);
GraphicsPath path4 = new GraphicsPath();
path4.AddLine(_startPosX, _startPosY + 10, _startPosX + 40, _startPosY - 7);
path4.AddLine(_startPosX + 40, _startPosY - 7, _startPosX + 43, _startPosY - 5);
path4.AddLine(_startPosX + 43, _startPosY - 5, _startPosX + 41, _startPosY - 3);
path4.AddLine(_startPosX + 41, _startPosY - 3, _startPosX + 2, _startPosY + 13);
path4.CloseFigure();
g.DrawPath(pen, path4);
g.FillPath(additionalBrush, path4);
GraphicsPath path5 = new GraphicsPath();
path5.AddLine(_startPosX + 3, _startPosY + 15, _startPosX + 45, _startPosY - 2);
path5.AddLine(_startPosX + 46, _startPosY - 2, _startPosX + 49, _startPosY - 1);
path5.AddLine(_startPosX + 49, _startPosY - 1, _startPosX + 46, _startPosY + 3);
path5.AddLine(_startPosX + 46, _startPosY + 3, _startPosX + 6, _startPosY + 20);
path5.CloseFigure();
g.DrawPath(pen, path5);
g.FillPath(BodyColor, path5);
GraphicsPath path6 = new GraphicsPath();
path6.AddLine(_startPosX + 5, _startPosY + 22, _startPosX + 47, _startPosY + 5);
path6.AddLine(_startPosX + 47, _startPosY + 5, _startPosX + 51, _startPosY + 5);
path6.AddLine(_startPosX + 51, _startPosY + 5, _startPosX + 53, _startPosY + 7);
path6.AddLine(_startPosX + 53, _startPosY + 7, _startPosX + 8, _startPosY + 25);
path6.CloseFigure();
g.DrawPath(pen, path6);
g.FillPath(additionalBrush, path6);
GraphicsPath path7 = new GraphicsPath();
path7.AddLine(_startPosX + 7, _startPosY + 27, _startPosX + 46, _startPosY + 11);
path7.AddLine(_startPosX + 46, _startPosY + 11, _startPosX + 51, _startPosY + 9);
path7.AddLine(_startPosX + 51, _startPosY + 9, _startPosX + 56, _startPosY + 11);
path7.AddLine(_startPosX + 56, _startPosY + 11, _startPosX + 10, _startPosY + 31);
path7.CloseFigure();
g.DrawPath(pen, path7);
g.FillPath(BodyColor, path7);
}
base.DrawTransport(g);
// пушка
if (ustaBat.Pushka)
{
g.FillRectangle(pen2, _startPosX + 80, _startPosY + 25, 10, 10);
g.DrawRectangle(pen, _startPosX + 80, _startPosY + 25, 10, 10);
g.FillRectangle(additionalBrush, _startPosX + 90, _startPosY + 28, 40, 5);
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 28, 40, 5);
g.FillRectangle(additionalBrush, _startPosX + 130, _startPosY + 27, 5, 7);
g.DrawRectangle(pen, _startPosX + 130, _startPosY + 27, 5, 7);
}
}
}
}

View File

@ -4,8 +4,11 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit namespace SelfPropelledArtilleryUnit.Entities
{ {
/// <summary>
/// Класс-сущность "Установка"
/// </summary>
public class EntityUsta public class EntityUsta
{ {
/// <summary> /// <summary>
@ -21,42 +24,21 @@ namespace SelfPropelledArtilleryUnit
/// </summary> /// </summary>
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
/// <summary> /// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия батареи
/// </summary>
public bool BodyKit { get; private set; }
/// <summary>
/// Признак (опция) наличия пушки
/// </summary>
public bool Pushka { get; private set; }
/// <summary>
/// Шаг перемещения установки /// Шаг перемещения установки
/// </summary> /// </summary>
public double Step => (double)Speed * 100 / Weight; public double Step => (double)Speed * 100 / Weight;
/// <summary> /// <summary>
/// Инициализация полей объекта-класса установки с пушкой /// Конструктор с параметрами
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес установки</param> /// <param name="weight">Вес установки</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param> public EntityUsta(int speed, double weight, Color bodyColor)
/// <param name="bodyKit">Признак наличия батареи</param>
/// <param name="pushka">Признак наличия пушки</param>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool pushka)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Pushka = pushka;
} }
} }
} }

View File

@ -0,0 +1,40 @@
using System;
namespace SelfPropelledArtilleryUnit.Entities
{
/// <summary>
/// Класс-сущность "Установка с вооружением"
/// </summary>
public class EntityUstaBat : EntityUsta
{
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия батареи
/// </summary>
public bool BodyKit { get; private set; }
/// <summary>
/// Признак (опция) наличия пушки
/// </summary>
public bool Pushka { get; private set; }
/// <summary>
/// Инициализация полей объекта-класса установки с вооружением
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес установки</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="pushka">Признак наличия пушки</param>
/// <param name="bodyKit">Признак наличия батареи</param>
public EntityUstaBat(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool pushka)
: base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Pushka = pushka;
}
}
}

View File

@ -29,88 +29,123 @@
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormSelfPropelledArtilleryUnit)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormSelfPropelledArtilleryUnit));
pictureBoxUsta = new PictureBox(); comboBoxStrategy = new ComboBox();
buttonCreate = new Button(); ButtonCreateUstaBat = new Button();
buttonRight = new Button(); ButtonCreateUsta = new Button();
buttonLeft = new Button(); ButtonStep = new Button();
buttonDown = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonDown = new Button();
buttonLeft = new Button();
buttonRight = new Button();
pictureBoxUsta = new PictureBox();
((System.ComponentModel.ISupportInitialize)pictureBoxUsta).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxUsta).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder", "-" });
comboBoxStrategy.Location = new Point(667, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(121, 23);
comboBoxStrategy.TabIndex = 0;
//
// ButtonCreateUstaBat
//
ButtonCreateUstaBat.Location = new Point(19, 393);
ButtonCreateUstaBat.Name = "ButtonCreateUstaBat";
ButtonCreateUstaBat.Size = new Size(160, 42);
ButtonCreateUstaBat.TabIndex = 1;
ButtonCreateUstaBat.Text = "Создать арт. установку с вооружением";
ButtonCreateUstaBat.UseVisualStyleBackColor = true;
ButtonCreateUstaBat.Click += ButtonCreateUstaBat_Click;
//
// ButtonCreateUsta
//
ButtonCreateUsta.Location = new Point(185, 393);
ButtonCreateUsta.Name = "ButtonCreateUsta";
ButtonCreateUsta.Size = new Size(157, 42);
ButtonCreateUsta.TabIndex = 2;
ButtonCreateUsta.Text = "Создать арт. установку";
ButtonCreateUsta.UseVisualStyleBackColor = true;
ButtonCreateUsta.Click += ButtonCreateUsta_Click;
//
// ButtonStep
//
ButtonStep.Location = new Point(713, 50);
ButtonStep.Name = "ButtonStep";
ButtonStep.Size = new Size(75, 23);
ButtonStep.TabIndex = 3;
ButtonStep.Text = "Шаг";
ButtonStep.UseVisualStyleBackColor = true;
ButtonStep.Click += ButtonStep_Click;
//
// buttonUp
//
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
buttonUp.Location = new Point(617, 314);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(50, 50);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
buttonDown.Location = new Point(617, 370);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(50, 50);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// buttonLeft
//
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
buttonLeft.Location = new Point(561, 370);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(50, 50);
buttonLeft.TabIndex = 6;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
buttonRight.Location = new Point(673, 370);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(50, 50);
buttonRight.TabIndex = 7;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// pictureBoxUsta // pictureBoxUsta
// //
pictureBoxUsta.Dock = DockStyle.Fill; pictureBoxUsta.Dock = DockStyle.Fill;
pictureBoxUsta.Location = new Point(0, 0); pictureBoxUsta.Location = new Point(0, 0);
pictureBoxUsta.Name = "pictureBoxUsta"; pictureBoxUsta.Name = "pictureBoxUsta";
pictureBoxUsta.Size = new Size(884, 461); pictureBoxUsta.Size = new Size(800, 450);
pictureBoxUsta.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxUsta.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxUsta.TabIndex = 0; pictureBoxUsta.TabIndex = 8;
pictureBoxUsta.TabStop = false; pictureBoxUsta.TabStop = false;
// //
// buttonCreate
//
buttonCreate.Location = new Point(22, 417);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(109, 28);
buttonCreate.TabIndex = 8;
buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// buttonRight
//
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
buttonRight.Location = new Point(778, 390);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(50, 50);
buttonRight.TabIndex = 12;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
//
// buttonLeft
//
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
buttonLeft.Location = new Point(666, 390);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(50, 50);
buttonLeft.TabIndex = 11;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += buttonMove_Click;
//
// buttonDown
//
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
buttonDown.Location = new Point(722, 390);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(50, 50);
buttonDown.TabIndex = 10;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
//
// buttonUp
//
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
buttonUp.Location = new Point(722, 334);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(50, 50);
buttonUp.TabIndex = 9;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += buttonMove_Click;
//
// FormSelfPropelledArtilleryUnit // FormSelfPropelledArtilleryUnit
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(884, 461); ClientSize = new Size(800, 450);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonCreate); Controls.Add(ButtonStep);
Controls.Add(ButtonCreateUsta);
Controls.Add(ButtonCreateUstaBat);
Controls.Add(comboBoxStrategy);
Controls.Add(pictureBoxUsta); Controls.Add(pictureBoxUsta);
Name = "FormSelfPropelledArtilleryUnit"; Name = "FormSelfPropelledArtilleryUnit";
StartPosition = FormStartPosition.CenterScreen;
Text = "SelfPropelledArtilleryUnit"; Text = "SelfPropelledArtilleryUnit";
((System.ComponentModel.ISupportInitialize)pictureBoxUsta).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxUsta).EndInit();
ResumeLayout(false); ResumeLayout(false);
@ -118,12 +153,14 @@
} }
#endregion #endregion
private ComboBox comboBoxStrategy;
private PictureBox pictureBoxUsta; private Button ButtonCreateUstaBat;
private Button buttonCreate; private Button ButtonCreateUsta;
private Button buttonRight; private Button ButtonStep;
private Button buttonLeft;
private Button buttonDown;
private Button buttonUp; private Button buttonUp;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private PictureBox pictureBoxUsta;
} }
} }

View File

@ -1,12 +1,31 @@
using SelfPropelledArtilleryUnit.DrawningObjects;
using SelfPropelledArtilleryUnit.Drawnings;
using SelfPropelledArtilleryUnit.MovementStrategy;
namespace SelfPropelledArtilleryUnit namespace SelfPropelledArtilleryUnit
{ {
/// <summary>
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Óñòàíîâêà ñ âîîðóæåíèåì"
/// </summary>
public partial class FormSelfPropelledArtilleryUnit : Form public partial class FormSelfPropelledArtilleryUnit : Form
{ {
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawningUsta? _drawningUsta; private DrawningUsta? _drawningUsta;
/// <summary>
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
/// </summary>
private AbstractStrategy? _abstractStrategy;
/// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû
/// </summary>
public FormSelfPropelledArtilleryUnit() public FormSelfPropelledArtilleryUnit()
{ {
InitializeComponent(); InitializeComponent();
} }
/// <summary>
/// Ìåòîä ïðîðèñîâêè óñòàíîâêè
/// </summary>
private void Draw() private void Draw()
{ {
if (_drawningUsta == null) if (_drawningUsta == null)
@ -20,28 +39,48 @@ namespace SelfPropelledArtilleryUnit
pictureBoxUsta.Image = bmp; pictureBoxUsta.Image = bmp;
} }
/// <summary> /// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü" /// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü óñòàíîâêó ñ âîîðóæåíèåì"
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonCreateUstaBat_Click(object sender, EventArgs e)
private void buttonCreate_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
_drawningUsta = new DrawningUsta(); _drawningUsta = new DrawningUstaBat(random.Next(100, 300),
_drawningUsta.Init(random.Next(100, 300), random.Next(1000, 3000), random.Next(1000, 3000),
Color.FromArgb(30, 89, 69), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
Convert.ToBoolean(random.Next(0, 2)), random.Next(0, 256)),
pictureBoxUsta.Width, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxUsta.Height); pictureBoxUsta.Width, pictureBoxUsta.Height);
_drawningUsta.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawningUsta.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw(); Draw();
} }
/// <summary>
private void buttonMove_Click(object sender, EventArgs e) /// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü óñòàíîâêó"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateUsta_Click(object sender, EventArgs e)
{
Random random = new();
_drawningUsta = new DrawningUsta(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
pictureBoxUsta.Width, pictureBoxUsta.Height);
_drawningUsta.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
/// <summary>
/// Èçìåíåíèå ïîëîæåíèÿ óñòàíîâêè
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_drawningUsta == null) if (_drawningUsta == null)
{ {
@ -65,6 +104,48 @@ namespace SelfPropelledArtilleryUnit
} }
Draw(); Draw();
} }
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawningUsta == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawningObjectUsta(_drawningUsta), pictureBoxUsta.Width,
pictureBoxUsta.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy != null)
{
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
}
} }
} }

View File

@ -118,19 +118,32 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="buttonRight.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>
iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
DAAACwwBP0AiyAAAAhhJREFUaEPtmb2KWkEYhmUJaIKEgIUEvInU/qBhQVAQRFKk2GKbXWSbSIqQJneQ DAAACwwBP0AiyAAAAcJJREFUaEPtmcFKAkEYx+0m9Sz1BguKh6wFL0FdRPRaFEUPUYfoBfTcKxT4BC7a
IhdgrsFehLQBscgt5AIEf0DXZGffF84ZJus5o+se43wwDzyFxRm+h/PjGU15PB6Px8Jr+Ba+g+/hSyiO oc4dos5dXSGa/t8yH0TO1jjr7Iw1P/iBrM433++oVgL/iBg+w3cpvd6FK8Up/IDim/SM3lsJjmEWUa/X
r/AvVIZ/4A0Uwzk0A1QulzM/f4Ai+Az14PV6Xa1WK9VsNsXFfIF66E6no8h6vVatVsuM+QidJjKESIuJ RZIkYjQaZa/pmfQMes0hzCKazaaYTqeCmc1motVqfY05h16SG8GsQsyvEYzPMdoRjI8xC0cwPsUcQaMI
DSGSYqwhRErMzhAiIWavEJJUzCv4Df6CU7iCtwn4zxehLYTw0dxoNMyYRz2an8Gf0FzgKPZ6vWDkeJ4S xoeYwhGMy5ilRTAuYpYewZQZYy2CKSPGegRjM6a0CMZGzA7MhsVxLNI0lVfZh+6iO/l+uA2NeYSi0WiU
w3cgfWA2m1WDwUCNx+NEnUwmarPZBOPaOTTmGuqDSqVSsNxpOSSmC/UBlUolWOr0PPYB4GwIiTgzvIIi GsHQnXQ37QAfaCFTXqHo9XpiPB7nOplMjELpDJ1VzWS73S6HvNBCpiSQB/1op9OR6+nTbreVs3KkXYy5
cTqEPIjZwMj9jPMhZLFYqEKhEM7Jt+otRISQdrsdzvkdbiEiZDqdqnw+H84ZedM7HzKfz1W5XA5nXMMM gaqhc9ZqNbmePnRGNStH2sWYA6gaOmcJIfuwECfwCb7lmMKiITRDNZuku+nrs3WuYdEQmuGcEBJCLBFC
3MLpkAcRd5A/YETibAhv8Gq1akZcwliuoA4pFovBMqcl4kxcQCsVqEMymYzq9/tqOBwm6mg0UsvlMhjT QoglQkgIsUQICSGWCCEhxBJ/JuQKiiiK5Hr60Bk6K2c4h/5uFtVqVQwGAzEcDrXs9/vZGTorZzhnD/JC
ziER5AyOoI45lt1uNxg1nkMjQp5DboJ+wN9wBpcJyD2JDtm1H3lqxDHZe4fIy65Wq5kR1hv7f7NXiOsR ptIM52xB1XKLuAmdswbvoGpBHW8hzfCCDXgJ7yH9fKMjffYCrsNAwE8qlU+yNBGf6frdkAAAAABJRU5E
ZGeIhAhiDZESQWJDJEWQyBBpEeQT1CEcfjabOfuItVGGOoSm02lxESHczfHV2wziZ/4FJ44X8A0sBvK1 rkJggg==
yOPxeDxSSaXuAf56EEyW1ZwcAAAAAElFTkSuQmCC </value>
</data>
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
DAAACwwBP0AiyAAAAchJREFUaEPtmLFKM0EURqN1Kn0SMSJxSUjeQQsRUZsEku7HF9BafAF9AZukzANo
GUXtQwStVRLC32S9fneZATET3Z3NzOzKHDggiXPvPaUWPH+UVXgJn+BrTPl3L+AKzATL8AaSpteQZzhn
HaoOTOIadM4OVB2XxG3onGNIxWKRut0u9fv9WHY6negNv4X/eJBrziBVq1VKCr/ht2KGc84h1Wo1cV58
+A2/FTOc40N8iCF8iA8xhA/xIYbwIT7EED7EhxgiFyH8341T+A7lUqUpQ37yDZ7AJajNIVQNn9FgiPQA
anMFVUNntBDCt2hzC1VDZ2w2m+K8+DQaDeWsOfIt2rxAarfbNBgM5jocDikMQ3FefKbTafRWNVPaarVk
yDMfpMs9pHK5TOPxWKy3B+/k3XwDvOODdAngB6RKpWI1hnfxTt4tbtiCqdiFUUwQBDQajcQqc0wmE6rX
618jjuBCsBZjMkJiPMZGhMRYjM0IycJjXERIFhbjMkKSOiYLERLtmCxFSBLHZDFCEjsmyxGSX2PyECGZ
G5OnCMkejGJKpRL1er1I/pk/E9+l+mvPJvswivlmCPm7XLEJH+F/4QPcgB5PfigUPgEBKRF/8g21wAAA
AABJRU5ErkJggg==
</value> </value>
</data> </data>
<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">
@ -148,32 +161,19 @@
oAAAAABJRU5ErkJggg== oAAAAABJRU5ErkJggg==
</value> </value>
</data> </data>
<data name="buttonDown.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>
iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
DAAACwwBP0AiyAAAAchJREFUaEPtmLFKM0EURqN1Kn0SMSJxSUjeQQsRUZsEku7HF9BafAF9AZukzANo DAAACwwBP0AiyAAAAhhJREFUaEPtmb2KWkEYhmUJaIKEgIUEvInU/qBhQVAQRFKk2GKbXWSbSIqQJneQ
GUXtQwStVRLC32S9fneZATET3Z3NzOzKHDggiXPvPaUWPH+UVXgJn+BrTPl3L+AKzATL8AaSpteQZzhn IhdgrsFehLQBscgt5AIEf0DXZGffF84ZJus5o+se43wwDzyFxRm+h/PjGU15PB6Px8Jr+Ba+g+/hSyiO
HaoOTOIadM4OVB2XxG3onGNIxWKRut0u9fv9WHY6negNv4X/eJBrziBVq1VKCr/ht2KGc84h1Wo1cV58 r/AvVIZ/4A0Uwzk0A1QulzM/f4Ai+Az14PV6Xa1WK9VsNsXFfIF66E6no8h6vVatVsuM+QidJjKESIuJ
+A2/FTOc40N8iCF8iA8xhA/xIYbwIT7EED7EhxgiFyH8341T+A7lUqUpQ37yDZ7AJajNIVQNn9FgiPQA DSGSYqwhRErMzhAiIWavEJJUzCv4Df6CU7iCtwn4zxehLYTw0dxoNMyYRz2an8Gf0FzgKPZ6vWDkeJ4S
anMFVUNntBDCt2hzC1VDZ2w2m+K8+DQaDeWsOfIt2rxAarfbNBgM5jocDikMQ3FefKbTafRWNVPaarVk w3cgfWA2m1WDwUCNx+NEnUwmarPZBOPaOTTmGuqDSqVSsNxpOSSmC/UBlUolWOr0PPYB4GwIiTgzvIIi
yDMfpMs9pHK5TOPxWKy3B+/k3XwDvOODdAngB6RKpWI1hnfxTt4tbtiCqdiFUUwQBDQajcQqc0wmE6rX cTqEPIjZwMj9jPMhZLFYqEKhEM7Jt+otRISQdrsdzvkdbiEiZDqdqnw+H84ZedM7HzKfz1W5XA5nXMMM
618jjuBCsBZjMkJiPMZGhMRYjM0IycJjXERIFhbjMkKSOiYLERLtmCxFSBLHZDFCEjsmyxGSX2PyECGZ 3MLpkAcRd5A/YETibAhv8Gq1akZcwliuoA4pFovBMqcl4kxcQCsVqEMymYzq9/tqOBwm6mg0UsvlMhjT
G5OnCMkejGJKpRL1er1I/pk/E9+l+mvPJvswivlmCPm7XLEJH+F/4QPcgB5PfigUPgEBKRF/8g21wAAA ziER5AyOoI45lt1uNxg1nkMjQp5DboJ+wN9wBpcJyD2JDtm1H3lqxDHZe4fIy65Wq5kR1hv7f7NXiOsR
AABJRU5ErkJggg== ZGeIhAhiDZESQWJDJEWQyBBpEeQT1CEcfjabOfuItVGGOoSm02lxESHczfHV2wziZ/4FJ44X8A0sBvK1
</value> yOPxeDxSSaXuAf56EEyW1ZwcAAAAAElFTkSuQmCC
</data>
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
DAAACwwBP0AiyAAAAcJJREFUaEPtmcFKAkEYx+0m9Sz1BguKh6wFL0FdRPRaFEUPUYfoBfTcKxT4BC7a
oc4dos5dXSGa/t8yH0TO1jjr7Iw1P/iBrM433++oVgL/iBg+w3cpvd6FK8Up/IDim/SM3lsJjmEWUa/X
RZIkYjQaZa/pmfQMes0hzCKazaaYTqeCmc1motVqfY05h16SG8GsQsyvEYzPMdoRjI8xC0cwPsUcQaMI
xoeYwhGMy5ilRTAuYpYewZQZYy2CKSPGegRjM6a0CMZGzA7MhsVxLNI0lVfZh+6iO/l+uA2NeYSi0WiU
GsHQnXQ37QAfaCFTXqHo9XpiPB7nOplMjELpDJ1VzWS73S6HvNBCpiSQB/1op9OR6+nTbreVs3KkXYy5
gaqhc9ZqNbmePnRGNStH2sWYA6gaOmcJIfuwECfwCb7lmMKiITRDNZuku+nrs3WuYdEQmuGcEBJCLBFC
QoglQkgIsUQICSGWCCEhxBJ/JuQKiiiK5Hr60Bk6K2c4h/5uFtVqVQwGAzEcDrXs9/vZGTorZzhnD/JC
ptIM52xB1XKLuAmdswbvoGpBHW8hzfCCDXgJ7yH9fKMjffYCrsNAwE8qlU+yNBGf6frdkAAAAABJRU5E
rkJggg==
</value> </value>
</data> </data>
</root> </root>

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SelfPropelledArtilleryUnit.Drawnings;
namespace SelfPropelledArtilleryUnit.MovementStrategy
{
/// <summary>
/// Интерфейс для работы с перемещаемым объектом
/// </summary>
public interface IMoveableObject
{
/// <summary>
/// Получение координаты X объекта
/// </summary>
ObjectParameters? GetObjectPosition { get; }
/// <summary>
/// Шаг объекта
/// </summary>
int GetStep { get; }
/// <summary>
/// Проверка, можно ли переместиться по нужному направлению
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
bool CheckCanMove(DirectionType direction);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
void MoveObject(DirectionType direction);
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SelfPropelledArtilleryUnit.DrawningObjects;
using SelfPropelledArtilleryUnit.Drawnings;
namespace SelfPropelledArtilleryUnit.MovementStrategy
{
/// <summary>
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningUsta (паттерн Adapter)
/// </summary>
public class DrawningObjectUsta : IMoveableObject
{
private readonly DrawningUsta? _drawningUsta = null;
public DrawningObjectUsta(DrawningUsta drawningUsta)
{
_drawningUsta = drawningUsta;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningUsta == null || _drawningUsta.EntityUsta ==
null)
{
return null;
}
return new ObjectParameters(_drawningUsta.GetPosX,
_drawningUsta.GetPosY, _drawningUsta.GetWidth, _drawningUsta.GetHeight);
}
}
public int GetStep => (int)(_drawningUsta?.EntityUsta?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningUsta?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningUsta?.MoveTransport(direction);
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit.MovementStrategy
{
/// <summary>
/// Стратегия перемещения объекта к границе экрана
/// </summary>
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
MoveRight();
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit.MovementStrategy
{
/// <summary>
/// Стратегия перемещения объекта в центр экрана
/// </summary>
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
// Проверка, чтобы объект не двигался слишком далеко
if (Math.Abs(diffX) > GetStep() || Math.Abs(diffY) > GetStep())
{
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit.MovementStrategy
{
/// <summary>
/// Параметры-координаты объекта
/// </summary>
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
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;
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit.MovementStrategy
{
/// <summary>
/// Статус выполнения операции перемещения
/// </summary>
public enum Status
{
NotInit,
InProgress,
Finish
}
}