Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de8bd02d0f |
@@ -4,37 +4,32 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
namespace ProectMilitaryAircraft;
|
||||
|
||||
/// <summary>
|
||||
/// Навравление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
Up =1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
Down =2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
Left =3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4,
|
||||
Right =4,
|
||||
|
||||
}
|
||||
|
||||
@@ -1,235 +0,0 @@
|
||||
using ProectMilitaryAircraft.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
|
||||
public class DrawningAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс - сущность
|
||||
/// </summary>
|
||||
public EntityAircraft? EntityAircraft { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прописовки самолета
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя координа прорисовки самолета
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawningMilitaryAircraftWidth = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawingMilitaryAircraftHeight = 110;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Координа Х
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningMilitaryAircraftWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawingMilitaryAircraftHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningAircraft()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public DrawningAircraft(int speed, double weight, Color bodyColor, int width, int height) : this()
|
||||
{
|
||||
if (width < _drawingMilitaryAircraftHeight || height < _drawningMilitaryAircraftWidth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Констуктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningMilitaryAircraftWidth">Ширина прорисовки самолета</param>
|
||||
/// <param name="drawingMilitaryAircraftHeight">Высота прорисовки самолета</param>
|
||||
|
||||
protected DrawningAircraft(int speed, double weight, Color bodyColor, int width, int height, int drawningMilitaryAircraftWidth, int drawingMilitaryAircraftHeight) : this()
|
||||
{
|
||||
if (width < _drawingMilitaryAircraftHeight || height < _drawningMilitaryAircraftWidth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_drawningMilitaryAircraftWidth = drawningMilitaryAircraftWidth;
|
||||
_drawingMilitaryAircraftHeight = drawingMilitaryAircraftHeight;
|
||||
EntityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width"> Ширина поля</param>
|
||||
/// <param name="height"> Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetpictureSize(int width, int height)
|
||||
{
|
||||
// TODO провека, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата Х</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAircraft == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//Влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityAircraft.Step > 0)
|
||||
{
|
||||
if (_startPosX - 50 <= _pictureWidth)
|
||||
_startPosX -= (int)EntityAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
//Вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityAircraft.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
//Вправо
|
||||
case DirectionType.Right:
|
||||
#pragma warning disable CS8629 // Тип значения, допускающего NULL, может быть NULL.
|
||||
if (_startPosX.Value + EntityAircraft.Step <= _pictureWidth.Value)
|
||||
{
|
||||
if (_startPosX + 98 <= _pictureWidth)
|
||||
_startPosX += (int)EntityAircraft.Step;
|
||||
}
|
||||
#pragma warning restore CS8629 // Тип значения, допускающего NULL, может быть NULL.
|
||||
return true;
|
||||
|
||||
//Влево
|
||||
case DirectionType.Down:
|
||||
#pragma warning disable CS8629 // Тип значения, допускающего NULL, может быть NULL.
|
||||
if (_startPosY.Value + EntityAircraft.Step <= _pictureHeight.Value)
|
||||
{
|
||||
if (_startPosY + 90 <= _pictureHeight)
|
||||
_startPosY += (int)EntityAircraft.Step;
|
||||
}
|
||||
#pragma warning restore CS8629 // Тип значения, допускающего NULL, может быть NULL.
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAircraft == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush br = new SolidBrush(EntityAircraft.BodyColor);
|
||||
|
||||
//крыло
|
||||
g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
|
||||
//хвост
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
|
||||
//Границы Самолета
|
||||
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
|
||||
//Хвост (центр)
|
||||
g.FillRectangle(br, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
|
||||
//Кабина
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 25);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 25, _startPosX.Value + 80, _startPosY.Value + 40);
|
||||
g.DrawLine(pen, _startPosX.Value + 80, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using ProectMilitaryAircraft.Entities;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за отрисовку и перемещение объекта - сущности
|
||||
/// </summary>
|
||||
public class DrawningMilitaryAircraft : DrawningAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Констуктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Доп. цвет</param>
|
||||
/// <param name="pin"> Признак наличия "Штыря на носу самолета"</param>
|
||||
/// <param name="rokets">Признак наличия "Символики"</param>
|
||||
/// <param name="symbolism">Признак наличия "Символики"</param>
|
||||
|
||||
public DrawningMilitaryAircraft(int speed, double weight, Color bodyColor, Color additionalColor, bool pin, bool rokets, bool symbolism, int width, int height) :base (speed, weight, bodyColor, width, height,120, 110)
|
||||
{
|
||||
if (EntityAircraft != null)
|
||||
{
|
||||
EntityAircraft = new EntityMilitaryAircraft(speed, weight, bodyColor, additionalColor, pin, rokets, symbolism);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAircraft is not EntityMilitaryAircraft airCraft || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush abr = new SolidBrush(airCraft.AdditionalColor);
|
||||
|
||||
Brush br = new SolidBrush(airCraft.BodyColor);
|
||||
|
||||
//крыло
|
||||
g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
|
||||
//хвост
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
|
||||
//Границы Самолета
|
||||
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
|
||||
//Хвост (центр)
|
||||
g.FillRectangle(br, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
|
||||
//Кабина
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 25);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 25, _startPosX.Value + 80, _startPosY.Value + 40);
|
||||
g.DrawLine(pen, _startPosX.Value + 80, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
//Ракеты
|
||||
if (airCraft.Rokets)
|
||||
{
|
||||
//Ракеты 1-3
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 20, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 20, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 13, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 13, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 6, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 6, 5, 5);
|
||||
|
||||
|
||||
//Ракеты 4-6
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 55, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 55, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 62, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 62, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 69, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 69, 5, 5);
|
||||
}
|
||||
|
||||
if (airCraft.Symbolism)
|
||||
{
|
||||
//Символ
|
||||
g.FillEllipse(abr, _startPosX.Value + 15, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.FillRectangle(abr, _startPosX.Value + 30, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
}
|
||||
|
||||
if (airCraft.Pin)
|
||||
{
|
||||
//Носовая часть
|
||||
g.FillEllipse(abr, _startPosX.Value + 78, _startPosY.Value + 37, 10, 5);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProectMilitaryAircraft;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за отрисовку и перемещение объекта - сущности
|
||||
/// </summary>
|
||||
public class DrawningMilitaryAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс - сущность
|
||||
/// </summary>
|
||||
public EntityMilitaryAircraft? EntityMilitaryAircraft { 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 _drawningMilitaryAircraftWidth = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawingMilitaryAircraftHeight = 110;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Доп. цвет</param>
|
||||
/// <param name="pin"> Признак наличия "Штыря на носу самолета"</param>
|
||||
/// <param name="rokets">Признак наличия "Символики"</param>
|
||||
/// <param name="symbolism">Признак наличия "Символики"</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pin, bool rokets, bool symbolism)
|
||||
{
|
||||
EntityMilitaryAircraft = new EntityMilitaryAircraft();
|
||||
EntityMilitaryAircraft.Init(speed, weight, bodyColor, additionalColor, pin, rokets, symbolism);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width"> Ширина поля</param>
|
||||
/// <param name="height"> Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetpictureSize(int width, int height)
|
||||
{
|
||||
if (width <= _drawningMilitaryAircraftWidth || height <= _drawingMilitaryAircraftHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата Х</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition (int x, int y)
|
||||
{
|
||||
int endx = x + _drawningMilitaryAircraftWidth;
|
||||
|
||||
int endy = y + _drawingMilitaryAircraftHeight;
|
||||
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (endx > _pictureWidth || x < 0 || endy > _pictureHeight || y < 0)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityMilitaryAircraft == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(direction)
|
||||
{
|
||||
//Влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityMilitaryAircraft.Step > 0)
|
||||
{
|
||||
if (_startPosX -50 <= _pictureWidth)
|
||||
_startPosX -= (int)EntityMilitaryAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
//Вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityMilitaryAircraft.Step > 0)
|
||||
{
|
||||
_startPosY -= (int) EntityMilitaryAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
//Вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityMilitaryAircraft.Step <= _pictureWidth.Value)
|
||||
{
|
||||
if (_startPosX + 98 <= _pictureWidth)
|
||||
_startPosX += (int)EntityMilitaryAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
//Влево
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityMilitaryAircraft.Step <= _pictureHeight.Value)
|
||||
{
|
||||
if (_startPosY + 90 <= _pictureHeight)
|
||||
_startPosY += (int)EntityMilitaryAircraft.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityMilitaryAircraft == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush abr = new SolidBrush(EntityMilitaryAircraft.AdditionalColor);
|
||||
Brush br = new SolidBrush(EntityMilitaryAircraft.BodyColor);
|
||||
|
||||
//крыло
|
||||
g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
|
||||
//хвост
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
|
||||
//Границы Самолета
|
||||
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
|
||||
//Хвост (центр)
|
||||
g.FillRectangle(br, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
|
||||
//Кабина
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value +25);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 25, _startPosX.Value + 80, _startPosY.Value +40);
|
||||
g.DrawLine(pen, _startPosX.Value + 80, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
|
||||
//Ракеты
|
||||
|
||||
if (EntityMilitaryAircraft.Rokets)
|
||||
{
|
||||
//Ракеты 1-3
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 20, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 20, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 13, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 13, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 6, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 6, 5, 5);
|
||||
|
||||
|
||||
//Ракеты 4-6
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 55, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 55, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 62, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 62, 5, 5);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 44, _startPosY.Value + 69, 5, 5);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 44, _startPosY.Value + 69, 5, 5);
|
||||
}
|
||||
|
||||
if (EntityMilitaryAircraft.Symbolism)
|
||||
{
|
||||
//Символ
|
||||
g.FillEllipse(abr, _startPosX.Value +15, _startPosY.Value +35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.FillRectangle(abr, _startPosX.Value + 30, _startPosY.Value +35, 10, 10);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 35, 10, 10);
|
||||
|
||||
g.FillEllipse(abr, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 35, 10, 10);
|
||||
}
|
||||
|
||||
if (EntityMilitaryAircraft.Pin)
|
||||
{
|
||||
//Носовая часть
|
||||
g.FillEllipse(abr, _startPosX.Value + 78, _startPosY.Value + 37, 10, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Entities;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Cамолет"
|
||||
/// </summary>
|
||||
public class EntityAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public EntityAircraft(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,21 @@
|
||||
namespace ProectMilitaryAircraft.Entities;
|
||||
namespace ProectMilitaryAircraft;
|
||||
/// <summary>
|
||||
/// Класс-сущность "Военный самолет"
|
||||
/// </summary>
|
||||
public class EntityMilitaryAircraft : EntityAircraft
|
||||
public class EntityMilitaryAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get;private set; }
|
||||
/// <summary>
|
||||
/// Доп. цвет
|
||||
/// </summary>
|
||||
@@ -11,7 +23,7 @@ public class EntityMilitaryAircraft : EntityAircraft
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия "Штыря на носу самолета"
|
||||
/// </summary>
|
||||
public bool Pin { get; private set; }
|
||||
public bool Pin { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия "Ракет"
|
||||
/// </summary>
|
||||
@@ -21,6 +33,14 @@ public class EntityMilitaryAircraft : EntityAircraft
|
||||
/// </summary>
|
||||
public bool Symbolism { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения самолета
|
||||
/// </summary>
|
||||
public double Step
|
||||
{
|
||||
get { return Speed * 100 / Weight; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -31,8 +51,11 @@ public class EntityMilitaryAircraft : EntityAircraft
|
||||
/// <param name="pin"> Признак наличия "Штыря на носу самолета"</param>
|
||||
/// <param name="rokets">Признак наличия "Символики"</param>
|
||||
/// <param name="symbolism">Признак наличия "Символики"</param>
|
||||
public EntityMilitaryAircraft(int speed, double weight, Color bodyColor, Color additionalColor, bool pin, bool rokets, bool symbolism) :base(speed, weight, bodyColor)
|
||||
public void Init( int speed, double weight, Color bodyColor, Color additionalColor, bool pin, bool rokets, bool symbolism )
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Pin = pin;
|
||||
Rokets = rokets;
|
||||
@@ -29,14 +29,11 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxMilitaryAircraft = new PictureBox();
|
||||
buttonCreateMA = new Button();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateA = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxMilitaryAircraft).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@@ -45,20 +42,20 @@
|
||||
pictureBoxMilitaryAircraft.Dock = DockStyle.Fill;
|
||||
pictureBoxMilitaryAircraft.Location = new Point(0, 0);
|
||||
pictureBoxMilitaryAircraft.Name = "pictureBoxMilitaryAircraft";
|
||||
pictureBoxMilitaryAircraft.Size = new Size(953, 651);
|
||||
pictureBoxMilitaryAircraft.Size = new Size(1108, 499);
|
||||
pictureBoxMilitaryAircraft.TabIndex = 0;
|
||||
pictureBoxMilitaryAircraft.TabStop = false;
|
||||
//
|
||||
// buttonCreateMA
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreateMA.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateMA.Location = new Point(12, 616);
|
||||
buttonCreateMA.Name = "buttonCreateMA";
|
||||
buttonCreateMA.Size = new Size(172, 23);
|
||||
buttonCreateMA.TabIndex = 1;
|
||||
buttonCreateMA.Text = "Создать военный самолет";
|
||||
buttonCreateMA.UseVisualStyleBackColor = true;
|
||||
buttonCreateMA.Click += ButtonCreateMA_Click;
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 464);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
@@ -67,7 +64,7 @@
|
||||
buttonLeft.BackgroundImage = Properties.Resources.Left;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.ForeColor = SystemColors.ControlLightLight;
|
||||
buttonLeft.Location = new Point(824, 610);
|
||||
buttonLeft.Location = new Point(979, 458);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.TabIndex = 2;
|
||||
@@ -81,7 +78,7 @@
|
||||
buttonUp.BackgroundImage = Properties.Resources.Up;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.ForeColor = SystemColors.ControlLightLight;
|
||||
buttonUp.Location = new Point(865, 569);
|
||||
buttonUp.Location = new Point(1020, 417);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 3;
|
||||
@@ -95,7 +92,7 @@
|
||||
buttonRight.BackgroundImage = Properties.Resources.Right;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.ForeColor = SystemColors.ControlLightLight;
|
||||
buttonRight.Location = new Point(906, 610);
|
||||
buttonRight.Location = new Point(1061, 458);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.TabIndex = 4;
|
||||
@@ -109,59 +106,23 @@
|
||||
buttonDown.BackgroundImage = Properties.Resources.Down;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.ForeColor = SystemColors.ControlLightLight;
|
||||
buttonDown.Location = new Point(865, 610);
|
||||
buttonDown.Location = new Point(1020, 458);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.TabIndex = 5;
|
||||
buttonDown.UseVisualStyleBackColor = false;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateA
|
||||
//
|
||||
buttonCreateA.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateA.Location = new Point(199, 616);
|
||||
buttonCreateA.Name = "buttonCreateA";
|
||||
buttonCreateA.Size = new Size(172, 23);
|
||||
buttonCreateA.TabIndex = 6;
|
||||
buttonCreateA.Text = "Создать самолет";
|
||||
buttonCreateA.UseVisualStyleBackColor = true;
|
||||
buttonCreateA.Click += ButtonCreateA_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К ценру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(823, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStrategyStep.Location = new Point(870, 41);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(75, 23);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormMilitaryAircraft
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(953, 651);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateA);
|
||||
ClientSize = new Size(1108, 499);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreateMA);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxMilitaryAircraft);
|
||||
Name = "FormMilitaryAircraft";
|
||||
Text = "Военный самолет";
|
||||
@@ -172,13 +133,10 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxMilitaryAircraft;
|
||||
private Button buttonCreateMA;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateA;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
||||
@@ -7,90 +7,48 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
namespace ProectMilitaryAircraft
|
||||
{
|
||||
public partial class FormMilitaryAircraft : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAircraft? _DrawningAircraft;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategys? _AbstractStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
private DrawningMilitaryAircraft? _DrawningMilitaryAircraft;
|
||||
public FormMilitaryAircraft()
|
||||
{
|
||||
InitializeComponent();
|
||||
_AbstractStrategy = null;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_DrawningAircraft == null)
|
||||
if (_DrawningMilitaryAircraft == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_DrawningAircraft.DrawTransport(gr);
|
||||
_DrawningMilitaryAircraft.DrawTransport(gr);
|
||||
pictureBoxMilitaryAircraft.Image = bmp;
|
||||
}
|
||||
|
||||
private void CreateObj(string type)
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAircraft):
|
||||
_DrawningAircraft = new DrawningAircraft(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
_DrawningMilitaryAircraft = new DrawningMilitaryAircraft();
|
||||
_DrawningMilitaryAircraft.Init(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
_DrawningMilitaryAircraft.SetpictureSize(pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
_DrawningMilitaryAircraft.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
||||
|
||||
break;
|
||||
|
||||
case nameof(DrawningMilitaryAircraft):
|
||||
_DrawningAircraft = new DrawningMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_DrawningAircraft.SetpictureSize(pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
_DrawningAircraft.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
||||
_AbstractStrategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка кнопки нажатия "Создать ваенный самолет"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateMA_Click(object sender, EventArgs e) => CreateObj(nameof(DrawningMilitaryAircraft));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка кнопки нажатия "Создать самолет"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateA_Click(object sender, EventArgs e) => CreateObj(nameof(DrawningAircraft));
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_DrawningAircraft == null)
|
||||
if (_DrawningMilitaryAircraft == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -98,64 +56,26 @@ namespace ProectMilitaryAircraft
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
|
||||
switch (name)
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _DrawningAircraft.MoveTransport(DirectionType.Up);
|
||||
result = _DrawningMilitaryAircraft.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _DrawningAircraft.MoveTransport(DirectionType.Down);
|
||||
result = _DrawningMilitaryAircraft.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _DrawningAircraft.MoveTransport(DirectionType.Left);
|
||||
result = _DrawningMilitaryAircraft.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _DrawningAircraft.MoveTransport(DirectionType.Right);
|
||||
result = _DrawningMilitaryAircraft.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result)
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_DrawningAircraft == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_AbstractStrategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_AbstractStrategy == null) { return; }
|
||||
|
||||
_AbstractStrategy.SetData(new MoveableAircraft(_DrawningAircraft), pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height);
|
||||
}
|
||||
|
||||
if (_AbstractStrategy == null) { return; }
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_AbstractStrategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_AbstractStrategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_AbstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.DirectoryServices.ActiveDirectory;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// класс - стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategys
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObjects? _moveableObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Статус перемеения
|
||||
/// </summary>
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObjects">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObjects moveableObjects, int width, int height)
|
||||
{
|
||||
if(moveableObjects == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObjects = moveableObjects;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTrgetDestansion())
|
||||
{
|
||||
_state |= StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns> Результат перемещения (true - да, false - неи)</returns>
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns> Результат перемещения (true - да, false - неи)</returns>
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение Вверх
|
||||
/// </summary>
|
||||
/// <returns> Результат перемещения (true - да, false - неи)</returns>
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение Вниз
|
||||
/// </summary>
|
||||
/// <returns> Результат перемещения (true - да, false - неи)</returns>
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters => _moveableObjects?.GetObjectPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObjects?.GetStep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTrgetDestansion();
|
||||
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _moveableObjects?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction"> Направление</param>
|
||||
/// <returns>true - Объект перемещен, false - перемещение невозможно-v</returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategys
|
||||
{
|
||||
protected override bool IsTrgetDestansion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
public class MoveToCenter : AbstractStrategys
|
||||
{
|
||||
protected override bool IsTrgetDestansion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if(objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2
|
||||
&& objParams.ObjectMiddleVertical +GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if(objParams == null) { return;}
|
||||
|
||||
int diffx = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffx) > GetStep())
|
||||
{
|
||||
if (diffx > 0) { MoveLeft(); } else { MoveRight(); }
|
||||
}
|
||||
|
||||
int diffy = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffy) > GetStep())
|
||||
{
|
||||
if (diffy > 0) { MoveUp(); } else { MoveDown(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Класс - реалицация IMoveableObjects с использованием DrawningAircraft
|
||||
/// </summary>
|
||||
public class MoveableAircraft : IMoveableObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле - объект класса DrawningAircraft или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningAircraft? _Air = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="Air">Объект класса DrawningAircraft</param>
|
||||
public MoveableAircraft(DrawningAircraft Air)
|
||||
{
|
||||
_Air = Air;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Air == null || _Air.EntityAircraft == null || !_Air.GetPosX.HasValue || !_Air.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_Air.GetPosX.Value, _Air.GetPosY.Value, _Air.GetWidth, _Air.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_Air?.EntityAircraft?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if(_Air == null || _Air.EntityAircraft == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _Air.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
/// <param name="direction">MovementDirection</param>
|
||||
/// <returns>DirectionType</returns>
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknow,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum MovementDirection
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
///Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4,
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Параметры - координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Координата Х
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
private readonly int _height;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _width;
|
||||
|
||||
/// <summary>
|
||||
/// Середнина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _height / 2;
|
||||
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.MovementStrategy;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
||||
Reference in New Issue
Block a user