done
This commit is contained in:
parent
d9c313d1bf
commit
2419848c25
@ -1,171 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using static System.Windows.Forms.AxHost;
|
|
||||||
|
|
||||||
namespace AntiAircraftGun
|
|
||||||
{
|
|
||||||
public class DrawingAntiAirCraftGun
|
|
||||||
|
|
||||||
{
|
|
||||||
private Point[] points = new Point[4];
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-сущность
|
|
||||||
/// </summary>
|
|
||||||
public EntityAntiAircraftGun? AntiAircraftGun { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина окна
|
|
||||||
/// </summary>
|
|
||||||
private int _pictureWidth;
|
|
||||||
/// <summary>
|
|
||||||
/// Высота окна
|
|
||||||
/// </summary>
|
|
||||||
private int _pictureHeight;
|
|
||||||
/// <summary>
|
|
||||||
/// Левая координата прорисовки автомобиля
|
|
||||||
/// </summary>
|
|
||||||
private int _startPosX;
|
|
||||||
/// <summary>
|
|
||||||
/// Верхняя кооридната прорисовки автомобиля
|
|
||||||
/// </summary>
|
|
||||||
private int _startPosY;
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина прорисовки автомобиля
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _zenitWidth = 110;
|
|
||||||
/// <summary>
|
|
||||||
/// Высота прорисовки автомобиля
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _zenitHeight = 60;
|
|
||||||
/// <summary>
|
|
||||||
/// Инициализация свойств
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
|
||||||
|
|
||||||
/// <param name="width">Ширина картинки</param>
|
|
||||||
/// <param name="height">Высота картинки</param>
|
|
||||||
/// <returns>true - объект создан, false - проверка не пройдена,
|
|
||||||
///нельзя создать объект в этих размерах</returns>
|
|
||||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, Color dopColor, bool rocket, bool radar, int width, int height)
|
|
||||||
{
|
|
||||||
if (width <= _zenitWidth || height <= _zenitHeight) return false;
|
|
||||||
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
|
||||||
AntiAircraftGun = new EntityAntiAircraftGun();
|
|
||||||
AntiAircraftGun.Init(speed, weight, bodyColor, additionalColor,dopColor,rocket,radar);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Установка позиции
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">Координата X</param>
|
|
||||||
/// <param name="y">Координата Y</param>
|
|
||||||
public void SetPosition(int x, int y)
|
|
||||||
{
|
|
||||||
if (AntiAircraftGun == null) return;
|
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
if (x + _zenitWidth >= _pictureWidth || y + _zenitHeight>= _pictureHeight)
|
|
||||||
{
|
|
||||||
_startPosX = 1;
|
|
||||||
_startPosY = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Изменение направления перемещения
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction">Направление</param>
|
|
||||||
public void MoveTransport(DirectionType direction)
|
|
||||||
{
|
|
||||||
if (AntiAircraftGun == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
//влево
|
|
||||||
case DirectionType.Left:
|
|
||||||
if (_startPosX - AntiAircraftGun.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosX -= (int)AntiAircraftGun.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вверх
|
|
||||||
case DirectionType.Up:
|
|
||||||
if (_startPosY - AntiAircraftGun.Step > 0)
|
|
||||||
{
|
|
||||||
_startPosY -= (int)AntiAircraftGun.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
// вправо
|
|
||||||
case DirectionType.Right:
|
|
||||||
if (_startPosX + AntiAircraftGun.Step < _pictureWidth-110)
|
|
||||||
{
|
|
||||||
_startPosX += (int)AntiAircraftGun.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//вниз
|
|
||||||
case DirectionType.Down:
|
|
||||||
if (_startPosY + AntiAircraftGun.Step < _pictureHeight-60)
|
|
||||||
{
|
|
||||||
_startPosY += (int)AntiAircraftGun.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Прорисовка объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (AntiAircraftGun == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Pen pen = new(Color.Black);
|
|
||||||
Brush bodyBrush = new SolidBrush(AntiAircraftGun.BodyColor);
|
|
||||||
Brush additionalBrush = new SolidBrush(AntiAircraftGun.AdditionalColor);
|
|
||||||
|
|
||||||
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY+40, 110, 10);
|
|
||||||
g.DrawEllipse(pen, _startPosX, _startPosY+40, 110, 10);
|
|
||||||
g.FillRectangle(bodyBrush, _startPosX, _startPosY+30, 110, 10);
|
|
||||||
g.DrawRectangle(pen, _startPosX, _startPosY+30, 110, 10);
|
|
||||||
g.FillRectangle(bodyBrush, _startPosX+80, _startPosY+10, 30, 20);
|
|
||||||
g.DrawRectangle(pen, _startPosX+80, _startPosY+10, 30, 20);
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
Rectangle trackRect = new Rectangle(_startPosX+20 + i*19, _startPosY+40, 10, 10);
|
|
||||||
g.DrawEllipse(pen, trackRect);
|
|
||||||
g.FillEllipse(Brushes.Black, trackRect);
|
|
||||||
}
|
|
||||||
Brush dopBrush = new SolidBrush(AntiAircraftGun.DopColor);
|
|
||||||
Pen dopPen = new Pen(AntiAircraftGun.DopColor);
|
|
||||||
if (AntiAircraftGun.Rocket)
|
|
||||||
{
|
|
||||||
points[0] = new Point(_startPosX, _startPosY + 30);
|
|
||||||
points[1] = new Point(_startPosX + 95, _startPosY + 5);
|
|
||||||
points[2] = new Point(_startPosX + 92, _startPosY);
|
|
||||||
points[3] = new Point(_startPosX, _startPosY + 25);
|
|
||||||
g.FillPolygon(dopBrush, points);
|
|
||||||
g.DrawPolygon(pen, points);
|
|
||||||
}
|
|
||||||
if (AntiAircraftGun.Radar)
|
|
||||||
{
|
|
||||||
g.DrawLine(dopPen, _startPosX + 105, _startPosY + 20, _startPosX +105, _startPosY + 5);
|
|
||||||
g.FillPie(dopBrush, _startPosX + 81, _startPosY-15, 30, 30, -45, 180);
|
|
||||||
g.DrawLine(dopPen, _startPosX + 98, _startPosY, _startPosX + 93, _startPosY + 10);
|
|
||||||
g.FillEllipse(dopBrush, _startPosX + 88, _startPosY -10, 10, 10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AntiAircraftGun.Enitites;
|
||||||
|
using static System.Windows.Forms.AxHost;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.DrawingObjects
|
||||||
|
{
|
||||||
|
public class AdvancedDrawingAntAirCraftGun : BaseDrawingAntiAirCraftGun
|
||||||
|
{
|
||||||
|
private Point[] points = new Point[4];
|
||||||
|
|
||||||
|
public AdvancedDrawingAntAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool rocket,bool radar, int width, int height) :
|
||||||
|
base(speed, weight, bodyColor, additionalColor, width, height)
|
||||||
|
{
|
||||||
|
EntityAntiAirСraftGun = new EntityAdvancedAntiAircraftGun(speed, weight, bodyColor, additionalColor, dopColor, rocket,radar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityAntiAirСraftGun is not EntityAdvancedAntiAircraftGun advancedGun)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new Pen(Color.Black);
|
||||||
|
Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor);
|
||||||
|
Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor);
|
||||||
|
base.DrawTransport(g);
|
||||||
|
Brush dopBrush = new SolidBrush(advancedGun.DopColor);
|
||||||
|
Pen dopPen = new Pen(advancedGun.DopColor);
|
||||||
|
if (advancedGun.Rocket)
|
||||||
|
{
|
||||||
|
points[0] = new Point(_startPosX, _startPosY + 30);
|
||||||
|
points[1] = new Point(_startPosX + 95, _startPosY + 5);
|
||||||
|
points[2] = new Point(_startPosX + 92, _startPosY);
|
||||||
|
points[3] = new Point(_startPosX, _startPosY + 25);
|
||||||
|
g.FillPolygon(dopBrush, points);
|
||||||
|
g.DrawPolygon(pen, points);
|
||||||
|
}
|
||||||
|
if (advancedGun.Radar)
|
||||||
|
{
|
||||||
|
g.DrawLine(dopPen, _startPosX + 105, _startPosY + 20, _startPosX +105, _startPosY + 5);
|
||||||
|
g.FillPie(dopBrush, _startPosX + 81, _startPosY-15, 30, 30, -45, 180);
|
||||||
|
g.DrawLine(dopPen, _startPosX + 98, _startPosY , _startPosX + 93, _startPosY + 10);
|
||||||
|
g.FillEllipse(dopBrush, _startPosX + 88, _startPosY -10, 10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,144 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AntiAircraftGun.Enitites;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.DrawingObjects
|
||||||
|
{
|
||||||
|
public class BaseDrawingAntiAirCraftGun
|
||||||
|
{
|
||||||
|
public EntityAntiAirCraftGun? EntityAntiAirСraftGun { get; protected set; }
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
|
protected int _zenitWidth = 110;
|
||||||
|
protected int _zenitHeight = 60;
|
||||||
|
|
||||||
|
public BaseDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height)
|
||||||
|
{
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityAntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BaseDrawingAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor, int width, int height, int carWidth, int carHeight)
|
||||||
|
{
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_zenitWidth = carWidth;
|
||||||
|
_zenitHeight = carHeight;
|
||||||
|
EntityAntiAirСraftGun = new EntityAntiAirCraftGun(speed, weight, bodyColor, additionalColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (x < 0 || y < 0)
|
||||||
|
{
|
||||||
|
_startPosX = 10;
|
||||||
|
_startPosY = 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Координата X объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Y объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetWidth => _zenitWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => _zenitHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка, что объект может переместится по указанному направлению
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||||
|
public bool CanMove(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityAntiAirСraftGun == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
DirectionType.Left => _startPosX - EntityAntiAirСraftGun.Step > 0,
|
||||||
|
//вверх
|
||||||
|
DirectionType.Up => _startPosY - EntityAntiAirСraftGun.Step > 0,
|
||||||
|
// вправо
|
||||||
|
DirectionType.Right =>_startPosX + EntityAntiAirСraftGun.Step < _pictureWidth - 110,
|
||||||
|
//вниз
|
||||||
|
DirectionType.Down => _startPosY + EntityAntiAirСraftGun.Step < _pictureHeight - 60,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
public void MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityAntiAirСraftGun == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case DirectionType.Left:
|
||||||
|
_startPosX -= (int)EntityAntiAirСraftGun.Step;
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case DirectionType.Up:
|
||||||
|
_startPosY -= (int)EntityAntiAirСraftGun.Step;
|
||||||
|
break;
|
||||||
|
// вправо
|
||||||
|
case DirectionType.Right:
|
||||||
|
_startPosX += (int)EntityAntiAirСraftGun.Step;
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case DirectionType.Down:
|
||||||
|
_startPosY += (int)EntityAntiAirСraftGun.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
Pen pen = Pens.Black;
|
||||||
|
Brush bodyBrush = new SolidBrush(EntityAntiAirСraftGun.BodyColor);
|
||||||
|
Brush additionalBrush = new SolidBrush(EntityAntiAirСraftGun.AdditionalColor);
|
||||||
|
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX, _startPosY + 40, 110, 10);
|
||||||
|
g.DrawEllipse(pen, _startPosX, _startPosY + 40, 110, 10);
|
||||||
|
g.FillRectangle(bodyBrush, _startPosX, _startPosY + 30, 110, 10);
|
||||||
|
g.DrawRectangle(pen, _startPosX, _startPosY + 30, 110, 10);
|
||||||
|
g.FillRectangle(bodyBrush, _startPosX + 80, _startPosY + 10, 30, 20);
|
||||||
|
g.DrawRectangle(pen, _startPosX + 80, _startPosY + 10, 30, 20);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
Rectangle trackRect = new Rectangle(_startPosX + 20 + i * 19, _startPosY + 40, 10, 10);
|
||||||
|
g.DrawEllipse(pen, trackRect);
|
||||||
|
g.FillEllipse(Brushes.Black, trackRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.Enitites
|
||||||
|
{
|
||||||
|
public class EntityAdvancedAntiAircraftGun : EntityAntiAirCraftGun
|
||||||
|
{
|
||||||
|
|
||||||
|
public Color DopColor { get; private set; }
|
||||||
|
|
||||||
|
public bool Rocket { get; private set; }
|
||||||
|
|
||||||
|
public bool Radar { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public EntityAdvancedAntiAircraftGun(int speed, double weight, Color bodyColor, Color additionalColor,Color dopColor, bool rocket, bool radar)
|
||||||
|
: base(speed, weight, bodyColor, additionalColor)
|
||||||
|
{
|
||||||
|
DopColor = dopColor;
|
||||||
|
Rocket = rocket;
|
||||||
|
Radar = radar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,14 +4,14 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AntiAircraftGun
|
namespace AntiAircraftGun.Enitites
|
||||||
{
|
{
|
||||||
public class EntityAntiAircraftGun
|
public class EntityAntiAirCraftGun
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Скорость
|
/// Скорость
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Speed { get; private set; }
|
public int Speed { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вес
|
/// Вес
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -21,7 +21,7 @@ namespace AntiAircraftGun
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
/// Шаг перемещения автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color AdditionalColor { get; private set; }
|
public Color AdditionalColor { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -29,33 +29,17 @@ namespace AntiAircraftGun
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Цвет для доп. деталей
|
/// Конструктор с параметрами
|
||||||
/// </summary>
|
|
||||||
public Color DopColor { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Ракета
|
|
||||||
/// </summary>
|
|
||||||
public bool Rocket { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Радар
|
|
||||||
/// </summary>
|
|
||||||
public bool Radar { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public EntityAntiAirCraftGun(int speed, double weight, Color bodyColor, Color additionalColor)
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, Color dopColor, bool rocket, bool radar)
|
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
DopColor = dopColor;
|
|
||||||
Rocket = rocket;
|
|
||||||
Radar = radar;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,38 +2,41 @@
|
|||||||
{
|
{
|
||||||
partial class FormAntiAirCraftGun
|
partial class FormAntiAirCraftGun
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.pictureBoxAntiAircraftGun = new System.Windows.Forms.PictureBox();
|
this.pictureBoxAntiAircraftGun = new System.Windows.Forms.PictureBox();
|
||||||
this.buttonCreate = new System.Windows.Forms.Button();
|
this.CreateAdavancedAntiAirCraftGun = new System.Windows.Forms.Button();
|
||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||||
|
this.CreateAntiAirCraftGun = new System.Windows.Forms.Button();
|
||||||
|
this.Step = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -47,16 +50,16 @@
|
|||||||
this.pictureBoxAntiAircraftGun.TabIndex = 0;
|
this.pictureBoxAntiAircraftGun.TabIndex = 0;
|
||||||
this.pictureBoxAntiAircraftGun.TabStop = false;
|
this.pictureBoxAntiAircraftGun.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// CreateAdavancedAntiAirCraftGun
|
||||||
//
|
//
|
||||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
this.CreateAdavancedAntiAirCraftGun.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
this.buttonCreate.Location = new System.Drawing.Point(32, 577);
|
this.CreateAdavancedAntiAirCraftGun.Location = new System.Drawing.Point(32, 577);
|
||||||
this.buttonCreate.Name = "buttonCreate";
|
this.CreateAdavancedAntiAirCraftGun.Name = "CreateAdavancedAntiAirCraftGun";
|
||||||
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
|
this.CreateAdavancedAntiAirCraftGun.Size = new System.Drawing.Size(183, 23);
|
||||||
this.buttonCreate.TabIndex = 1;
|
this.CreateAdavancedAntiAirCraftGun.TabIndex = 1;
|
||||||
this.buttonCreate.Text = "Создать";
|
this.CreateAdavancedAntiAirCraftGun.Text = "Создать с дополнениями";
|
||||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
this.CreateAdavancedAntiAirCraftGun.UseVisualStyleBackColor = true;
|
||||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
this.CreateAdavancedAntiAirCraftGun.Click += new System.EventHandler(this.CreateAdvancedAintiAirCraftGun_Click);
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
@ -106,16 +109,52 @@
|
|||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||||
|
"Двигаться в центер ",
|
||||||
|
"Двигаться в правый нижний угол",
|
||||||
|
"Двигаться к краю окна"});
|
||||||
|
this.comboBoxStrategy.Location = new System.Drawing.Point(1244, 28);
|
||||||
|
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
this.comboBoxStrategy.Size = new System.Drawing.Size(170, 23);
|
||||||
|
this.comboBoxStrategy.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// CreateAntiAirCraftGun
|
||||||
|
//
|
||||||
|
this.CreateAntiAirCraftGun.Location = new System.Drawing.Point(221, 577);
|
||||||
|
this.CreateAntiAirCraftGun.Name = "CreateAntiAirCraftGun";
|
||||||
|
this.CreateAntiAirCraftGun.Size = new System.Drawing.Size(185, 23);
|
||||||
|
this.CreateAntiAirCraftGun.TabIndex = 7;
|
||||||
|
this.CreateAntiAirCraftGun.Text = "Создать обычный";
|
||||||
|
this.CreateAntiAirCraftGun.UseVisualStyleBackColor = true;
|
||||||
|
this.CreateAntiAirCraftGun.Click += new System.EventHandler(this.CreateAntiAirCraftGun_Click);
|
||||||
|
//
|
||||||
|
// Step
|
||||||
|
//
|
||||||
|
this.Step.Location = new System.Drawing.Point(1323, 61);
|
||||||
|
this.Step.Name = "Step";
|
||||||
|
this.Step.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.Step.TabIndex = 8;
|
||||||
|
this.Step.Text = "Шаг";
|
||||||
|
this.Step.UseVisualStyleBackColor = true;
|
||||||
|
this.Step.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||||
|
//
|
||||||
// FormAntiAirCraftGun
|
// FormAntiAirCraftGun
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(1491, 628);
|
this.ClientSize = new System.Drawing.Size(1491, 628);
|
||||||
|
this.Controls.Add(this.Step);
|
||||||
|
this.Controls.Add(this.CreateAntiAirCraftGun);
|
||||||
|
this.Controls.Add(this.comboBoxStrategy);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
this.Controls.Add(this.buttonCreate);
|
this.Controls.Add(this.CreateAdavancedAntiAirCraftGun);
|
||||||
this.Controls.Add(this.pictureBoxAntiAircraftGun);
|
this.Controls.Add(this.pictureBoxAntiAircraftGun);
|
||||||
this.Name = "FormAntiAirCraftGun";
|
this.Name = "FormAntiAirCraftGun";
|
||||||
this.Text = "Form1";
|
this.Text = "Form1";
|
||||||
@ -123,16 +162,18 @@
|
|||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxAntiAircraftGun;
|
|
||||||
private Button buttonCreate;
|
|
||||||
private Button buttonLeft;
|
|
||||||
private Button buttonUp;
|
|
||||||
private Button buttonRight;
|
|
||||||
private Button buttonDown;
|
|
||||||
|
|
||||||
|
private PictureBox pictureBoxAntiAircraftGun;
|
||||||
|
private Button CreateAdavancedAntiAirCraftGun;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonDown;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button CreateAntiAirCraftGun;
|
||||||
|
private Button Step;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,64 +1,18 @@
|
|||||||
|
using AntiAircraftGun.DrawingObjects;
|
||||||
|
using AntiAircraftGun.MovementStrategy;
|
||||||
|
|
||||||
namespace AntiAircraftGun
|
namespace AntiAircraftGun
|
||||||
{
|
{
|
||||||
public partial class FormAntiAirCraftGun : Form
|
public partial class FormAntiAirCraftGun : Form
|
||||||
{
|
{
|
||||||
/// <summary>
|
private BaseDrawingAntiAirCraftGun _drawing;
|
||||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
|
||||||
/// </summary>
|
|
||||||
private DrawingAntiAirCraftGun? _drawing;
|
|
||||||
public FormAntiAirCraftGun()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
private void Move_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_drawing == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
||||||
switch (name)
|
|
||||||
{
|
|
||||||
case "buttonUp":
|
|
||||||
_drawing.MoveTransport(DirectionType.Up);
|
|
||||||
break;
|
|
||||||
case "buttonDown":
|
|
||||||
_drawing.MoveTransport(DirectionType.Down);
|
|
||||||
break;
|
|
||||||
case "buttonLeft":
|
|
||||||
_drawing.MoveTransport(DirectionType.Left);
|
|
||||||
break;
|
|
||||||
case "buttonRight":
|
|
||||||
_drawing.MoveTransport(DirectionType.Right);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public FormAntiAirCraftGun()
|
||||||
|
|
||||||
|
|
||||||
private void pictureBoxZenit_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
|
||||||
/// </summary>
|
|
||||||
private void Draw()
|
|
||||||
{
|
{
|
||||||
if (_drawing == null)
|
InitializeComponent();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width,pictureBoxAntiAircraftGun.Height);
|
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
|
||||||
_drawing.DrawTransport(gr);
|
|
||||||
pictureBoxAntiAircraftGun.Image = bmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawing == null)
|
if (_drawing == null)
|
||||||
@ -83,28 +37,89 @@ namespace AntiAircraftGun
|
|||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void Draw()
|
||||||
{
|
{
|
||||||
Random random = new();
|
if (_drawing == null)
|
||||||
_drawing = new DrawingAntiAirCraftGun();
|
{
|
||||||
_drawing.Init(random.Next(100, 300),//cêîðîñòü
|
return;
|
||||||
random.Next(1000, 3000), //âåñ
|
}
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),//îñíîâíîé öâåò
|
Bitmap bmp = new Bitmap(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||||
random.Next(0, 256)),
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),//äîï. öâåò
|
_drawing.DrawTransport(gr);
|
||||||
random.Next(0, 256)),
|
pictureBoxAntiAircraftGun.Image = bmp;
|
||||||
|
}
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), // Äîï. öâåò2
|
|
||||||
Convert.ToBoolean(random.Next(2)), // Rocket
|
|
||||||
Convert.ToBoolean(random.Next(2)), // Radar
|
|
||||||
|
|
||||||
pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
|
||||||
_drawing.SetPosition(random.Next(10, 100),
|
|
||||||
random.Next(10, 100));
|
|
||||||
|
|
||||||
|
private void CreateAdvancedAintiAirCraftGun_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
_drawing = new AdvancedDrawingAntAirCraftGun(
|
||||||
|
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)), // Äîï. öâåò
|
||||||
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), // Äîï. öâåò äëÿ EntityAdvancedAntiAircraftGun
|
||||||
|
Convert.ToBoolean(random.Next(2)), // Rocket
|
||||||
|
Convert.ToBoolean(random.Next(2)),
|
||||||
|
pictureBoxAntiAircraftGun.Width,
|
||||||
|
pictureBoxAntiAircraftGun.Height
|
||||||
|
);
|
||||||
|
|
||||||
|
_drawing.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CreateAntiAirCraftGun_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
_drawing = new BaseDrawingAntiAirCraftGun(
|
||||||
|
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)), // Äîï. öâåò
|
||||||
|
pictureBoxAntiAircraftGun.Width,
|
||||||
|
pictureBoxAntiAircraftGun.Height
|
||||||
|
);
|
||||||
|
|
||||||
|
_drawing.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawing == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||||
|
switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(new
|
||||||
|
DrawingObjectAntiAirCraftGun(_drawing), pictureBoxAntiAircraftGun.Width,
|
||||||
|
pictureBoxAntiAircraftGun.Height);
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,132 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.MovementStrategy
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum BorderDirection
|
||||||
|
{
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Top,
|
||||||
|
Bottom
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AntiAircraftGun.DrawingObjects;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.MovementStrategy
|
||||||
|
{
|
||||||
|
public class DrawingObjectAntiAirCraftGun : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly BaseDrawingAntiAirCraftGun? _drawningCar = null;
|
||||||
|
public DrawingObjectAntiAirCraftGun(BaseDrawingAntiAirCraftGun drawningCar)
|
||||||
|
{
|
||||||
|
_drawningCar = drawningCar;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningCar == null || _drawningCar.EntityAntiAirСraftGun ==
|
||||||
|
null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningCar.GetPosX,
|
||||||
|
_drawningCar.GetPosY, _drawningCar.GetWidth, _drawningCar.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningCar?.EntityAntiAirСraftGun?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(DirectionType direction) =>
|
||||||
|
_drawningCar?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DirectionType direction) =>
|
||||||
|
_drawningCar?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.MovementStrategy
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.MovementStrategy
|
||||||
|
{
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.MovementStrategy
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.MovementStrategy
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/Status.cs
Normal file
15
AntiAirCraftGun/AntiAirCraftGun/MovementStrategy/Status.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AntiAircraftGun.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user