Start
This commit is contained in:
parent
f94479162a
commit
d3a855e23c
@ -1,53 +0,0 @@
|
|||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace PrLaba1;
|
|
||||||
public class DiselLoko
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Скорость
|
|
||||||
/// </summary>
|
|
||||||
public int Speed { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// вес
|
|
||||||
/// </summary>
|
|
||||||
public double Weight { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Цвет тела
|
|
||||||
/// </summary>
|
|
||||||
public Color ColorBody { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// цвет бака
|
|
||||||
/// </summary>
|
|
||||||
public Color ColorComportament { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак наличия трубы
|
|
||||||
/// </summary>
|
|
||||||
public bool IsTube { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак наличия отсека
|
|
||||||
/// </summary>
|
|
||||||
public bool IsComportament { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// шаг, перемещенние обьекта
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Инициализация
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed"></param>
|
|
||||||
/// <param name="weight"></param>
|
|
||||||
/// <param name="colorBody"></param>
|
|
||||||
/// <param name="Comportament"></param>
|
|
||||||
/// <param name="isTube"></param>
|
|
||||||
/// <param name="isComportament"></param>
|
|
||||||
public void Init(int speed, double weight, Color colorBody, Color Comportament, bool isTube, bool isComportament)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
ColorBody = colorBody;
|
|
||||||
ColorComportament = Comportament;
|
|
||||||
IsTube = isTube;
|
|
||||||
IsComportament = isComportament;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,11 @@
|
|||||||
namespace PrLaba1;
|
namespace PrLaba1.Drawnings;
|
||||||
|
|
||||||
public enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неизвестное направление
|
||||||
|
/// </summary>
|
||||||
|
Unknow = -1,
|
||||||
///<summary>
|
///<summary>
|
||||||
///Вверх
|
///Вверх
|
||||||
///</summary>
|
///</summary>
|
76
PrLaba1/PrLaba1/Drawnings/DrawningDiselLoko.cs
Normal file
76
PrLaba1/PrLaba1/Drawnings/DrawningDiselLoko.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using PrLaba1.Entities;
|
||||||
|
|
||||||
|
namespace PrLaba1.Drawnings;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningDiselLoko : DrawningLoko
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="Comportamen">Дополнительный цвет</param>
|
||||||
|
/// <param name="isTube">Признак наличия трубы</param>
|
||||||
|
/// <param name="isComportament">Признак наличия топливного отсека</param>
|
||||||
|
public DrawningDiselLoko(int speed, double weight, Color bodyColor, Color Comportamen, bool isTube, bool isComportament) : base(140, 60)
|
||||||
|
{
|
||||||
|
EntityLoko = new DiselLoko(speed, weight, bodyColor, Comportamen, isTube, isComportament);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityLoko == null || EntityLoko is not DiselLoko diselLoko || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(diselLoko.ColorComportament);
|
||||||
|
|
||||||
|
// труба
|
||||||
|
if (diselLoko.IsTube)
|
||||||
|
{
|
||||||
|
// **Труба (полигон)**
|
||||||
|
|
||||||
|
Point[] chimney = {
|
||||||
|
new Point(_startPosX.Value + 20, _startPosY.Value - 20),
|
||||||
|
new Point(_startPosX.Value + 35, _startPosY.Value - 20),
|
||||||
|
new Point(_startPosX.Value + 35, _startPosY.Value),
|
||||||
|
new Point(_startPosX.Value + 20, _startPosY.Value)
|
||||||
|
};
|
||||||
|
g.DrawPolygon(pen, chimney);
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosX += 10;//change
|
||||||
|
_startPosY += 5;
|
||||||
|
base.DrawTransport(g);
|
||||||
|
_startPosX -= 10;
|
||||||
|
_startPosY -= 5;
|
||||||
|
|
||||||
|
// отсек
|
||||||
|
if (diselLoko.IsComportament)
|
||||||
|
{
|
||||||
|
//Топливный отсек(полигон)
|
||||||
|
Point[] fuelTank = {
|
||||||
|
new Point(_startPosX.Value + 110, _startPosY.Value ), // Верхний левый угол
|
||||||
|
new Point(_startPosX.Value + 130, _startPosY.Value ), // Верхний правый угол
|
||||||
|
new Point(_startPosX.Value +130 , _startPosY.Value ), // Нижний правый угол
|
||||||
|
new Point(_startPosX.Value + 110, _startPosY.Value ) // Нижний левый угол
|
||||||
|
};
|
||||||
|
g.DrawPolygon(pen, fuelTank);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,17 +1,16 @@
|
|||||||
using System;
|
using PrLaba1.Entities;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace PrLaba1;
|
namespace PrLaba1.Drawnings;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение базового объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
public class DrawningDiselLoko
|
public class DrawningLoko
|
||||||
{
|
{
|
||||||
///<summary>
|
///<summary>
|
||||||
///Класс-сущность
|
///Класс-сущность
|
||||||
///</summary>
|
///</summary>
|
||||||
public DiselLoko? DiselLoko { get; private set; }
|
public EntityLoko? EntityLoko { get; protected set; }
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Ширина окна
|
///Ширина окна
|
||||||
@ -26,22 +25,22 @@ public class DrawningDiselLoko
|
|||||||
///<summary>
|
///<summary>
|
||||||
///Левая координата прорисовки тепловоза
|
///Левая координата прорисовки тепловоза
|
||||||
///</summary>
|
///</summary>
|
||||||
private int? _startPosX;
|
protected int? _startPosX;
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Верхняя координата прорисовки тепловоза
|
///Верхняя координата прорисовки тепловоза
|
||||||
///</summary>
|
///</summary>
|
||||||
private int? _startPosY;
|
protected int? _startPosY;
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Ширина прорисовки тепловоза
|
///Ширина прорисовки тепловоза
|
||||||
///</summary>
|
///</summary>
|
||||||
private readonly int _drawingCarWidth = 140;
|
private readonly int _drawingCarWidth = 140;//поменять
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Высота прорисовки тепловоза
|
///Высота прорисовки тепловоза
|
||||||
///</summary>
|
///</summary>
|
||||||
private readonly int _drawingCarHeight = 60;
|
private readonly int _drawingCarHeight = 60;//поменять
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Высота прорисовки тепловоза с трубой
|
///Высота прорисовки тепловоза с трубой
|
||||||
@ -58,44 +57,78 @@ public class DrawningDiselLoko
|
|||||||
///</summary>
|
///</summary>
|
||||||
private int _InsertWidth = 10;
|
private int _InsertWidth = 10;
|
||||||
|
|
||||||
///<summary>
|
/// <summary>
|
||||||
///Иницилизация
|
/// Координата X объекта
|
||||||
///</summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
public int? GetPosX => _startPosX;
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="colorBody">Цвет тела</param>
|
|
||||||
/// <param name="colorComportament">Цвет колёс</param>
|
|
||||||
/// <param name="isTube">Признак езды</param>
|
|
||||||
/// <param name="isComportament">Признак заполнености</param>
|
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color colorBody, Color colorComportament, bool isTube, bool isComportament)
|
/// <summary>
|
||||||
|
/// Координата Y объекта
|
||||||
|
/// </summary>
|
||||||
|
public int? GetPosY => _startPosY;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetWidth => _drawingCarWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => _drawingCarHeight;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Пустой конструктор
|
||||||
|
/// </summary>
|
||||||
|
private DrawningLoko()
|
||||||
{
|
{
|
||||||
DiselLoko = new DiselLoko();
|
|
||||||
DiselLoko.Init(speed, weight, colorBody, colorComportament, isTube, isComportament);
|
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = null;
|
_startPosY = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public DrawningLoko(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityLoko = new EntityLoko(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор для наследников
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningCarWidth">Ширина прорисовки автомобиля</param>
|
||||||
|
/// <param name="drawningCarHeight">Высота прорисовки автомобиля</param>
|
||||||
|
protected DrawningLoko(int drawningCarWidth, int drawningCarHeight) : this()
|
||||||
|
{
|
||||||
|
_drawingCarWidth = drawningCarWidth;
|
||||||
|
_pictureHeight = drawningCarHeight;
|
||||||
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Установка границ поля
|
///Установка границ поля
|
||||||
///</summary>
|
///</summary>
|
||||||
/// <param name="width">Ширина поля</param>
|
/// <param name="width">Ширина поля</param>
|
||||||
/// <param name="height">Высота поля</param>
|
/// <param name="height">Высота поля</param>
|
||||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||||
|
|
||||||
public bool SetPictureSize(int width, int height)
|
public bool SetPictureSize(int width, int height)
|
||||||
{
|
{
|
||||||
// TODO проверка, что объект "влезает" в размеры поля
|
|
||||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
|
||||||
|
|
||||||
if (width <= _startPosX || height <= _startPosY) { return false; }
|
if (width <= _startPosX || height <= _startPosY) { return false; }
|
||||||
|
|
||||||
|
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции
|
/// Установка позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -115,7 +148,8 @@ public class DrawningDiselLoko
|
|||||||
|
|
||||||
if (y < 0) { y = 1; }
|
if (y < 0) { y = 1; }
|
||||||
|
|
||||||
if (x + _drawingCarWidth > _pictureWidth.Value) {
|
if (x + _drawingCarWidth > _pictureWidth.Value)
|
||||||
|
{
|
||||||
x = _pictureWidth.Value - _drawingCarWidth - 1;
|
x = _pictureWidth.Value - _drawingCarWidth - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +160,7 @@ public class DrawningDiselLoko
|
|||||||
|
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -136,7 +170,7 @@ public class DrawningDiselLoko
|
|||||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
public bool MoveTransport(Direction direction)
|
public bool MoveTransport(Direction direction)
|
||||||
{
|
{
|
||||||
if (DiselLoko == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityLoko == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -145,34 +179,31 @@ public class DrawningDiselLoko
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case Direction.Left:
|
case Direction.Left:
|
||||||
if (_startPosX.Value - DiselLoko.Step > 0)
|
if (_startPosX.Value - EntityLoko.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)DiselLoko.Step;
|
_startPosX -= (int)EntityLoko.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case Direction.Up:
|
case Direction.Up:
|
||||||
|
|
||||||
if (_startPosY.Value - _drawingCarHeightWithKit >= 0 && DiselLoko.IsTube)
|
if (_startPosY.Value - _drawingCarHeightWithKit >= 0)
|
||||||
{
|
{
|
||||||
_startPosY = _startPosY - (int)DiselLoko.Step;
|
_startPosY = _startPosY - (int)EntityLoko.Step;
|
||||||
}else if(_startPosY.Value - DiselLoko.Step > 0 && !DiselLoko.IsTube)
|
|
||||||
{
|
|
||||||
_startPosY = _startPosY - (int)DiselLoko.Step;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case Direction.Right:
|
case Direction.Right:
|
||||||
if (_startPosX.Value < _pictureWidth.Value - _drawingCarWidth-_InsertWidth)
|
if (_startPosX.Value < _pictureWidth.Value - _drawingCarWidth - _InsertWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)DiselLoko.Step;
|
_startPosX += (int)EntityLoko.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case Direction.Down:
|
case Direction.Down:
|
||||||
if (_startPosY.Value + _WheelHeight + _drawingCarHeight < _pictureHeight.Value )
|
if (_startPosY.Value + _WheelHeight + _drawingCarHeight < _pictureHeight.Value)
|
||||||
{
|
{
|
||||||
_startPosY += (int)DiselLoko.Step;
|
_startPosY += (int)EntityLoko.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -184,17 +215,17 @@ public class DrawningDiselLoko
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (DiselLoko == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityLoko == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush additionalBrush = new SolidBrush(DiselLoko.ColorBody);
|
Brush additionalBrush = new SolidBrush(EntityLoko.ColorBody);
|
||||||
Brush blueBrush = Brushes.Blue;
|
Brush blueBrush = Brushes.Blue;
|
||||||
|
|
||||||
Pen blackPen = new Pen(Color.Black, 2);
|
Pen blackPen = new Pen(Color.Black, 2);
|
||||||
Brush blackBrush = Brushes.Black;
|
Brush blackBrush = Brushes.Black;
|
||||||
|
|
||||||
@ -207,14 +238,14 @@ public class DrawningDiselLoko
|
|||||||
new Point(_startPosX.Value-10, _startPosY.Value + _drawingCarHeight/2)
|
new Point(_startPosX.Value-10, _startPosY.Value + _drawingCarHeight/2)
|
||||||
|
|
||||||
};
|
};
|
||||||
Brush br = new SolidBrush(DiselLoko.ColorBody);
|
Brush br = new SolidBrush(EntityLoko.ColorBody);
|
||||||
g.FillPolygon(br, trainBody);
|
g.FillPolygon(br, trainBody);
|
||||||
|
|
||||||
|
|
||||||
//разделительная линия
|
//разделительная линия
|
||||||
|
|
||||||
g.DrawLine(blackPen, _startPosX.Value-10, _startPosY.Value + _drawingCarHeight / 2, _startPosX.Value + 55, _startPosY.Value + _drawingCarHeight / 2);
|
g.DrawLine(blackPen, _startPosX.Value - 10, _startPosY.Value + _drawingCarHeight / 2, _startPosX.Value + 55, _startPosY.Value + _drawingCarHeight / 2);
|
||||||
g.DrawLine(blackPen, _startPosX.Value + 140, _startPosY.Value + _drawingCarHeight / 2, _startPosX.Value + _drawingCarHeight+15, _startPosY.Value + _drawingCarHeight / 2);
|
g.DrawLine(blackPen, _startPosX.Value + 140, _startPosY.Value + _drawingCarHeight / 2, _startPosX.Value + _drawingCarHeight + 15, _startPosY.Value + _drawingCarHeight / 2);
|
||||||
|
|
||||||
// Окна (полигоны)
|
// Окна (полигоны)
|
||||||
Point[] window1 = {
|
Point[] window1 = {
|
||||||
@ -256,7 +287,7 @@ public class DrawningDiselLoko
|
|||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
Brush brBlack = new SolidBrush(Color.Black);
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
g.FillEllipse(brBlack, _startPosX.Value + (i * 35), _startPosY.Value + _drawingCarHeight, 20, 20);
|
g.FillEllipse(brBlack, _startPosX.Value + i * 35, _startPosY.Value + _drawingCarHeight, 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Черные вставки внизу корпуса (полигон)
|
// Черные вставки внизу корпуса (полигон)
|
||||||
@ -266,7 +297,7 @@ public class DrawningDiselLoko
|
|||||||
new Point(_startPosX.Value + _drawingCarWidth, _startPosY.Value + _drawingCarHeight + 10),
|
new Point(_startPosX.Value + _drawingCarWidth, _startPosY.Value + _drawingCarHeight + 10),
|
||||||
new Point(_startPosX.Value+10, _startPosY.Value + _drawingCarHeight + 10)
|
new Point(_startPosX.Value+10, _startPosY.Value + _drawingCarHeight + 10)
|
||||||
};
|
};
|
||||||
|
|
||||||
Point[] bottomBlack3 = {
|
Point[] bottomBlack3 = {
|
||||||
new Point(_startPosX.Value, _startPosY.Value + _drawingCarHeight),
|
new Point(_startPosX.Value, _startPosY.Value + _drawingCarHeight),
|
||||||
new Point(_startPosX.Value+7, _startPosY.Value + _drawingCarHeight),
|
new Point(_startPosX.Value+7, _startPosY.Value + _drawingCarHeight),
|
||||||
@ -281,41 +312,10 @@ public class DrawningDiselLoko
|
|||||||
};
|
};
|
||||||
g.FillPolygon(blackBrush, bottomBlack);
|
g.FillPolygon(blackBrush, bottomBlack);
|
||||||
g.FillPolygon(blackBrush, bottomBlack3);
|
g.FillPolygon(blackBrush, bottomBlack3);
|
||||||
|
|
||||||
|
|
||||||
// Черные вставки сбоку корпуса (полигон)
|
// Черные вставки сбоку корпуса (полигон)
|
||||||
g.FillRectangle(blackBrush, _startPosX.Value + _drawingCarWidth, _startPosY.Value + 10, 10, _drawingCarHeight - 20);
|
g.FillRectangle(blackBrush, _startPosX.Value + _drawingCarWidth, _startPosY.Value + 10, 10, _drawingCarHeight - 20);
|
||||||
|
|
||||||
// труба
|
|
||||||
if (DiselLoko.IsTube)
|
|
||||||
{
|
|
||||||
// **Труба (полигон)**
|
|
||||||
_drawingCarHeightWithKit = 20;
|
|
||||||
Point[] chimney = {
|
|
||||||
new Point(_startPosX.Value + 20, _startPosY.Value - 20),
|
|
||||||
new Point(_startPosX.Value + 35, _startPosY.Value - 20),
|
|
||||||
new Point(_startPosX.Value + 35, _startPosY.Value),
|
|
||||||
new Point(_startPosX.Value + 20, _startPosY.Value)
|
|
||||||
};
|
|
||||||
g.FillPolygon(blackBrush, chimney);
|
|
||||||
}
|
|
||||||
|
|
||||||
// отсек
|
|
||||||
if (DiselLoko.IsComportament)
|
|
||||||
{
|
|
||||||
//Топливный отсек(полигон)
|
|
||||||
Point[] fuelTank = {
|
|
||||||
new Point(_startPosX.Value + 110, _startPosY.Value + _drawingCarHeight-20), // Верхний левый угол
|
|
||||||
new Point(_startPosX.Value + 130, _startPosY.Value + _drawingCarHeight -20), // Верхний правый угол
|
|
||||||
new Point(_startPosX.Value +130 , _startPosY.Value + _drawingCarHeight-5), // Нижний правый угол
|
|
||||||
new Point(_startPosX.Value + 110, _startPosY.Value + _drawingCarHeight-5) // Нижний левый угол
|
|
||||||
};
|
|
||||||
Brush br2 = new SolidBrush(DiselLoko.ColorComportament);
|
|
||||||
g.FillPolygon(br2, fuelTank);
|
|
||||||
g.DrawPolygon(blackPen, fuelTank);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
33
PrLaba1/PrLaba1/Entities/DiselLoko.cs
Normal file
33
PrLaba1/PrLaba1/Entities/DiselLoko.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
namespace PrLaba1.Entities;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Тепловоз с обвесами"
|
||||||
|
/// </summary>
|
||||||
|
public class DiselLoko : EntityLoko
|
||||||
|
{
|
||||||
|
public Color ColorComportament { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия трубы
|
||||||
|
/// </summary>
|
||||||
|
public bool IsTube { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия отсека
|
||||||
|
/// </summary>
|
||||||
|
public bool IsComportament { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="Comportament">цвет отсека</param>
|
||||||
|
/// <param name="isTube">признак наличия трубы</param>
|
||||||
|
/// <param name="isComportament">признак наличия отсека</param>
|
||||||
|
public DiselLoko(int speed, double weight, Color bodyColor, Color Comportament, bool isTube, bool isComportament) : base(0, 0, Color.Black)
|
||||||
|
{
|
||||||
|
ColorComportament = Comportament;
|
||||||
|
IsTube = isTube;
|
||||||
|
IsComportament = isComportament;
|
||||||
|
}
|
||||||
|
}
|
39
PrLaba1/PrLaba1/Entities/EntityLoko.cs
Normal file
39
PrLaba1/PrLaba1/Entities/EntityLoko.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
namespace PrLaba1.Entities;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Тепловоза"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityLoko
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет тела
|
||||||
|
/// </summary>
|
||||||
|
public Color ColorBody { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// шаг, перемещенние обьекта
|
||||||
|
/// </summary>
|
||||||
|
public double Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор сущности
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed"></param>
|
||||||
|
/// <param name="weight"></param>
|
||||||
|
/// <param name="colorBody"></param>
|
||||||
|
public EntityLoko(int speed, double weight, Color colorBody)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
ColorBody = colorBody;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
74
PrLaba1/PrLaba1/FormDiselLoko.Designer.cs
generated
74
PrLaba1/PrLaba1/FormDiselLoko.Designer.cs
generated
@ -35,6 +35,9 @@
|
|||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
ButtonLeft = new Button();
|
ButtonLeft = new Button();
|
||||||
|
buttonCreateLoko = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonStrategyStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxDiselLoko).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxDiselLoko).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -42,20 +45,18 @@
|
|||||||
//
|
//
|
||||||
pictureBoxDiselLoko.Dock = DockStyle.Fill;
|
pictureBoxDiselLoko.Dock = DockStyle.Fill;
|
||||||
pictureBoxDiselLoko.Location = new Point(0, 0);
|
pictureBoxDiselLoko.Location = new Point(0, 0);
|
||||||
pictureBoxDiselLoko.Margin = new Padding(5, 6, 5, 6);
|
|
||||||
pictureBoxDiselLoko.Name = "pictureBoxDiselLoko";
|
pictureBoxDiselLoko.Name = "pictureBoxDiselLoko";
|
||||||
pictureBoxDiselLoko.Size = new Size(1371, 900);
|
pictureBoxDiselLoko.Size = new Size(800, 450);
|
||||||
pictureBoxDiselLoko.TabIndex = 0;
|
pictureBoxDiselLoko.TabIndex = 0;
|
||||||
pictureBoxDiselLoko.TabStop = false;
|
pictureBoxDiselLoko.TabStop = false;
|
||||||
//
|
//
|
||||||
// create
|
// create
|
||||||
//
|
//
|
||||||
create.Location = new Point(21, 830);
|
create.Location = new Point(12, 415);
|
||||||
create.Margin = new Padding(5, 6, 5, 6);
|
|
||||||
create.Name = "create";
|
create.Name = "create";
|
||||||
create.Size = new Size(129, 46);
|
create.Size = new Size(188, 23);
|
||||||
create.TabIndex = 1;
|
create.TabIndex = 1;
|
||||||
create.Text = "Создать";
|
create.Text = "Создать тепловоз с обвесами";
|
||||||
create.UseVisualStyleBackColor = true;
|
create.UseVisualStyleBackColor = true;
|
||||||
create.Click += ButtonCreate_Click;
|
create.Click += ButtonCreate_Click;
|
||||||
//
|
//
|
||||||
@ -63,10 +64,9 @@
|
|||||||
//
|
//
|
||||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonUp.Location = new Point(1236, 736);
|
buttonUp.Location = new Point(721, 368);
|
||||||
buttonUp.Margin = new Padding(5, 6, 5, 6);
|
|
||||||
buttonUp.Name = "buttonUp";
|
buttonUp.Name = "buttonUp";
|
||||||
buttonUp.Size = new Size(60, 70);
|
buttonUp.Size = new Size(35, 35);
|
||||||
buttonUp.TabIndex = 2;
|
buttonUp.TabIndex = 2;
|
||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += ButtonMove_Click;
|
buttonUp.Click += ButtonMove_Click;
|
||||||
@ -75,10 +75,9 @@
|
|||||||
//
|
//
|
||||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonDown.Location = new Point(1236, 806);
|
buttonDown.Location = new Point(721, 403);
|
||||||
buttonDown.Margin = new Padding(5, 6, 5, 6);
|
|
||||||
buttonDown.Name = "buttonDown";
|
buttonDown.Name = "buttonDown";
|
||||||
buttonDown.Size = new Size(60, 70);
|
buttonDown.Size = new Size(35, 35);
|
||||||
buttonDown.TabIndex = 3;
|
buttonDown.TabIndex = 3;
|
||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
buttonDown.Click += ButtonMove_Click;
|
buttonDown.Click += ButtonMove_Click;
|
||||||
@ -87,10 +86,9 @@
|
|||||||
//
|
//
|
||||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonRight.Location = new Point(1291, 806);
|
buttonRight.Location = new Point(753, 403);
|
||||||
buttonRight.Margin = new Padding(5, 6, 5, 6);
|
|
||||||
buttonRight.Name = "buttonRight";
|
buttonRight.Name = "buttonRight";
|
||||||
buttonRight.Size = new Size(60, 70);
|
buttonRight.Size = new Size(35, 35);
|
||||||
buttonRight.TabIndex = 4;
|
buttonRight.TabIndex = 4;
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += ButtonMove_Click;
|
buttonRight.Click += ButtonMove_Click;
|
||||||
@ -99,27 +97,58 @@
|
|||||||
//
|
//
|
||||||
ButtonLeft.BackgroundImage = (Image)resources.GetObject("ButtonLeft.BackgroundImage");
|
ButtonLeft.BackgroundImage = (Image)resources.GetObject("ButtonLeft.BackgroundImage");
|
||||||
ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
ButtonLeft.Location = new Point(1181, 806);
|
ButtonLeft.Location = new Point(689, 403);
|
||||||
ButtonLeft.Margin = new Padding(5, 6, 5, 6);
|
|
||||||
ButtonLeft.Name = "ButtonLeft";
|
ButtonLeft.Name = "ButtonLeft";
|
||||||
ButtonLeft.Size = new Size(60, 70);
|
ButtonLeft.Size = new Size(35, 35);
|
||||||
ButtonLeft.TabIndex = 5;
|
ButtonLeft.TabIndex = 5;
|
||||||
ButtonLeft.TextImageRelation = TextImageRelation.TextBeforeImage;
|
ButtonLeft.TextImageRelation = TextImageRelation.TextBeforeImage;
|
||||||
ButtonLeft.UseVisualStyleBackColor = true;
|
ButtonLeft.UseVisualStyleBackColor = true;
|
||||||
ButtonLeft.Click += ButtonMove_Click;
|
ButtonLeft.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreateLoko
|
||||||
|
//
|
||||||
|
buttonCreateLoko.Location = new Point(218, 415);
|
||||||
|
buttonCreateLoko.Name = "buttonCreateLoko";
|
||||||
|
buttonCreateLoko.Size = new Size(188, 23);
|
||||||
|
buttonCreateLoko.TabIndex = 6;
|
||||||
|
buttonCreateLoko.Text = "Создать тепловоз";
|
||||||
|
buttonCreateLoko.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateLoko.Click += buttonCreateLoko_Click;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||||
|
comboBoxStrategy.Location = new Point(667, 12);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(121, 23);
|
||||||
|
comboBoxStrategy.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonStrategyStep
|
||||||
|
//
|
||||||
|
buttonStrategyStep.Location = new Point(713, 41);
|
||||||
|
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||||
|
buttonStrategyStep.Size = new Size(75, 23);
|
||||||
|
buttonStrategyStep.TabIndex = 8;
|
||||||
|
buttonStrategyStep.Text = "Шаг";
|
||||||
|
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStrategyStep.Click += buttonStrategyStep_Click;
|
||||||
|
//
|
||||||
// FormDiselLoko
|
// FormDiselLoko
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(12F, 30F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1371, 900);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(buttonStrategyStep);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(buttonCreateLoko);
|
||||||
Controls.Add(ButtonLeft);
|
Controls.Add(ButtonLeft);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(create);
|
Controls.Add(create);
|
||||||
Controls.Add(pictureBoxDiselLoko);
|
Controls.Add(pictureBoxDiselLoko);
|
||||||
Margin = new Padding(5, 6, 5, 6);
|
|
||||||
Name = "FormDiselLoko";
|
Name = "FormDiselLoko";
|
||||||
Text = "Тепловоз";
|
Text = "Тепловоз";
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxDiselLoko).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxDiselLoko).EndInit();
|
||||||
@ -134,5 +163,8 @@
|
|||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button ButtonLeft;
|
private Button ButtonLeft;
|
||||||
|
private Button buttonCreateLoko;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
namespace PrLaba1
|
using PrLaba1.Drawnings;
|
||||||
|
using PrLaba1.MovementStrategy;
|
||||||
|
|
||||||
|
namespace PrLaba1
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Форма работы с объектом "Тепловоз"
|
/// Форма работы с объектом "Тепловоз"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -8,23 +11,12 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поле-объект для прорисовки объекта
|
/// Поле-объект для прорисовки объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningDiselLoko? _drawningDiselLoko;
|
private DrawningLoko? _drawningLoko;
|
||||||
|
|
||||||
/// <summary>
|
// <summary>
|
||||||
/// Метод прорисовки машины
|
/// Стратегия перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private AbstractStrategy? _strategy;
|
||||||
{
|
|
||||||
if (_drawningDiselLoko == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxDiselLoko.Width, pictureBoxDiselLoko.Height);
|
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
|
||||||
_drawningDiselLoko.DrawTransport(gr);
|
|
||||||
pictureBoxDiselLoko.Image = bmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор формы
|
/// Конструктор формы
|
||||||
@ -32,30 +24,73 @@
|
|||||||
public FormDiselLoko()
|
public FormDiselLoko()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Кнопка создать
|
/// Метод прорисовки машины
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void Draw()
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
if (_drawningLoko == null)
|
||||||
_drawningDiselLoko = new DrawningDiselLoko();
|
{
|
||||||
_drawningDiselLoko.Init(random.Next(100, 300), random.Next(1000, 3000),
|
return;
|
||||||
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)));
|
|
||||||
_drawningDiselLoko.SetPictureSize(pictureBoxDiselLoko.Width, pictureBoxDiselLoko.Height);
|
|
||||||
_drawningDiselLoko.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
|
|
||||||
|
Bitmap bmp = new(pictureBoxDiselLoko.Width, pictureBoxDiselLoko.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawningLoko.DrawTransport(gr);
|
||||||
|
pictureBoxDiselLoko.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningLoko):
|
||||||
|
_drawningLoko = new DrawningLoko(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(DrawningDiselLoko):
|
||||||
|
_drawningLoko = new DrawningDiselLoko(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawningLoko.SetPictureSize(pictureBoxDiselLoko.Width, pictureBoxDiselLoko.Height);
|
||||||
|
_drawningLoko.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
_strategy = null;
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать тепловоз с обвесами"
|
||||||
|
/// </summary>
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDiselLoko));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать тепловоз"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateLoko_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLoko));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Кнопки движения
|
/// Кнопки движения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningDiselLoko == null)
|
if (_drawningLoko == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -65,16 +100,16 @@
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result = _drawningDiselLoko.MoveTransport(Direction.Up);
|
result = _drawningLoko.MoveTransport(Direction.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result = _drawningDiselLoko.MoveTransport(Direction.Down);
|
result = _drawningLoko.MoveTransport(Direction.Down);
|
||||||
break;
|
break;
|
||||||
case "ButtonLeft":
|
case "ButtonLeft":
|
||||||
result = _drawningDiselLoko.MoveTransport(Direction.Left);
|
result = _drawningLoko.MoveTransport(Direction.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result = _drawningDiselLoko.MoveTransport(Direction.Right);
|
result = _drawningLoko.MoveTransport(Direction.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,5 +118,48 @@
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Шаг"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningLoko == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCentre(),
|
||||||
|
1 => new MoveToBoarder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(new MoveableLoko(_drawningLoko), pictureBoxDiselLoko.Width, pictureBoxDiselLoko.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
|
||||||
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,35 +121,34 @@
|
|||||||
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
vwAADr8BOAVTJAAAAKxJREFUSEvdzEsOwjAUQ9Hsf9MgBRU5N+/jQjvpmSV+9njdZvDjOo+fHhN/c+7p
|
vQAADr0BR/uQrQAAAIdJREFUSEvtzFsOgCAMRFH3v2kkcjUFC6U+MCacP+jMLOE1c7rgmF42PDr0RtNu
|
||||||
Z/fUunWnu/56f8TViUeR/oirB95tmgvurXi96uISr1dVzKUIOyLNuJFgTaQZN3JsHuKA7Q77U/J7EvtT
|
wpelK8ekwKHJDjGW49Z0cTriXGckmKkgVPHRNANNRDXVG1ULac3d6YjCiX6g1I1abuw0cSfKQvlF0I++
|
||||||
8Muehyv7NBs27Fw5va9v7z9wCu+f17kSTn+xHWFHlJmBHVFmBnZEmRnYEWVmYEeUmYEdUWYGdkSZGdgR
|
8Nh0xMRu4HRE0ImyoHwdKDUR1czpwpwu/HE6hBWbVcKS8nHq8gAAAABJRU5ErkJggg==
|
||||||
ZWZgR7wBm1XCkmZMrk8AAAAASUVORK5CYII=
|
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
vwAADr8BOAVTJAAAAKZJREFUSEvtzEEOwzAMA8H8/9MtECAFs5ZoKrl2bjZFHp/eEWBH2CzAjrBZgB1h
|
vQAADr0BR/uQrQAAAIVJREFUSEvtzFsKgDAMRFH3v+k6yBXsI22iUkF6PpOZ2ZJtcyDasqYLa7rwm2lK
|
||||||
swA7wmYBdoTNAuwImwXYETYLsCNsFmBHFBnbGa6s02xMcIrvFziF95t17uD9eJor5fSDdfZPze8Q+6f6
|
QZQvyhPBW5g4TZwWgnH0T69NU75onIS4G7Xc9Gmh5EChYj6E6gjpytNpoi29nzBgIGT4blqYqfC2jRPC
|
||||||
d7TO5qUN8nXWLm0QTrMjXLZd5/XdLrZ4fbeJzTrvFvuLbp1Hi/1FOc2LSnSEdWaN9O63zt/e4HTqPw1f
|
WI6f7eY0jy5XSJg8cBrx5iS0K4Fo1JrOpLQD0c/CkunHhukAAAAASUVORK5CYII=
|
||||||
0c/CkmqWjm8AAAAASUVORK5CYII=
|
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
vwAADr8BOAVTJAAAAIRJREFUSEvtzEEKwCAMBVHvf+kWFEuY1BjTuCj4lvoz5dqm8CHPScMkXTp+OFg3
|
vQAADr0BR/uQrQAAAIZJREFUSEvtzUkOgCAMQFHuf2lM4JMgMnSAuOHtbMs3xGNuuvFfOhR8a8zeUC2Y
|
||||||
TzdWtw6Qbjgas6asCpy+4Y0fSwoPVrEncBrDasVRGMOJaV3n90c/TMtuZhrdnDSTHXer2BM49WNJsRaM
|
iinSGTsBdTrjYopTAwJj3JmR6eHCidgbOz96FRZbkCyY7kI1YbQL1YTRFiQLpn70Kiw8KH2wNiPTw4UB
|
||||||
ddwNWDsmK47GrGk42kwOYtEmeOZx0rAxfQP0JcKSXR+eRgAAAABJRU5ErkJggg==
|
gTHLb1mvqNPsBBRppmKLB7ZoZnwmcdONY+kYH/QlwpJxqZGzAAAAAElFTkSuQmCC
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="ButtonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="ButtonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
|
||||||
vwAADr8BOAVTJAAAAIVJREFUSEvtzEkOwCAMBEH+/+lEwiIaGmT2nKgjYzo8xwQ+7HPTMJkOEV9zjblk
|
vQAADr0BR/uQrQAAAJNJREFUSEvt0EEOgCAMBVHuf2k0MBiRr0CLiQvfjraZBSG+5k9ffC8dEh43ptM5
|
||||||
0Q9n4W2AqOGR8DbFZMI74W2GsX4sCZ6OYi/h3QQmt0TNqS7S3Bb9lN5cR3pnneGIR3NYFTwdxV6BH/qx
|
emCqTKSJ1dgpo2lKDdZKP03DgIDChRmZBmsPSics/OgVTJcgmTBahWrCaBWqBdMlSJ6w8KNXY+dETOHC
|
||||||
VMM/gqfC24DViEfC26oOprXOIdeYV9w0HEy/eP/CkookNBkAAAAASUVORK5CYII=
|
jMw97gwIPOJU4UIZSmfEauyUiXRGsmCqTKd3VHufaUkP+tMXr6Vj3AB4/8KSzy1jIwAAAABJRU5ErkJg
|
||||||
|
gg==
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
139
PrLaba1/PrLaba1/MovementStrategy/AbstractStrategy.cs
Normal file
139
PrLaba1/PrLaba1/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
|
||||||
|
namespace PrLaba1.MovementStrategy;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-стратегия перемещения объекта
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещаемый объект
|
||||||
|
/// </summary>
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
public StrategyStatus GetStatus() { return _state; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Установка данных
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||||
|
/// <param name="width">Ширина поля</param>
|
||||||
|
/// <param name="height">Высота поля</param>
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = StrategyStatus.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_state = StrategyStatus.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения
|
||||||
|
/// </summary>
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = StrategyStatus.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение влево
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вправо
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вверх
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вниз
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры объекта
|
||||||
|
/// </summary>
|
||||||
|
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение к цели
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Достигнута ли цель
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Попытка перемещения в требуемом направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="movementDirection">Направление</param>
|
||||||
|
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
private bool MoveTo(MovementDirection movementDirection)
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||||
|
}
|
||||||
|
}
|
23
PrLaba1/PrLaba1/MovementStrategy/IMoveableObject.cs
Normal file
23
PrLaba1/PrLaba1/MovementStrategy/IMoveableObject.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace PrLaba1.MovementStrategy;
|
||||||
|
/// <summary>
|
||||||
|
/// Интерфейс для работы с перемещаемым объектом
|
||||||
|
/// </summary>
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение координаты объекта
|
||||||
|
/// </summary>
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
int GetStep { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Попытка переместить объект в указанном направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||||
|
bool TryMoveObject(MovementDirection direction);
|
||||||
|
}
|
14
PrLaba1/PrLaba1/MovementStrategy/MoveToBoarder.cs
Normal file
14
PrLaba1/PrLaba1/MovementStrategy/MoveToBoarder.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace PrLaba1.MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToBoarder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
53
PrLaba1/PrLaba1/MovementStrategy/MoveToCentre.cs
Normal file
53
PrLaba1/PrLaba1/MovementStrategy/MoveToCentre.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
namespace PrLaba1.MovementStrategy;
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения объекта в центр экрана
|
||||||
|
/// </summary>
|
||||||
|
public class MoveToCentre : 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
PrLaba1/PrLaba1/MovementStrategy/MoveableLoko.cs
Normal file
63
PrLaba1/PrLaba1/MovementStrategy/MoveableLoko.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using PrLaba1.Drawnings;
|
||||||
|
|
||||||
|
namespace PrLaba1.MovementStrategy;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-реализация IMoveableObject с использованием DrawningCar
|
||||||
|
/// </summary>
|
||||||
|
public class MoveableLoko : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поле-объект класса DrawningLoko или его наследника
|
||||||
|
/// </summary>
|
||||||
|
private readonly DrawningLoko? _loko = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="loko">Объект класса DrawningCar</param>
|
||||||
|
public MoveableLoko(DrawningLoko loko)
|
||||||
|
{
|
||||||
|
_loko = loko;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_loko == null || _loko.EntityLoko == null || !_loko.GetPosX.HasValue || !_loko.GetPosY.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_loko.GetPosX.Value, _loko.GetPosY.Value, _loko.GetWidth, _loko.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetStep => (int)(_loko?.EntityLoko?.Step ?? 0);
|
||||||
|
|
||||||
|
public bool TryMoveObject(MovementDirection direction)
|
||||||
|
{
|
||||||
|
if (_loko == null || _loko.EntityLoko == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _loko.MoveTransport(GetDirectionType(direction));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конвертация из MovementDirection в DirectionType
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">MovementDirection</param>
|
||||||
|
/// <returns>DirectionType</returns>
|
||||||
|
private static Direction GetDirectionType(MovementDirection direction)
|
||||||
|
{
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
MovementDirection.Left => Direction.Left,
|
||||||
|
MovementDirection.Right => Direction.Right,
|
||||||
|
MovementDirection.Up => Direction.Up,
|
||||||
|
MovementDirection.Down => Direction.Down,
|
||||||
|
_ => Direction.Unknow,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
26
PrLaba1/PrLaba1/MovementStrategy/MovementDirection.cs
Normal file
26
PrLaba1/PrLaba1/MovementStrategy/MovementDirection.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
namespace PrLaba1.MovementStrategy;
|
||||||
|
/// <summary>
|
||||||
|
/// Направление перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum MovementDirection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
72
PrLaba1/PrLaba1/MovementStrategy/ObjectParameters.cs
Normal file
72
PrLaba1/PrLaba1/MovementStrategy/ObjectParameters.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
namespace PrLaba1.MovementStrategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры-координаты объекта
|
||||||
|
/// </summary>
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Координата X
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _x;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Y
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _y;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _width;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _height;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Левая граница
|
||||||
|
/// </summary>
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int TopBorder => _y;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Правая граница
|
||||||
|
/// </summary>
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Нижняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
/// <param name="width">Ширина объекта</param>
|
||||||
|
/// <param name="height">Высота объекта</param>
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
22
PrLaba1/PrLaba1/MovementStrategy/StrategyStatus.cs
Normal file
22
PrLaba1/PrLaba1/MovementStrategy/StrategyStatus.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
namespace PrLaba1.MovementStrategy;
|
||||||
|
/// <summary>
|
||||||
|
/// Статус выполнения операции перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum StrategyStatus
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Все готово к началу
|
||||||
|
/// </summary>
|
||||||
|
NotInit,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выполняется
|
||||||
|
/// </summary>
|
||||||
|
InProgress,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Завершено
|
||||||
|
/// </summary>
|
||||||
|
Finish
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user