PIBD-12 kuznetsov_I.V. LabWork02 Simple #2
@ -1,186 +0,0 @@
|
||||
namespace ProjectGasolineTanker;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawingGasolineTanker
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityGasolineTanker? EntityGasolineTanker { 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 _drawingTankerWidth = 160;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки газовоза
|
||||
/// </summary>
|
||||
private readonly int _drawingTankerHeight = 55;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="ornamentWheels">Признак наличия украшения на колесах</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool ornamentWheels)
|
||||
{
|
||||
EntityGasolineTanker = new EntityGasolineTanker();
|
||||
EntityGasolineTanker.Init(speed, weight, bodyColor, additionalColor, bodyKit, ornamentWheels);
|
||||
_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)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityGasolineTanker == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - (int)EntityGasolineTanker.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityGasolineTanker.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - (int)EntityGasolineTanker.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityGasolineTanker.Step;
|
||||
}
|
||||
return true;
|
||||
//вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawingTankerWidth + (int)EntityGasolineTanker.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityGasolineTanker.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawingTankerHeight + (int)EntityGasolineTanker.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityGasolineTanker.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityGasolineTanker == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//бак бензовоза
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(EntityGasolineTanker.AdditionalColor);
|
||||
if (EntityGasolineTanker.BodyKit)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX.Value + 25, _startPosY.Value + 5, 100, 35);
|
||||
g.FillRectangle(dopBrush, _startPosX.Value + 80, _startPosY.Value, 10, 5);
|
||||
}
|
||||
|
||||
//колеса
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 130, _startPosY.Value + 35, 20, 20);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 35, 20, 20);
|
||||
//корпус
|
||||
Brush br = new SolidBrush(EntityGasolineTanker?.BodyColor ?? Color.Black);
|
||||
g.FillRectangle(br, _startPosX.Value + 115, _startPosY.Value + 5, 40, 40);
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 35, 140, 10);
|
||||
//окно
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 120, _startPosY.Value + 10, 25, 25);
|
||||
//окантовка
|
||||
g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value + 10, 25, 25);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 115, _startPosY.Value + 5, 40, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 35, 105, 10);
|
||||
//крыло колеса
|
||||
if (EntityGasolineTanker != null && EntityGasolineTanker.OrnamentWheels)
|
||||
{
|
||||
Pen penGray = new Pen(Color.Gray);
|
||||
g.DrawEllipse(penGray, _startPosX.Value + 130, _startPosY.Value + 35, 20, 20);
|
||||
g.DrawEllipse(penGray, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20);
|
||||
g.DrawEllipse(penGray, _startPosX.Value + 30, _startPosY.Value + 35, 20, 20);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
namespace ProjectGasolineTanker;
|
||||
namespace ProjectGasolineTanker.Drawings;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
Unknow = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
@ -23,5 +24,5 @@ public enum DirectionType
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
Right = 4,
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using ProjectGasolineTanker.Entities;
|
||||
|
||||
namespace ProjectGasolineTanker.Drawings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawingGasolineTanker : DrawingTanker
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="tank">Признак наличия обвеса</param>
|
||||
/// <param name="ornamentWheels">Признак наличия украшения на колесах</param>
|
||||
public DrawingGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool ornamentWheels) : base(160,55)
|
||||
{
|
||||
EntityTanker = new EntityGasolineTanker(speed, weight, bodyColor, additionalColor, tank, ornamentWheels);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTanker == null || EntityTanker is not EntityGasolineTanker tanker || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(tanker.AdditionalColor);
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 10;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 10;
|
||||
|
||||
//бак бензовоза
|
||||
if (tanker != null && tanker.Tank)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX.Value + 15, _startPosY.Value + 3, 100, 35);
|
||||
g.FillRectangle(dopBrush, _startPosX.Value + 70, _startPosY.Value, 5, 5);
|
||||
}
|
||||
|
||||
//крыло колеса
|
||||
if (tanker != null && tanker.OrnamentWheels)
|
||||
{
|
||||
Pen penGray = new Pen(Color.Gray);
|
||||
g.DrawEllipse(penGray, _startPosX.Value + 130, _startPosY.Value + 35, 20, 20);
|
||||
g.DrawEllipse(penGray, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20);
|
||||
g.DrawEllipse(penGray, _startPosX.Value + 30, _startPosY.Value + 35, 20, 20);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,225 @@
|
||||
using ProjectGasolineTanker.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.Drawings;
|
||||
public class DrawingTanker
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityTanker? EntityTanker { 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 _drawingTankerWidth = 130;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки газовоза
|
||||
/// </summary>
|
||||
private readonly int _drawingTankerHeight = 50;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawingTankerWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawingTankerHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawingTanker()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawingTanker(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityTanker = new EntityTanker(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="_drawingTankerWidt">Ширина прорисовки газовоза</param>
|
||||
/// <param name="_drawingTankerHeight">Высота прорисовки газовоза</param>
|
||||
protected DrawingTanker(int _drawingTankerWidth, int _drawingTankerHeight) : this()
|
||||
{
|
||||
this._drawingTankerWidth = _drawingTankerWidth;
|
||||
this._drawingTankerHeight = _drawingTankerHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public Boolean SetPictureSize(int width, int height)
|
||||
{
|
||||
if (width <= _drawingTankerWidth || height <= _drawingTankerHeight) return false;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
if (_startPosX + _drawingTankerWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth.Value - _drawingTankerWidth;
|
||||
}
|
||||
if (_startPosY + _drawingTankerHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight.Value - _drawingTankerHeight;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if (_drawingTankerHeight + y > _pictureHeight || y < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
if (_drawingTankerWidth + x > _pictureWidth || x < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityTanker == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - (int)EntityTanker.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityTanker.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - (int)EntityTanker.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityTanker.Step;
|
||||
}
|
||||
return true;
|
||||
//вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawingTankerWidth + (int)EntityTanker.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityTanker.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawingTankerHeight + (int)EntityTanker.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityTanker.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTanker == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new Pen(Color.Black);
|
||||
|
||||
//колеса
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 120, _startPosY.Value + 25, 20, 20);
|
||||
g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 25, 20, 20);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 20, _startPosY.Value + 25, 20, 20);
|
||||
//корпус
|
||||
Brush br = new SolidBrush(EntityTanker?.BodyColor ?? Color.Black);
|
||||
g.FillRectangle(br, _startPosX.Value + 105, _startPosY.Value, 40, 40);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 140, 10);
|
||||
//окно
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(brBlue, _startPosX.Value + 110, _startPosY.Value, 25, 25);
|
||||
//окантовка
|
||||
g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value, 25, 25);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 105, _startPosY.Value, 40, 40);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 105, 10);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace ProjectGasolineTanker.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Газовоз"
|
||||
/// </summary>
|
||||
public class EntityGasolineTanker : EntityTanker
|
||||
{
|
||||
public EntityGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool ornamentWheels) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Tank = tank;
|
||||
OrnamentWheels = ornamentWheels;
|
||||
}
|
||||
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак наличия цистерны
|
||||
/// </summary>
|
||||
public bool Tank { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак наличия украшенных колес
|
||||
/// </summary>
|
||||
public bool OrnamentWheels { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса газовоза
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес газовоза</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="tank">Признак наличия цистерны</param>
|
||||
/// <param name="ornamentWheels">Признак наличия украшенных колес</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool ornamentWheels)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Tank = tank;
|
||||
OrnamentWheels = ornamentWheels;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Танкер"
|
||||
/// </summary>
|
||||
public class EntityTanker
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения газовоза
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес газовоза</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public EntityTanker(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
namespace ProjectGasolineTanker;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Газовоз"
|
||||
/// </summary>
|
||||
public class EntityGasolineTanker
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак наличия обвеса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак наличия украшенных колес
|
||||
/// </summary>
|
||||
public bool OrnamentWheels { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения газовоза
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса газовоза
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес газовоза</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="ornamentWheels">Признак наличия украшенных колес</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool ornamentWheels)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
OrnamentWheels = ornamentWheels;
|
||||
}
|
||||
}
|
@ -34,6 +34,9 @@
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreateTanker = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxGasolineTanker).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -51,9 +54,9 @@
|
||||
buttonCreateGasolineTanker.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateGasolineTanker.Location = new Point(12, 682);
|
||||
buttonCreateGasolineTanker.Name = "buttonCreateGasolineTanker";
|
||||
buttonCreateGasolineTanker.Size = new Size(112, 34);
|
||||
buttonCreateGasolineTanker.Size = new Size(230, 34);
|
||||
buttonCreateGasolineTanker.TabIndex = 1;
|
||||
buttonCreateGasolineTanker.Text = "Создать";
|
||||
buttonCreateGasolineTanker.Text = "Создать Бензовоз";
|
||||
buttonCreateGasolineTanker.UseVisualStyleBackColor = true;
|
||||
buttonCreateGasolineTanker.Click += buttonCreateGasolineTanker_Click;
|
||||
//
|
||||
@ -105,11 +108,45 @@
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateTanker
|
||||
//
|
||||
buttonCreateTanker.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateTanker.Location = new Point(248, 682);
|
||||
buttonCreateTanker.Name = "buttonCreateTanker";
|
||||
buttonCreateTanker.Size = new Size(230, 34);
|
||||
buttonCreateTanker.TabIndex = 6;
|
||||
buttonCreateTanker.Text = "Создать Грузовик";
|
||||
buttonCreateTanker.UseVisualStyleBackColor = true;
|
||||
buttonCreateTanker.Click += buttonCreateTanker_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(1118, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(182, 33);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Location = new Point(1188, 51);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(112, 34);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += buttonStrategyStep_Click;
|
||||
//
|
||||
// FormGasolineTanker
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1312, 749);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateTanker);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
@ -130,5 +167,8 @@
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateTanker;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProjectGasolineTanker.Drawings;
|
||||
using ProjectGasolineTanker.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -15,29 +17,63 @@ namespace ProjectGasolineTanker
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawingGasolineTanker? _drawingGasolineTanker;
|
||||
private DrawingTanker? _drawingTanker;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация формы
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
public FormGasolineTanker()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки бензовоза
|
||||
/// </summary>
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingGasolineTanker == null)
|
||||
if (_drawingTanker == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingGasolineTanker.DrawTransport(gr);
|
||||
_drawingTanker.DrawTransport(gr);
|
||||
pictureBoxGasolineTanker.Image = bmp;
|
||||
}
|
||||
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawingTanker):
|
||||
_drawingTanker = new DrawingTanker(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawingGasolineTanker):
|
||||
_drawingTanker = new DrawingGasolineTanker(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawingTanker.SetPictureSize(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
|
||||
_drawingTanker.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки создать
|
||||
/// </summary>
|
||||
@ -45,16 +81,14 @@ namespace ProjectGasolineTanker
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateGasolineTanker_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingGasolineTanker = new DrawingGasolineTanker();
|
||||
_drawingGasolineTanker.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawingGasolineTanker.SetPictureSize(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
|
||||
_drawingGasolineTanker.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
CreateObject(nameof(DrawingGasolineTanker));
|
||||
}
|
||||
|
||||
private void buttonCreateTanker_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawingTanker));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
@ -62,7 +96,7 @@ namespace ProjectGasolineTanker
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingGasolineTanker == null)
|
||||
if (_drawingTanker == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -72,16 +106,16 @@ namespace ProjectGasolineTanker
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawingGasolineTanker.MoveTransport(DirectionType.Up);
|
||||
result = _drawingTanker.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawingGasolineTanker.MoveTransport(DirectionType.Down);
|
||||
result = _drawingTanker.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawingGasolineTanker.MoveTransport(DirectionType.Left);
|
||||
result = _drawingTanker.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawingGasolineTanker.MoveTransport(DirectionType.Right);
|
||||
result = _drawingTanker.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -90,5 +124,31 @@ namespace ProjectGasolineTanker
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingTanker == null) return;
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null) return;
|
||||
_strategy.SetData(new MoveableTanker(_drawingTanker), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
|
||||
}
|
||||
if (_strategy == null) return;
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
|
||||
namespace ProjectGasolineTanker.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
private IMoveableObject? _moveableObject;
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
|
||||
protected int FieldWidth { get; private set; }
|
||||
protected int FieldHeight { get; private set; }
|
||||
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
|
||||
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.MovementStrategy;
|
||||
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.RightBorder - FieldWidth + 11;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0) MoveLeft();
|
||||
else MoveRight();
|
||||
}
|
||||
int diffY = objParams.DownBorder - FieldHeight + 11;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0) MoveUp();
|
||||
else MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.MovementStrategy;
|
||||
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0) MoveLeft();
|
||||
else MoveRight();
|
||||
}
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0) MoveUp();
|
||||
else MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
using ProjectGasolineTanker.Drawings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.MovementStrategy;
|
||||
|
||||
public class MoveableTanker : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawingTanker или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawingTanker? _tanker = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="tanker">Объект класса DrawingTanker</param>
|
||||
public MoveableTanker(DrawingTanker tanker)
|
||||
{
|
||||
_tanker = tanker;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_tanker == null || _tanker.EntityTanker == null || !_tanker.GetPosX.HasValue || !_tanker.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_tanker.GetPosX.Value, _tanker.GetPosY.Value, _tanker.GetWidth, _tanker.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_tanker?.EntityTanker?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_tanker == null || _tanker.EntityTanker == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _tanker.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
/// <param name="direction">MovementDirection</param>
|
||||
/// <returns>DirectionType</returns>
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknow,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.MovementStrategy;
|
||||
|
||||
public enum MovementDirection
|
||||
{
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4,
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.MovementStrategy;
|
||||
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Координата x
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
|
||||
/// <summary>
|
||||
/// Координата y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
private readonly int _height;
|
||||
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата x</param>
|
||||
/// <param name="y">Координата y</param>
|
||||
/// <param name="width">Ширина объекта</param>
|
||||
/// <param name="height">Высота объекта</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.MovementStrategy;
|
||||
|
||||
public enum StrategyStatus
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user