Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4d599ac689 | ||
|
f69bc78105 | ||
|
a8b0acd1f8 | ||
|
ba9a4d66ce | ||
|
656f12f9a9 | ||
|
fcf35359c7 | ||
|
17c57e7c37 |
141
ProjectMonorail/ProjectMonorail/AbstractStrategy.cs
Normal file
141
ProjectMonorail/ProjectMonorail/AbstractStrategy.cs
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
namespace ProjectMonorail.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-стратегия перемещения объекта
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещаемый объект
|
||||||
|
/// </summary>
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота поля
|
||||||
|
/// </summary>
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статус перемещения
|
||||||
|
/// </summary>
|
||||||
|
public Status GetStatus() { return _state; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Установка данных
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||||
|
/// <param name="width">Ширина поля</param>
|
||||||
|
/// <param name="height">Высота поля</param>
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||||
|
{
|
||||||
|
if (moveableObject == null)
|
||||||
|
{
|
||||||
|
_state = Status.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = Status.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения
|
||||||
|
/// </summary>
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение влево
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вправо
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вверх
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение вниз
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры объекта
|
||||||
|
/// </summary>
|
||||||
|
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение к цели
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Достигнута ли цель
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected abstract bool IsTargetDestinaion();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Попытка перемещения в требуемом направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="directionType">Направление</param>
|
||||||
|
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||||
|
private bool MoveTo(DirectionType directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
ProjectMonorail/ProjectMonorail/DirectionType.cs
Normal file
28
ProjectMonorail/ProjectMonorail/DirectionType.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
namespace ProjectMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Направление перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum DirectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
||||||
|
}
|
99
ProjectMonorail/ProjectMonorail/DrawingExtendedMonorail.cs
Normal file
99
ProjectMonorail/ProjectMonorail/DrawingExtendedMonorail.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using ProjectMonorail.Entities;
|
||||||
|
|
||||||
|
namespace ProjectMonorail.DrawingObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawingExtendedMonorail : DrawingMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="mainColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="magneticRail">Признак наличия магнитной рельсы</param>
|
||||||
|
/// <param name="extraCabin">Признак наличия дополнительной кабины</param>
|
||||||
|
/// <param name="width">Ширина картинки</param>
|
||||||
|
/// <param name="height">Высота картинки</param>
|
||||||
|
public DrawingExtendedMonorail(int speed, double weight, Color mainColor, Color additionalColor, bool magneticRail,
|
||||||
|
bool extraCabin, int width, int height) : base(speed, weight, mainColor, width, height, 186, 92)
|
||||||
|
{
|
||||||
|
if (!magneticRail && !extraCabin)
|
||||||
|
{
|
||||||
|
_monorailWidth = 117;
|
||||||
|
_monorailHeight = 56;
|
||||||
|
}
|
||||||
|
if (!magneticRail && extraCabin)
|
||||||
|
{
|
||||||
|
_monorailWidth = 183;
|
||||||
|
_monorailHeight = 56;
|
||||||
|
}
|
||||||
|
if (EntityMonorail != null)
|
||||||
|
{
|
||||||
|
EntityMonorail = new EntityExtendedMonorail(speed, weight, mainColor,
|
||||||
|
additionalColor, magneticRail, extraCabin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityMonorail is not EntityExtendedMonorail extendedMonorail)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen mainPen = new Pen(Color.Black, 2);
|
||||||
|
Pen additionalPen = new(Color.Blue);
|
||||||
|
Brush additionalBrush = new SolidBrush(extendedMonorail.AdditionalColor);
|
||||||
|
Brush brBlue = new SolidBrush(Color.Blue);
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
Brush brWhite = new SolidBrush(Color.White);
|
||||||
|
Brush brGray = new SolidBrush(Color.Gray);
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
//магнитная рельса
|
||||||
|
if (extendedMonorail.MagneticRail)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 2, _startPosY + 58, 184, 18);
|
||||||
|
g.FillRectangle(brGray, _startPosX + 2, _startPosY + 58, 184, 18);
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 35 + 35 * i, _startPosY + 77, 8, 15);
|
||||||
|
g.FillRectangle(brGray, _startPosX + 35 + 35 * i, _startPosY + 77, 8, 15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//дополнительная кабина
|
||||||
|
if (extendedMonorail.ExtraCabin)
|
||||||
|
{
|
||||||
|
//корпус дополнительной кабины
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX + 118, _startPosY + 15, 65, 31);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 118, _startPosY + 15, 65, 31);
|
||||||
|
g.DrawLine(additionalPen, _startPosX + 118, _startPosY + 31, _startPosX + 183, _startPosY + 31);
|
||||||
|
|
||||||
|
//дверь дополнительной кабины
|
||||||
|
g.FillRectangle(brBlue, _startPosX + 146, _startPosY + 21, 7, 20);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 146, _startPosY + 21, 7, 20);
|
||||||
|
|
||||||
|
//окна дополнительной кабины
|
||||||
|
g.FillRectangle(brBlue, _startPosX + 130, _startPosY + 18, 6, 9);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 130, _startPosY + 18, 6, 9);
|
||||||
|
g.FillRectangle(brBlue, _startPosX + 169, _startPosY + 18, 6, 9);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 169, _startPosY + 18, 6, 9);
|
||||||
|
|
||||||
|
//колеса и тележка дополнительной кабины
|
||||||
|
g.FillRectangle(brBlack, _startPosX + 126, _startPosY + 47, 15, 6);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 126, _startPosY + 47, 15, 6);
|
||||||
|
g.FillRectangle(brBlack, _startPosX + 159, _startPosY + 47, 15, 6);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 159, _startPosY + 47, 15, 6);
|
||||||
|
g.FillEllipse(brWhite, _startPosX + 128, _startPosY + 47, 10, 9);
|
||||||
|
g.DrawEllipse(mainPen, _startPosX + 128, _startPosY + 47, 10, 9);
|
||||||
|
g.FillEllipse(brWhite, _startPosX + 161, _startPosY + 47, 10, 9);
|
||||||
|
g.DrawEllipse(mainPen, _startPosX + 161, _startPosY + 47, 10, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
253
ProjectMonorail/ProjectMonorail/DrawingMonorail.cs
Normal file
253
ProjectMonorail/ProjectMonorail/DrawingMonorail.cs
Normal file
@ -0,0 +1,253 @@
|
|||||||
|
using ProjectMonorail.Entities;
|
||||||
|
using ProjectMonorail.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectMonorail.DrawingObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawingMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность
|
||||||
|
/// </summary>
|
||||||
|
public EntityMonorail? EntityMonorail { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
private int _pictureWidth;
|
||||||
|
|
||||||
|
public int PictureWidth
|
||||||
|
{
|
||||||
|
set { _pictureWidth = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
private int _pictureHeight;
|
||||||
|
|
||||||
|
public int PictureHeight
|
||||||
|
{
|
||||||
|
set { _pictureHeight = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Левая координата прорисовки монорельса
|
||||||
|
/// </summary>
|
||||||
|
protected int _startPosX;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя координата прорисовки монорельса
|
||||||
|
/// </summary>
|
||||||
|
protected int _startPosY;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина прорисовки монорельса
|
||||||
|
/// </summary>
|
||||||
|
protected int _monorailWidth = 117;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота прорисовки монорельса
|
||||||
|
/// </summary>
|
||||||
|
protected int _monorailHeight = 56;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Координата X объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Координата Y объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetWidth => _monorailWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота объекта
|
||||||
|
/// </summary>
|
||||||
|
public int GetHeight => _monorailHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject из объекта DrawingMonorail
|
||||||
|
/// </summary>
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawingObjectMonorail(this);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="mainColor">Основной цвет</param>
|
||||||
|
/// <param name="width">Ширина картинки</param>
|
||||||
|
/// <param name="height">Высота картинки</param>
|
||||||
|
public DrawingMonorail(int speed, double weight, Color mainColor, int width, int height)
|
||||||
|
{
|
||||||
|
if (width < _monorailWidth || height < _monorailHeight) { return; }
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityMonorail = new EntityMonorail(speed, weight, mainColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="mainColor">Основной цвет</param>
|
||||||
|
/// <param name="width">Ширина картинки</param>
|
||||||
|
/// <param name="height">Высота картинки</param>
|
||||||
|
/// <param name="monorailWidth">Ширина прорисовки монорельса</param>
|
||||||
|
/// <param name="monorailHeight">Высота прорисовки монорельса</param>
|
||||||
|
protected DrawingMonorail(int speed, double weight, Color mainColor, int width,
|
||||||
|
int height, int monorailWidth, int monorailHeight)
|
||||||
|
{
|
||||||
|
if (width < monorailWidth || height < monorailHeight) { return; }
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_monorailWidth = monorailWidth;
|
||||||
|
_monorailHeight = monorailHeight;
|
||||||
|
EntityMonorail = new EntityMonorail(speed, weight, mainColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Установка позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (x < 0 || x + _monorailWidth > _pictureWidth) { x = 0; }
|
||||||
|
if (y < 0 || y + _monorailHeight > _pictureHeight) { y = 0; }
|
||||||
|
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка, что объект может переместится по указанному направлению
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||||
|
public bool CanMove(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityMonorail == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
DirectionType.Left => _startPosX - EntityMonorail.Step > 0,
|
||||||
|
//вверх
|
||||||
|
DirectionType.Up => _startPosY - EntityMonorail.Step > 0,
|
||||||
|
//вправо
|
||||||
|
DirectionType.Right => _startPosX + _monorailWidth + EntityMonorail.Step < _pictureWidth,
|
||||||
|
//вниз
|
||||||
|
DirectionType.Down => _startPosY + _monorailHeight + EntityMonorail.Step < _pictureHeight,
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
public void MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityMonorail == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case DirectionType.Left:
|
||||||
|
_startPosX -= (int)EntityMonorail.Step;
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case DirectionType.Up:
|
||||||
|
_startPosY -= (int)EntityMonorail.Step;
|
||||||
|
break;
|
||||||
|
//вправо
|
||||||
|
case DirectionType.Right:
|
||||||
|
_startPosX += (int)EntityMonorail.Step;
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case DirectionType.Down:
|
||||||
|
_startPosY += (int)EntityMonorail.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
public virtual void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityMonorail == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen mainPen = new Pen(Color.Black, 2);
|
||||||
|
Pen additionalPen = new(Color.Blue);
|
||||||
|
Brush mainBrush = new SolidBrush(EntityMonorail.MainColor);
|
||||||
|
Brush brBlue = new SolidBrush(Color.Blue);
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
Brush brWhite = new SolidBrush(Color.White);
|
||||||
|
Brush brGray = new SolidBrush(Color.Gray);
|
||||||
|
|
||||||
|
//надстройка
|
||||||
|
g.FillRectangle(mainBrush, _startPosX + 55, _startPosY, 25, 15);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 55, _startPosY, 25, 15);
|
||||||
|
|
||||||
|
//корпус локомотива
|
||||||
|
Point[] locoPoints = { new Point(_startPosX + 29, _startPosY + 15), new Point(_startPosX + 112, _startPosY + 15),
|
||||||
|
new Point(_startPosX + 112, _startPosY + 46), new Point(_startPosX + 25, _startPosY + 46), new Point(_startPosX + 25, _startPosY + 31) };
|
||||||
|
g.FillPolygon(mainBrush, locoPoints);
|
||||||
|
g.DrawPolygon(mainPen, locoPoints);
|
||||||
|
g.DrawLine(additionalPen, _startPosX + 25, _startPosY + 31, _startPosX + 112, _startPosY + 31);
|
||||||
|
|
||||||
|
//дверь локомотива
|
||||||
|
g.FillRectangle(brGray, _startPosX + 54, _startPosY + 21, 7, 20);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 54, _startPosY + 21, 7, 20);
|
||||||
|
|
||||||
|
//окна локомотива
|
||||||
|
g.FillRectangle(brBlue, _startPosX + 32, _startPosY + 18, 6, 9);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 32, _startPosY + 18, 6, 9);
|
||||||
|
g.FillRectangle(brBlue, _startPosX + 44, _startPosY + 18, 6, 9);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 44, _startPosY + 18, 6, 9);
|
||||||
|
g.FillRectangle(brBlue, _startPosX + 103, _startPosY + 18, 6, 9);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 103, _startPosY + 18, 6, 9);
|
||||||
|
|
||||||
|
//колеса и тележка локомотива
|
||||||
|
g.FillRectangle(brBlack, _startPosX + 23, _startPosY + 47, 33, 6);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 23, _startPosY + 47, 33, 6);
|
||||||
|
g.FillRectangle(brBlack, _startPosX + 76, _startPosY + 47, 30, 6);
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 76, _startPosY + 47, 30, 6);
|
||||||
|
g.FillEllipse(brWhite, _startPosX + 25, _startPosY + 47, 10, 9);
|
||||||
|
g.DrawEllipse(mainPen, _startPosX + 25, _startPosY + 47, 10, 9);
|
||||||
|
g.FillEllipse(brWhite, _startPosX + 45, _startPosY + 47, 10, 9);
|
||||||
|
g.DrawEllipse(mainPen, _startPosX + 45, _startPosY + 47, 10, 9);
|
||||||
|
g.FillEllipse(brWhite, _startPosX + 75, _startPosY + 47, 10, 9);
|
||||||
|
g.DrawEllipse(mainPen, _startPosX + 75, _startPosY + 47, 10, 9);
|
||||||
|
g.FillEllipse(brWhite, _startPosX + 95, _startPosY + 47, 10, 9);
|
||||||
|
g.DrawEllipse(mainPen, _startPosX + 95, _startPosY + 47, 10, 9);
|
||||||
|
Point[] bogiePoints = { new Point(_startPosX + 26, _startPosY + 46), new Point(_startPosX + 24, _startPosY + 54),
|
||||||
|
new Point(_startPosX + 12, _startPosY + 54), new Point(_startPosX + 8, _startPosY + 51), new Point(_startPosX + 12, _startPosY + 48),
|
||||||
|
new Point(_startPosX + 18, _startPosY + 46) };
|
||||||
|
g.FillPolygon(brBlack, bogiePoints);
|
||||||
|
|
||||||
|
//соединение между кабинами
|
||||||
|
g.DrawRectangle(mainPen, _startPosX + 112, _startPosY + 18, 5, 28);
|
||||||
|
g.FillRectangle(brBlack, _startPosX + 112, _startPosY + 18, 5, 28);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
ProjectMonorail/ProjectMonorail/DrawingObjectMonorail.cs
Normal file
38
ProjectMonorail/ProjectMonorail/DrawingObjectMonorail.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using ProjectMonorail.DrawingObjects;
|
||||||
|
|
||||||
|
namespace ProjectMonorail.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация интерфейса IMoveableObject для работы с объектом DrawingMonorail (паттерн Adapter)
|
||||||
|
/// </summary>
|
||||||
|
public class DrawingObjectMonorail : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawingMonorail? _drawingMonorail = null;
|
||||||
|
|
||||||
|
public DrawingObjectMonorail(DrawingMonorail drawingMonorail)
|
||||||
|
{
|
||||||
|
_drawingMonorail = drawingMonorail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawingMonorail == null || _drawingMonorail.EntityMonorail == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawingMonorail.GetPosX, _drawingMonorail.GetPosY,
|
||||||
|
_drawingMonorail.GetWidth, _drawingMonorail.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetStep => (int)(_drawingMonorail?.EntityMonorail?.Step ?? 0);
|
||||||
|
|
||||||
|
public bool CheckCanMove(DirectionType direction) =>
|
||||||
|
_drawingMonorail?.CanMove(direction) ?? false;
|
||||||
|
|
||||||
|
public void MoveObject(DirectionType direction) =>
|
||||||
|
_drawingMonorail?.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
40
ProjectMonorail/ProjectMonorail/EntityExtendedMonorail.cs
Normal file
40
ProjectMonorail/ProjectMonorail/EntityExtendedMonorail.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
namespace ProjectMonorail.Entities
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Расширенный монорельс"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityExtendedMonorail : EntityMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
|
/// </summary>
|
||||||
|
public Color AdditionalColor { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличия магнитной рельсы
|
||||||
|
/// </summary>
|
||||||
|
public bool MagneticRail { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличия дополнительной кабины
|
||||||
|
/// </summary>
|
||||||
|
public bool ExtraCabin { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация полей объекта-класса расширенного монорельса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес монорельса</param>
|
||||||
|
/// <param name="mainColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="magneticRail">Признак наличия магнитной рельсы</param>
|
||||||
|
/// <param name="extraCabin">Признак наличия дополнительной кабины</param>
|
||||||
|
public EntityExtendedMonorail(int speed, double weight, Color mainColor, Color
|
||||||
|
additionalColor, bool magneticRail, bool extraCabin) : base(speed, weight, mainColor)
|
||||||
|
{
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
MagneticRail = magneticRail;
|
||||||
|
ExtraCabin = extraCabin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
ProjectMonorail/ProjectMonorail/EntityMonorail.cs
Normal file
42
ProjectMonorail/ProjectMonorail/EntityMonorail.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
namespace ProjectMonorail.Entities
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Монорельс"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Основной цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color MainColor { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения монорельса
|
||||||
|
/// </summary>
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор с параметрами
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес монорельса</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public EntityMonorail(int speed, double weight, Color mainColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
MainColor = mainColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
61
ProjectMonorail/ProjectMonorail/ExtentionDrawingMonorail.cs
Normal file
61
ProjectMonorail/ProjectMonorail/ExtentionDrawingMonorail.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using ProjectMonorail.DrawingObjects;
|
||||||
|
using ProjectMonorail.Entities;
|
||||||
|
|
||||||
|
namespace ProjectMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Расширение для класса EntityMonorail
|
||||||
|
/// </summary>
|
||||||
|
public static class ExtentionDrawingMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">Строка с данными для создания объекта</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <param name="width">Ширина</param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
public static DrawingMonorail? CreateDrawingMonorail(this string info, char separatorForObject, int width, int height)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawingMonorail(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawingExtendedMonorail(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]),
|
||||||
|
width, height);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawingMonorail">Сохраняемый объект</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
public static string GetDataForSave(this DrawingMonorail drawingMonorail, char separatorForObject)
|
||||||
|
{
|
||||||
|
var monorail = drawingMonorail.EntityMonorail;
|
||||||
|
if (monorail == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
var str = $"{monorail.Speed}{separatorForObject}{monorail.Weight}{separatorForObject}{monorail.MainColor.Name}";
|
||||||
|
if (monorail is not EntityExtendedMonorail extendedMonorail)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return $"{str}{separatorForObject}{extendedMonorail.AdditionalColor.Name}{separatorForObject}{extendedMonorail.MagneticRail}{separatorForObject}{extendedMonorail.ExtraCabin}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
ProjectMonorail/ProjectMonorail/Form1.Designer.cs
generated
39
ProjectMonorail/ProjectMonorail/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace ProjectMonorail
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace ProjectMonorail
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
193
ProjectMonorail/ProjectMonorail/FormMonorail.Designer.cs
generated
Normal file
193
ProjectMonorail/ProjectMonorail/FormMonorail.Designer.cs
generated
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
namespace ProjectMonorail
|
||||||
|
{
|
||||||
|
partial class FormMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
pictureBoxMonorail = new PictureBox();
|
||||||
|
buttonCreateExtendedMonorail = new Button();
|
||||||
|
buttonLeft = new Button();
|
||||||
|
buttonDown = new Button();
|
||||||
|
buttonRight = new Button();
|
||||||
|
buttonUp = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonCreateMonorail = new Button();
|
||||||
|
buttonStep = new Button();
|
||||||
|
buttonSelectMonorail = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxMonorail
|
||||||
|
//
|
||||||
|
pictureBoxMonorail.Dock = DockStyle.Fill;
|
||||||
|
pictureBoxMonorail.Location = new Point(0, 0);
|
||||||
|
pictureBoxMonorail.Name = "pictureBoxMonorail";
|
||||||
|
pictureBoxMonorail.Size = new Size(884, 545);
|
||||||
|
pictureBoxMonorail.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBoxMonorail.TabIndex = 0;
|
||||||
|
pictureBoxMonorail.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonCreateExtendedMonorail
|
||||||
|
//
|
||||||
|
buttonCreateExtendedMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateExtendedMonorail.Location = new Point(12, 487);
|
||||||
|
buttonCreateExtendedMonorail.Name = "buttonCreateExtendedMonorail";
|
||||||
|
buttonCreateExtendedMonorail.Size = new Size(140, 39);
|
||||||
|
buttonCreateExtendedMonorail.TabIndex = 1;
|
||||||
|
buttonCreateExtendedMonorail.Text = "Create extended monorail";
|
||||||
|
buttonCreateExtendedMonorail.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateExtendedMonorail.Click += buttonCreateExtendedMonorail_Click;
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||||
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonLeft.Location = new Point(770, 503);
|
||||||
|
buttonLeft.Name = "buttonLeft";
|
||||||
|
buttonLeft.Size = new Size(30, 30);
|
||||||
|
buttonLeft.TabIndex = 2;
|
||||||
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||||
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonDown.Location = new Point(806, 503);
|
||||||
|
buttonDown.Name = "buttonDown";
|
||||||
|
buttonDown.Size = new Size(30, 30);
|
||||||
|
buttonDown.TabIndex = 3;
|
||||||
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||||
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonRight.Location = new Point(842, 503);
|
||||||
|
buttonRight.Name = "buttonRight";
|
||||||
|
buttonRight.Size = new Size(30, 30);
|
||||||
|
buttonRight.TabIndex = 4;
|
||||||
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||||
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonUp.Location = new Point(806, 467);
|
||||||
|
buttonUp.Name = "buttonUp";
|
||||||
|
buttonUp.Size = new Size(30, 30);
|
||||||
|
buttonUp.TabIndex = 5;
|
||||||
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += buttonMove_Click;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "Form center", "Form border" });
|
||||||
|
comboBoxStrategy.Location = new Point(751, 12);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(121, 23);
|
||||||
|
comboBoxStrategy.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// buttonCreateMonorail
|
||||||
|
//
|
||||||
|
buttonCreateMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateMonorail.Location = new Point(168, 487);
|
||||||
|
buttonCreateMonorail.Name = "buttonCreateMonorail";
|
||||||
|
buttonCreateMonorail.Size = new Size(140, 39);
|
||||||
|
buttonCreateMonorail.TabIndex = 7;
|
||||||
|
buttonCreateMonorail.Text = "Create monorail";
|
||||||
|
buttonCreateMonorail.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateMonorail.Click += buttonCreateMonorail_Click;
|
||||||
|
//
|
||||||
|
// buttonStep
|
||||||
|
//
|
||||||
|
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
buttonStep.Location = new Point(797, 50);
|
||||||
|
buttonStep.Name = "buttonStep";
|
||||||
|
buttonStep.Size = new Size(75, 28);
|
||||||
|
buttonStep.TabIndex = 8;
|
||||||
|
buttonStep.Text = "Step";
|
||||||
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
|
buttonStep.Click += buttonStep_Click;
|
||||||
|
//
|
||||||
|
// buttonSelectMonorail
|
||||||
|
//
|
||||||
|
buttonSelectMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonSelectMonorail.Location = new Point(324, 487);
|
||||||
|
buttonSelectMonorail.Name = "buttonSelectMonorail";
|
||||||
|
buttonSelectMonorail.Size = new Size(140, 39);
|
||||||
|
buttonSelectMonorail.TabIndex = 9;
|
||||||
|
buttonSelectMonorail.Text = "Select";
|
||||||
|
buttonSelectMonorail.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectMonorail.Click += buttonSelectMonorail_Click;
|
||||||
|
//
|
||||||
|
// FormMonorail
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(884, 545);
|
||||||
|
Controls.Add(buttonSelectMonorail);
|
||||||
|
Controls.Add(buttonStep);
|
||||||
|
Controls.Add(buttonCreateMonorail);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(buttonUp);
|
||||||
|
Controls.Add(buttonRight);
|
||||||
|
Controls.Add(buttonDown);
|
||||||
|
Controls.Add(buttonLeft);
|
||||||
|
Controls.Add(buttonCreateExtendedMonorail);
|
||||||
|
Controls.Add(pictureBoxMonorail);
|
||||||
|
Name = "FormMonorail";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Monorail";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxMonorail;
|
||||||
|
private Button buttonCreateExtendedMonorail;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonUp;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonCreateMonorail;
|
||||||
|
private Button buttonStep;
|
||||||
|
private Button buttonSelectMonorail;
|
||||||
|
}
|
||||||
|
}
|
179
ProjectMonorail/ProjectMonorail/FormMonorail.cs
Normal file
179
ProjectMonorail/ProjectMonorail/FormMonorail.cs
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
using ProjectMonorail.DrawingObjects;
|
||||||
|
using ProjectMonorail.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма работы с объектом "Монорельс"
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormMonorail : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поле-объект для прорисовки объекта
|
||||||
|
/// </summary>
|
||||||
|
private DrawingMonorail? _drawingMonorail;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выбранный монорельс
|
||||||
|
/// </summary>
|
||||||
|
public DrawingMonorail? SelectedMonorail { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация формы
|
||||||
|
/// </summary>
|
||||||
|
public FormMonorail()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
|
SelectedMonorail = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки транспорта
|
||||||
|
/// </summary>
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawingMonorail == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawingMonorail.DrawTransport(gr);
|
||||||
|
pictureBoxMonorail.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать расширенный монорельс"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateExtendedMonorail_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog additionalDialog = new();
|
||||||
|
if (additionalDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
additionalColor = additionalDialog.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawingMonorail = new DrawingExtendedMonorail(random.Next(200, 400), random.Next(1000, 3000), color, additionalColor,
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
||||||
|
_drawingMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать монорельс"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateMonorail_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawingMonorail = new DrawingMonorail(random.Next(200, 400), random.Next(1000, 3000), color, pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
||||||
|
_drawingMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение положения монорельса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingMonorail == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawingMonorail.MoveTransport(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawingMonorail.MoveTransport(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawingMonorail.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawingMonorail.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Шаг"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonStep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingMonorail == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_strategy = comboBoxStrategy.SelectedIndex
|
||||||
|
switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(new DrawingObjectMonorail(_drawingMonorail), pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
||||||
|
}
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_strategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор монорельса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSelectMonorail_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedMonorail = _drawingMonorail;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
298
ProjectMonorail/ProjectMonorail/FormMonorailCollection.Designer.cs
generated
Normal file
298
ProjectMonorail/ProjectMonorail/FormMonorailCollection.Designer.cs
generated
Normal file
@ -0,0 +1,298 @@
|
|||||||
|
namespace ProjectMonorail
|
||||||
|
{
|
||||||
|
partial class FormMonorailCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
panelTools = new Panel();
|
||||||
|
panelSets = new Panel();
|
||||||
|
textBoxNameSet = new TextBox();
|
||||||
|
buttonAddSet = new Button();
|
||||||
|
ButtonDelSet = new Button();
|
||||||
|
listBoxSets = new ListBox();
|
||||||
|
labelSetsName = new Label();
|
||||||
|
buttonRefreshCollection = new Button();
|
||||||
|
labelToolsName = new Label();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
buttonRemoveMonorail = new Button();
|
||||||
|
buttonAddMonorail = new Button();
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
menuStripFile = new MenuStrip();
|
||||||
|
fileToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
saveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
panelTools.SuspendLayout();
|
||||||
|
panelSets.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
menuStripFile.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// panelTools
|
||||||
|
//
|
||||||
|
panelTools.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
panelTools.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
panelTools.Controls.Add(panelSets);
|
||||||
|
panelTools.Controls.Add(buttonRefreshCollection);
|
||||||
|
panelTools.Controls.Add(labelToolsName);
|
||||||
|
panelTools.Controls.Add(maskedTextBoxNumber);
|
||||||
|
panelTools.Controls.Add(buttonRemoveMonorail);
|
||||||
|
panelTools.Controls.Add(buttonAddMonorail);
|
||||||
|
panelTools.Location = new Point(784, 38);
|
||||||
|
panelTools.Name = "panelTools";
|
||||||
|
panelTools.Size = new Size(187, 580);
|
||||||
|
panelTools.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// panelSets
|
||||||
|
//
|
||||||
|
panelSets.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
panelSets.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
panelSets.Controls.Add(textBoxNameSet);
|
||||||
|
panelSets.Controls.Add(buttonAddSet);
|
||||||
|
panelSets.Controls.Add(ButtonDelSet);
|
||||||
|
panelSets.Controls.Add(listBoxSets);
|
||||||
|
panelSets.Controls.Add(labelSetsName);
|
||||||
|
panelSets.Location = new Point(11, 45);
|
||||||
|
panelSets.Name = "panelSets";
|
||||||
|
panelSets.Size = new Size(163, 292);
|
||||||
|
panelSets.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// textBoxNameSet
|
||||||
|
//
|
||||||
|
textBoxNameSet.Location = new Point(7, 40);
|
||||||
|
textBoxNameSet.Name = "textBoxNameSet";
|
||||||
|
textBoxNameSet.Size = new Size(145, 23);
|
||||||
|
textBoxNameSet.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// buttonAddSet
|
||||||
|
//
|
||||||
|
buttonAddSet.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
buttonAddSet.BackColor = SystemColors.Window;
|
||||||
|
buttonAddSet.FlatAppearance.BorderColor = Color.Black;
|
||||||
|
buttonAddSet.FlatStyle = FlatStyle.Flat;
|
||||||
|
buttonAddSet.Location = new Point(7, 80);
|
||||||
|
buttonAddSet.Name = "buttonAddSet";
|
||||||
|
buttonAddSet.Size = new Size(145, 34);
|
||||||
|
buttonAddSet.TabIndex = 7;
|
||||||
|
buttonAddSet.Text = "Add set";
|
||||||
|
buttonAddSet.UseVisualStyleBackColor = false;
|
||||||
|
buttonAddSet.Click += buttonAddSet_Click;
|
||||||
|
//
|
||||||
|
// ButtonDelSet
|
||||||
|
//
|
||||||
|
ButtonDelSet.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
ButtonDelSet.BackColor = SystemColors.Window;
|
||||||
|
ButtonDelSet.FlatAppearance.BorderColor = Color.Black;
|
||||||
|
ButtonDelSet.FlatStyle = FlatStyle.Flat;
|
||||||
|
ButtonDelSet.Location = new Point(7, 244);
|
||||||
|
ButtonDelSet.Name = "ButtonDelSet";
|
||||||
|
ButtonDelSet.Size = new Size(145, 34);
|
||||||
|
ButtonDelSet.TabIndex = 5;
|
||||||
|
ButtonDelSet.Text = "Remove set";
|
||||||
|
ButtonDelSet.UseVisualStyleBackColor = false;
|
||||||
|
ButtonDelSet.Click += ButtonDelSet_Click;
|
||||||
|
//
|
||||||
|
// listBoxSets
|
||||||
|
//
|
||||||
|
listBoxSets.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
listBoxSets.FormattingEnabled = true;
|
||||||
|
listBoxSets.ItemHeight = 15;
|
||||||
|
listBoxSets.Location = new Point(7, 133);
|
||||||
|
listBoxSets.Name = "listBoxSets";
|
||||||
|
listBoxSets.Size = new Size(145, 94);
|
||||||
|
listBoxSets.TabIndex = 6;
|
||||||
|
listBoxSets.SelectedIndexChanged += listBoxSets_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// labelSetsName
|
||||||
|
//
|
||||||
|
labelSetsName.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
labelSetsName.AutoSize = true;
|
||||||
|
labelSetsName.Font = new Font("Segoe UI Semibold", 12F, FontStyle.Bold, GraphicsUnit.Point);
|
||||||
|
labelSetsName.Location = new Point(7, 6);
|
||||||
|
labelSetsName.Name = "labelSetsName";
|
||||||
|
labelSetsName.Size = new Size(41, 21);
|
||||||
|
labelSetsName.TabIndex = 5;
|
||||||
|
labelSetsName.Text = "Sets";
|
||||||
|
//
|
||||||
|
// buttonRefreshCollection
|
||||||
|
//
|
||||||
|
buttonRefreshCollection.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRefreshCollection.BackColor = SystemColors.Window;
|
||||||
|
buttonRefreshCollection.FlatAppearance.BorderColor = Color.Black;
|
||||||
|
buttonRefreshCollection.FlatStyle = FlatStyle.Flat;
|
||||||
|
buttonRefreshCollection.Location = new Point(5, 534);
|
||||||
|
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
|
buttonRefreshCollection.Size = new Size(175, 34);
|
||||||
|
buttonRefreshCollection.TabIndex = 3;
|
||||||
|
buttonRefreshCollection.Text = "Refresh collection";
|
||||||
|
buttonRefreshCollection.UseVisualStyleBackColor = false;
|
||||||
|
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// labelToolsName
|
||||||
|
//
|
||||||
|
labelToolsName.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
labelToolsName.AutoSize = true;
|
||||||
|
labelToolsName.Font = new Font("Segoe UI Semibold", 12F, FontStyle.Bold, GraphicsUnit.Point);
|
||||||
|
labelToolsName.Location = new Point(18, 9);
|
||||||
|
labelToolsName.Name = "labelToolsName";
|
||||||
|
labelToolsName.Size = new Size(48, 21);
|
||||||
|
labelToolsName.TabIndex = 0;
|
||||||
|
labelToolsName.Text = "Tools";
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
maskedTextBoxNumber.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
maskedTextBoxNumber.Location = new Point(4, 411);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(175, 23);
|
||||||
|
maskedTextBoxNumber.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// buttonRemoveMonorail
|
||||||
|
//
|
||||||
|
buttonRemoveMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRemoveMonorail.BackColor = SystemColors.Window;
|
||||||
|
buttonRemoveMonorail.FlatAppearance.BorderColor = Color.Black;
|
||||||
|
buttonRemoveMonorail.FlatStyle = FlatStyle.Flat;
|
||||||
|
buttonRemoveMonorail.Location = new Point(4, 451);
|
||||||
|
buttonRemoveMonorail.Name = "buttonRemoveMonorail";
|
||||||
|
buttonRemoveMonorail.Size = new Size(175, 34);
|
||||||
|
buttonRemoveMonorail.TabIndex = 1;
|
||||||
|
buttonRemoveMonorail.Text = "Remove monorail";
|
||||||
|
buttonRemoveMonorail.UseVisualStyleBackColor = false;
|
||||||
|
buttonRemoveMonorail.Click += buttonRemoveMonorail_Click;
|
||||||
|
//
|
||||||
|
// buttonAddMonorail
|
||||||
|
//
|
||||||
|
buttonAddMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonAddMonorail.BackColor = SystemColors.Window;
|
||||||
|
buttonAddMonorail.FlatAppearance.BorderColor = Color.Black;
|
||||||
|
buttonAddMonorail.FlatStyle = FlatStyle.Flat;
|
||||||
|
buttonAddMonorail.Location = new Point(4, 357);
|
||||||
|
buttonAddMonorail.Name = "buttonAddMonorail";
|
||||||
|
buttonAddMonorail.Size = new Size(175, 34);
|
||||||
|
buttonAddMonorail.TabIndex = 0;
|
||||||
|
buttonAddMonorail.Text = "Add monorail";
|
||||||
|
buttonAddMonorail.UseVisualStyleBackColor = false;
|
||||||
|
buttonAddMonorail.Click += buttonAddMonorail_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(8, 38);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(774, 580);
|
||||||
|
pictureBoxCollection.TabIndex = 1;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// menuStripFile
|
||||||
|
//
|
||||||
|
menuStripFile.Dock = DockStyle.None;
|
||||||
|
menuStripFile.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
|
||||||
|
menuStripFile.Location = new Point(0, 4);
|
||||||
|
menuStripFile.Name = "menuStripFile";
|
||||||
|
menuStripFile.Padding = new Padding(3, 2, 0, 2);
|
||||||
|
menuStripFile.Size = new Size(42, 24);
|
||||||
|
menuStripFile.TabIndex = 2;
|
||||||
|
menuStripFile.Text = "menuStrip";
|
||||||
|
//
|
||||||
|
// fileToolStripMenuItem
|
||||||
|
//
|
||||||
|
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
|
||||||
|
fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||||
|
fileToolStripMenuItem.Size = new Size(37, 20);
|
||||||
|
fileToolStripMenuItem.Text = "File";
|
||||||
|
//
|
||||||
|
// saveToolStripMenuItem
|
||||||
|
//
|
||||||
|
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||||
|
saveToolStripMenuItem.Size = new Size(100, 22);
|
||||||
|
saveToolStripMenuItem.Text = "Save";
|
||||||
|
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// loadToolStripMenuItem
|
||||||
|
//
|
||||||
|
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||||
|
loadToolStripMenuItem.Size = new Size(100, 22);
|
||||||
|
loadToolStripMenuItem.Text = "Load";
|
||||||
|
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.FileName = "openFileDialog1";
|
||||||
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// FormMonorailCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(974, 626);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Controls.Add(panelTools);
|
||||||
|
Controls.Add(menuStripFile);
|
||||||
|
MainMenuStrip = menuStripFile;
|
||||||
|
Name = "FormMonorailCollection";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Monorail collection";
|
||||||
|
panelTools.ResumeLayout(false);
|
||||||
|
panelTools.PerformLayout();
|
||||||
|
panelSets.ResumeLayout(false);
|
||||||
|
panelSets.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
menuStripFile.ResumeLayout(false);
|
||||||
|
menuStripFile.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Panel panelTools;
|
||||||
|
private Label labelToolsName;
|
||||||
|
private Button buttonAddMonorail;
|
||||||
|
private Button buttonRemoveMonorail;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private Button buttonRefreshCollection;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private Panel panelSets;
|
||||||
|
private Label labelSetsName;
|
||||||
|
private ListBox listBoxSets;
|
||||||
|
private Button ButtonDelSet;
|
||||||
|
private Button buttonAddSet;
|
||||||
|
private TextBox textBoxNameSet;
|
||||||
|
private MenuStrip menuStripFile;
|
||||||
|
private ToolStripMenuItem fileToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem saveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
}
|
||||||
|
}
|
236
ProjectMonorail/ProjectMonorail/FormMonorailCollection.cs
Normal file
236
ProjectMonorail/ProjectMonorail/FormMonorailCollection.cs
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
using ProjectMonorail.DrawingObjects;
|
||||||
|
using ProjectMonorail.Generics;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ProjectMonorail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма для работы с набором объектов класса DrawingMonorail
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormMonorailCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly MonorailsGenericStorage _storage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormMonorailCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_storage = new MonorailsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение listBoxSets
|
||||||
|
/// </summary>
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxSets.SelectedIndex;
|
||||||
|
listBoxSets.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxSets.Items.Add(_storage.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxSets.Items.Count > 0 && (index == -1 || index >= listBoxSets.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxSets.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxSets.Items.Count > 0 && index > -1 && index < listBoxSets.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxSets.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonAddSet_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxNameSet.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxNameSet.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void listBoxSets_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image =
|
||||||
|
_storage[listBoxSets.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDelSet_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxSets.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить набор {listBoxSets.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxSets.SelectedItem.ToString() ?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMonorail(DrawingMonorail monorail)
|
||||||
|
{
|
||||||
|
monorail.PictureHeight = pictureBoxCollection.Height;
|
||||||
|
monorail.PictureWidth = pictureBoxCollection.Width;
|
||||||
|
if (listBoxSets.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var obj = _storage[listBoxSets.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj + monorail != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonAddMonorail_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxSets.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var formMonorailConfig = new FormMonorailConfig();
|
||||||
|
formMonorailConfig.AddEvent(addMonorail);
|
||||||
|
formMonorailConfig.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonRemoveMonorail_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxSets.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var obj = _storage[listBoxSets.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
|
||||||
|
if (obj - pos)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обновление рисунка по набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxSets.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var obj = _storage[listBoxSets.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Сохранение"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_storage.SaveData(saveFileDialog.FileName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Save was successful",
|
||||||
|
"Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Save failed", "Result",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Загрузка"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_storage.LoadData(openFileDialog.FileName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Load was successful",
|
||||||
|
"Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Load failed", "Result",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
132
ProjectMonorail/ProjectMonorail/FormMonorailCollection.resx
Normal file
132
ProjectMonorail/ProjectMonorail/FormMonorailCollection.resx
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="menuStripFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 10</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>136, 10</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>269, 10</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>25</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
356
ProjectMonorail/ProjectMonorail/FormMonorailConfig.Designer.cs
generated
Normal file
356
ProjectMonorail/ProjectMonorail/FormMonorailConfig.Designer.cs
generated
Normal file
@ -0,0 +1,356 @@
|
|||||||
|
namespace ProjectMonorail
|
||||||
|
{
|
||||||
|
partial class FormMonorailConfig
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
groupBoxParameters = new GroupBox();
|
||||||
|
panelColor = new Panel();
|
||||||
|
panelPurple = new Panel();
|
||||||
|
panelRed = new Panel();
|
||||||
|
panelYellow = new Panel();
|
||||||
|
panelGray = new Panel();
|
||||||
|
panelGreen = new Panel();
|
||||||
|
panelBlue = new Panel();
|
||||||
|
panelWhite = new Panel();
|
||||||
|
panelBlack = new Panel();
|
||||||
|
labelModifiedObject = new Label();
|
||||||
|
labelSimpleObject = new Label();
|
||||||
|
checkBoxMagneticRail = new CheckBox();
|
||||||
|
checkBoxExtraCabin = new CheckBox();
|
||||||
|
numericUpDownWeight = new NumericUpDown();
|
||||||
|
numericUpDownSpeed = new NumericUpDown();
|
||||||
|
labelWeight = new Label();
|
||||||
|
labelSpeed = new Label();
|
||||||
|
pictureBoxObject = new PictureBox();
|
||||||
|
panelObject = new Panel();
|
||||||
|
labelAdditionalColor = new Label();
|
||||||
|
labelMainColor = new Label();
|
||||||
|
buttonAdd = new Button();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
groupBoxParameters.SuspendLayout();
|
||||||
|
panelColor.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
|
||||||
|
panelObject.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxParameters
|
||||||
|
//
|
||||||
|
groupBoxParameters.Controls.Add(panelColor);
|
||||||
|
groupBoxParameters.Controls.Add(labelModifiedObject);
|
||||||
|
groupBoxParameters.Controls.Add(labelSimpleObject);
|
||||||
|
groupBoxParameters.Controls.Add(checkBoxMagneticRail);
|
||||||
|
groupBoxParameters.Controls.Add(checkBoxExtraCabin);
|
||||||
|
groupBoxParameters.Controls.Add(numericUpDownWeight);
|
||||||
|
groupBoxParameters.Controls.Add(numericUpDownSpeed);
|
||||||
|
groupBoxParameters.Controls.Add(labelWeight);
|
||||||
|
groupBoxParameters.Controls.Add(labelSpeed);
|
||||||
|
groupBoxParameters.Location = new Point(12, 12);
|
||||||
|
groupBoxParameters.Name = "groupBoxParameters";
|
||||||
|
groupBoxParameters.Size = new Size(480, 218);
|
||||||
|
groupBoxParameters.TabIndex = 0;
|
||||||
|
groupBoxParameters.TabStop = false;
|
||||||
|
groupBoxParameters.Text = "Parameters";
|
||||||
|
//
|
||||||
|
// panelColor
|
||||||
|
//
|
||||||
|
panelColor.Controls.Add(panelPurple);
|
||||||
|
panelColor.Controls.Add(panelRed);
|
||||||
|
panelColor.Controls.Add(panelYellow);
|
||||||
|
panelColor.Controls.Add(panelGray);
|
||||||
|
panelColor.Controls.Add(panelGreen);
|
||||||
|
panelColor.Controls.Add(panelBlue);
|
||||||
|
panelColor.Controls.Add(panelWhite);
|
||||||
|
panelColor.Controls.Add(panelBlack);
|
||||||
|
panelColor.Location = new Point(264, 22);
|
||||||
|
panelColor.Name = "panelColor";
|
||||||
|
panelColor.Size = new Size(210, 112);
|
||||||
|
panelColor.TabIndex = 9;
|
||||||
|
panelColor.MouseDown += panelColor_MouseDown;
|
||||||
|
//
|
||||||
|
// panelPurple
|
||||||
|
//
|
||||||
|
panelPurple.BackColor = Color.Purple;
|
||||||
|
panelPurple.Location = new Point(168, 62);
|
||||||
|
panelPurple.Name = "panelPurple";
|
||||||
|
panelPurple.Size = new Size(32, 34);
|
||||||
|
panelPurple.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// panelRed
|
||||||
|
//
|
||||||
|
panelRed.BackColor = Color.Red;
|
||||||
|
panelRed.Location = new Point(10, 16);
|
||||||
|
panelRed.Name = "panelRed";
|
||||||
|
panelRed.Size = new Size(32, 34);
|
||||||
|
panelRed.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// panelYellow
|
||||||
|
//
|
||||||
|
panelYellow.BackColor = Color.Yellow;
|
||||||
|
panelYellow.Location = new Point(168, 16);
|
||||||
|
panelYellow.Name = "panelYellow";
|
||||||
|
panelYellow.Size = new Size(32, 34);
|
||||||
|
panelYellow.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// panelGray
|
||||||
|
//
|
||||||
|
panelGray.BackColor = Color.Gray;
|
||||||
|
panelGray.Location = new Point(60, 62);
|
||||||
|
panelGray.Name = "panelGray";
|
||||||
|
panelGray.Size = new Size(32, 34);
|
||||||
|
panelGray.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// panelGreen
|
||||||
|
//
|
||||||
|
panelGreen.BackColor = Color.Green;
|
||||||
|
panelGreen.Location = new Point(60, 16);
|
||||||
|
panelGreen.Name = "panelGreen";
|
||||||
|
panelGreen.Size = new Size(32, 34);
|
||||||
|
panelGreen.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// panelBlue
|
||||||
|
//
|
||||||
|
panelBlue.BackColor = Color.Blue;
|
||||||
|
panelBlue.Location = new Point(114, 16);
|
||||||
|
panelBlue.Name = "panelBlue";
|
||||||
|
panelBlue.Size = new Size(32, 34);
|
||||||
|
panelBlue.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// panelWhite
|
||||||
|
//
|
||||||
|
panelWhite.BackColor = Color.White;
|
||||||
|
panelWhite.Location = new Point(10, 62);
|
||||||
|
panelWhite.Name = "panelWhite";
|
||||||
|
panelWhite.Size = new Size(32, 34);
|
||||||
|
panelWhite.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panelBlack
|
||||||
|
//
|
||||||
|
panelBlack.BackColor = Color.Black;
|
||||||
|
panelBlack.Location = new Point(114, 62);
|
||||||
|
panelBlack.Name = "panelBlack";
|
||||||
|
panelBlack.Size = new Size(32, 34);
|
||||||
|
panelBlack.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// labelModifiedObject
|
||||||
|
//
|
||||||
|
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelModifiedObject.Location = new Point(378, 160);
|
||||||
|
labelModifiedObject.Name = "labelModifiedObject";
|
||||||
|
labelModifiedObject.Size = new Size(94, 33);
|
||||||
|
labelModifiedObject.TabIndex = 8;
|
||||||
|
labelModifiedObject.Text = "Modified";
|
||||||
|
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelModifiedObject.MouseDown += LabelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// labelSimpleObject
|
||||||
|
//
|
||||||
|
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelSimpleObject.Location = new Point(264, 160);
|
||||||
|
labelSimpleObject.Name = "labelSimpleObject";
|
||||||
|
labelSimpleObject.Size = new Size(94, 33);
|
||||||
|
labelSimpleObject.TabIndex = 7;
|
||||||
|
labelSimpleObject.Text = "Simple";
|
||||||
|
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelSimpleObject.MouseDown += LabelObject_MouseDown;
|
||||||
|
//
|
||||||
|
// checkBoxMagneticRail
|
||||||
|
//
|
||||||
|
checkBoxMagneticRail.AutoSize = true;
|
||||||
|
checkBoxMagneticRail.Location = new Point(15, 174);
|
||||||
|
checkBoxMagneticRail.Name = "checkBoxMagneticRail";
|
||||||
|
checkBoxMagneticRail.Size = new Size(174, 19);
|
||||||
|
checkBoxMagneticRail.TabIndex = 5;
|
||||||
|
checkBoxMagneticRail.Text = "Indication of a magnetic rail";
|
||||||
|
checkBoxMagneticRail.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxExtraCabin
|
||||||
|
//
|
||||||
|
checkBoxExtraCabin.AutoSize = true;
|
||||||
|
checkBoxExtraCabin.Location = new Point(15, 136);
|
||||||
|
checkBoxExtraCabin.Name = "checkBoxExtraCabin";
|
||||||
|
checkBoxExtraCabin.Size = new Size(197, 19);
|
||||||
|
checkBoxExtraCabin.TabIndex = 4;
|
||||||
|
checkBoxExtraCabin.Text = "Indication of an additional cabin";
|
||||||
|
checkBoxExtraCabin.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// numericUpDownWeight
|
||||||
|
//
|
||||||
|
numericUpDownWeight.Location = new Point(77, 73);
|
||||||
|
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||||
|
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||||
|
numericUpDownWeight.Size = new Size(75, 23);
|
||||||
|
numericUpDownWeight.TabIndex = 3;
|
||||||
|
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// numericUpDownSpeed
|
||||||
|
//
|
||||||
|
numericUpDownSpeed.Location = new Point(77, 29);
|
||||||
|
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||||
|
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||||
|
numericUpDownSpeed.Size = new Size(75, 23);
|
||||||
|
numericUpDownSpeed.TabIndex = 2;
|
||||||
|
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// labelWeight
|
||||||
|
//
|
||||||
|
labelWeight.AutoSize = true;
|
||||||
|
labelWeight.Location = new Point(15, 76);
|
||||||
|
labelWeight.Name = "labelWeight";
|
||||||
|
labelWeight.Size = new Size(48, 15);
|
||||||
|
labelWeight.TabIndex = 1;
|
||||||
|
labelWeight.Text = "Weight:";
|
||||||
|
//
|
||||||
|
// labelSpeed
|
||||||
|
//
|
||||||
|
labelSpeed.AutoSize = true;
|
||||||
|
labelSpeed.Location = new Point(15, 33);
|
||||||
|
labelSpeed.Name = "labelSpeed";
|
||||||
|
labelSpeed.Size = new Size(42, 15);
|
||||||
|
labelSpeed.TabIndex = 0;
|
||||||
|
labelSpeed.Text = "Speed:";
|
||||||
|
//
|
||||||
|
// pictureBoxObject
|
||||||
|
//
|
||||||
|
pictureBoxObject.Location = new Point(12, 44);
|
||||||
|
pictureBoxObject.Name = "pictureBoxObject";
|
||||||
|
pictureBoxObject.Size = new Size(237, 134);
|
||||||
|
pictureBoxObject.TabIndex = 1;
|
||||||
|
pictureBoxObject.TabStop = false;
|
||||||
|
//
|
||||||
|
// panelObject
|
||||||
|
//
|
||||||
|
panelObject.AllowDrop = true;
|
||||||
|
panelObject.Controls.Add(labelAdditionalColor);
|
||||||
|
panelObject.Controls.Add(labelMainColor);
|
||||||
|
panelObject.Controls.Add(pictureBoxObject);
|
||||||
|
panelObject.Location = new Point(498, 12);
|
||||||
|
panelObject.Name = "panelObject";
|
||||||
|
panelObject.Size = new Size(261, 193);
|
||||||
|
panelObject.TabIndex = 2;
|
||||||
|
panelObject.DragDrop += PanelObject_DragDrop;
|
||||||
|
panelObject.DragEnter += PanelObject_DragEnter;
|
||||||
|
//
|
||||||
|
// labelAdditionalColor
|
||||||
|
//
|
||||||
|
labelAdditionalColor.AllowDrop = true;
|
||||||
|
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelAdditionalColor.Location = new Point(139, 8);
|
||||||
|
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||||
|
labelAdditionalColor.Size = new Size(110, 33);
|
||||||
|
labelAdditionalColor.TabIndex = 10;
|
||||||
|
labelAdditionalColor.Text = "Additional color";
|
||||||
|
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop;
|
||||||
|
labelAdditionalColor.DragEnter += labelColor_DragEnter;
|
||||||
|
//
|
||||||
|
// labelMainColor
|
||||||
|
//
|
||||||
|
labelMainColor.AllowDrop = true;
|
||||||
|
labelMainColor.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelMainColor.Location = new Point(12, 8);
|
||||||
|
labelMainColor.Name = "labelMainColor";
|
||||||
|
labelMainColor.Size = new Size(110, 33);
|
||||||
|
labelMainColor.TabIndex = 9;
|
||||||
|
labelMainColor.Text = "Color";
|
||||||
|
labelMainColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
labelMainColor.DragDrop += labelMainColor_DragDrop;
|
||||||
|
labelMainColor.DragEnter += labelColor_DragEnter;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
buttonAdd.Location = new Point(522, 211);
|
||||||
|
buttonAdd.Name = "buttonAdd";
|
||||||
|
buttonAdd.Size = new Size(91, 23);
|
||||||
|
buttonAdd.TabIndex = 3;
|
||||||
|
buttonAdd.Text = "Add";
|
||||||
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += buttonAdd_Click;
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(647, 211);
|
||||||
|
buttonCancel.Name = "buttonCancel";
|
||||||
|
buttonCancel.Size = new Size(91, 23);
|
||||||
|
buttonCancel.TabIndex = 4;
|
||||||
|
buttonCancel.Text = "Cancellation";
|
||||||
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormMonorailConfig
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(772, 242);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonAdd);
|
||||||
|
Controls.Add(panelObject);
|
||||||
|
Controls.Add(groupBoxParameters);
|
||||||
|
Name = "FormMonorailConfig";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Object creation";
|
||||||
|
groupBoxParameters.ResumeLayout(false);
|
||||||
|
groupBoxParameters.PerformLayout();
|
||||||
|
panelColor.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
|
||||||
|
panelObject.ResumeLayout(false);
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxParameters;
|
||||||
|
private Label labelSpeed;
|
||||||
|
private Label labelWeight;
|
||||||
|
private NumericUpDown numericUpDownWeight;
|
||||||
|
private NumericUpDown numericUpDownSpeed;
|
||||||
|
private CheckBox checkBoxExtraCabin;
|
||||||
|
private CheckBox checkBoxMagneticRail;
|
||||||
|
private Panel panelGray;
|
||||||
|
private Panel panelYellow;
|
||||||
|
private Panel panelBlue;
|
||||||
|
private Panel panelGreen;
|
||||||
|
private Panel panelWhite;
|
||||||
|
private Panel panelRed;
|
||||||
|
private Panel panelPurple;
|
||||||
|
private Panel panelBlack;
|
||||||
|
private Label labelModifiedObject;
|
||||||
|
private Label labelSimpleObject;
|
||||||
|
private PictureBox pictureBoxObject;
|
||||||
|
private Panel panelObject;
|
||||||
|
private Label labelAdditionalColor;
|
||||||
|
private Label labelMainColor;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Panel panelColor;
|
||||||
|
}
|
||||||
|
}
|
159
ProjectMonorail/ProjectMonorail/FormMonorailConfig.cs
Normal file
159
ProjectMonorail/ProjectMonorail/FormMonorailConfig.cs
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
using ProjectMonorail.DrawingObjects;
|
||||||
|
using ProjectMonorail.Entities;
|
||||||
|
|
||||||
|
namespace ProjectMonorail
|
||||||
|
{
|
||||||
|
public partial class FormMonorailConfig : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Переменная-выбранный монорельс
|
||||||
|
/// </summary>
|
||||||
|
DrawingMonorail? _monorail = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Событие
|
||||||
|
/// </summary>
|
||||||
|
private event Action<DrawingMonorail>? EventAddMonorail;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormMonorailConfig()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
panelBlack.MouseDown += panelColor_MouseDown;
|
||||||
|
panelPurple.MouseDown += panelColor_MouseDown;
|
||||||
|
panelGray.MouseDown += panelColor_MouseDown;
|
||||||
|
panelGreen.MouseDown += panelColor_MouseDown;
|
||||||
|
panelRed.MouseDown += panelColor_MouseDown;
|
||||||
|
panelWhite.MouseDown += panelColor_MouseDown;
|
||||||
|
panelYellow.MouseDown += panelColor_MouseDown;
|
||||||
|
panelBlue.MouseDown += panelColor_MouseDown;
|
||||||
|
|
||||||
|
buttonCancel.Click += (s, e) => Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Добавление события
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ev">Привязанный метод</param>
|
||||||
|
public void AddEvent(Action<DrawingMonorail> ev)
|
||||||
|
{
|
||||||
|
if (EventAddMonorail == null)
|
||||||
|
{
|
||||||
|
EventAddMonorail = ev;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddMonorail += ev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Отрисовать монорельс
|
||||||
|
/// </summary>
|
||||||
|
private void DrawMonorail()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_monorail?.SetPosition(5, 5);
|
||||||
|
_monorail?.DrawTransport(gr);
|
||||||
|
pictureBoxObject.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Передаем информацию при нажатии на Label
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
||||||
|
DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
||||||
|
DragDropEffects.Move | DragDropEffects.Copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка получаемой информации (ее типа на соответствие требуемому)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.Effect = DragDropEffects.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Действия при приеме перетаскиваемой информации
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||||
|
{
|
||||||
|
case "labelSimpleObject":
|
||||||
|
_monorail = new DrawingMonorail((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
||||||
|
pictureBoxObject.Height);
|
||||||
|
break;
|
||||||
|
case "labelModifiedObject":
|
||||||
|
_monorail = new DrawingExtendedMonorail((int)numericUpDownSpeed.Value,
|
||||||
|
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxMagneticRail.Checked,
|
||||||
|
checkBoxExtraCabin.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DrawMonorail();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelMainColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_monorail == null)
|
||||||
|
return;
|
||||||
|
_monorail.EntityMonorail.MainColor = (Color)e.Data?.GetData(typeof(Color));
|
||||||
|
DrawMonorail();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (_monorail == null || _monorail is not DrawingExtendedMonorail)
|
||||||
|
return;
|
||||||
|
((EntityExtendedMonorail)_monorail.EntityMonorail).AdditionalColor = (Color)e.Data?.GetData(typeof(Color));
|
||||||
|
DrawMonorail();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление монорельса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
EventAddMonorail?.Invoke(_monorail);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectMonorail/ProjectMonorail/FormMonorailConfig.resx
Normal file
120
ProjectMonorail/ProjectMonorail/FormMonorailConfig.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
31
ProjectMonorail/ProjectMonorail/IMoveableObject.cs
Normal file
31
ProjectMonorail/ProjectMonorail/IMoveableObject.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
namespace ProjectMonorail.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Интерфейс для работы с перемещаемым объектом
|
||||||
|
/// </summary>
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение координаты X объекта
|
||||||
|
/// </summary>
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг объекта
|
||||||
|
/// </summary>
|
||||||
|
int GetStep { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверка, можно ли переместиться по нужному направлению
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool CheckCanMove(DirectionType direction);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
void MoveObject(DirectionType direction);
|
||||||
|
}
|
||||||
|
}
|
159
ProjectMonorail/ProjectMonorail/MonorailsGenericCollection.cs
Normal file
159
ProjectMonorail/ProjectMonorail/MonorailsGenericCollection.cs
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
using ProjectMonorail.DrawingObjects;
|
||||||
|
using ProjectMonorail.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectMonorail.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный класс для набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
internal class MonorailsGenericCollection<T, U>
|
||||||
|
where T : DrawingMonorail
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 193;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 102;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объектов коллекции
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<T?> GetMonorails => _collection.GetMonorails();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public MonorailsGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int operator +(MonorailsGenericCollection<T, U> collect, T? obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator -(MonorailsGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection[pos];
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
return collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowMonorails()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{ //линия разметки места
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth
|
||||||
|
+ _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||||
|
_pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
int diff = 1, currWidth = 0, i = 0;
|
||||||
|
foreach (var monorail in _collection.GetMonorails())
|
||||||
|
{
|
||||||
|
currWidth++;
|
||||||
|
if (currWidth > width)
|
||||||
|
{
|
||||||
|
diff++;
|
||||||
|
currWidth = 1;
|
||||||
|
}
|
||||||
|
if (monorail != null)
|
||||||
|
{
|
||||||
|
monorail.SetPosition(i % width * _placeSizeWidth + _placeSizeWidth / 40,
|
||||||
|
(height - diff) * _placeSizeHeight + _placeSizeHeight / 15);
|
||||||
|
monorail.DrawTransport(g);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
174
ProjectMonorail/ProjectMonorail/MonorailsGenericStorage.cs
Normal file
174
ProjectMonorail/ProjectMonorail/MonorailsGenericStorage.cs
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
using ProjectMonorail.DrawingObjects;
|
||||||
|
using ProjectMonorail.MovementStrategy;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ProjectMonorail.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс для хранения коллекции
|
||||||
|
/// </summary>
|
||||||
|
internal class MonorailsGenericStorage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи ключа и значения элемента словаря
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, MonorailsGenericCollection<DrawingMonorail, DrawingObjectMonorail>> _monorailsStorages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Keys => _monorailsStorages.Keys.ToList();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pictureWidth"></param>
|
||||||
|
/// <param name="pictureHeight"></param>
|
||||||
|
public MonorailsGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_monorailsStorages = new Dictionary<string, MonorailsGenericCollection<DrawingMonorail, DrawingObjectMonorail>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
if (!_monorailsStorages.ContainsKey(name))
|
||||||
|
_monorailsStorages.Add(name, new MonorailsGenericCollection<DrawingMonorail, DrawingObjectMonorail>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (_monorailsStorages.ContainsKey(name))
|
||||||
|
_monorailsStorages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public MonorailsGenericCollection<DrawingMonorail, DrawingObjectMonorail>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_monorailsStorages.ContainsKey(ind))
|
||||||
|
return _monorailsStorages[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по монорельсам в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<string, MonorailsGenericCollection<DrawingMonorail, DrawingObjectMonorail>> record in _monorailsStorages)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawingMonorail? elem in record.Value.GetMonorails)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using StreamWriter sw = new(filename);
|
||||||
|
sw.Write($"MonorailStorage{Environment.NewLine}{data}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка информации по монорельсам в хранилище из файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||||
|
public bool LoadData(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using (StreamReader sr = new(filename))
|
||||||
|
{
|
||||||
|
string str = sr.ReadLine();
|
||||||
|
if (str == null || str.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!str.StartsWith("MonorailStorage"))
|
||||||
|
{
|
||||||
|
//если нет такой записи, то это не те данные
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_monorailsStorages.Clear();
|
||||||
|
while ((str = sr.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 2)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
MonorailsGenericCollection<DrawingMonorail, DrawingObjectMonorail> collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (string elem in set.Reverse())
|
||||||
|
{
|
||||||
|
DrawingMonorail? monorail = elem?.CreateDrawingMonorail(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (monorail != null)
|
||||||
|
{
|
||||||
|
if (collection + monorail == -1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_monorailsStorages.Add(record[0], collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
ProjectMonorail/ProjectMonorail/MoveToBorder.cs
Normal file
46
ProjectMonorail/ProjectMonorail/MoveToBorder.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
namespace ProjectMonorail.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения объекта в правый нижний край экрана
|
||||||
|
/// </summary>
|
||||||
|
public class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder <= FieldWidth &&
|
||||||
|
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||||
|
objParams.DownBorder <= FieldHeight &&
|
||||||
|
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX < 0)
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY < 0)
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
ProjectMonorail/ProjectMonorail/MoveToCenter.cs
Normal file
54
ProjectMonorail/ProjectMonorail/MoveToCenter.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
namespace ProjectMonorail.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения объекта в центр экрана
|
||||||
|
/// </summary>
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestinaion()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParameters;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
ProjectMonorail/ProjectMonorail/ObjectParameters.cs
Normal file
61
ProjectMonorail/ProjectMonorail/ObjectParameters.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
namespace ProjectMonorail.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры-координаты объекта
|
||||||
|
/// </summary>
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
|
||||||
|
private readonly int _y;
|
||||||
|
|
||||||
|
private readonly int _width;
|
||||||
|
|
||||||
|
private readonly int _height;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Левая граница
|
||||||
|
/// </summary>
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Верхняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int TopBorder => _y;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Правая граница
|
||||||
|
/// </summary>
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Нижняя граница
|
||||||
|
/// </summary>
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Середина объекта
|
||||||
|
/// </summary>
|
||||||
|
public int ObjectMiddleVertical => _y + _height / 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Координата X</param>
|
||||||
|
/// <param name="y">Координата Y</param>
|
||||||
|
/// <param name="width">Ширина</param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace ProjectMonorail
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Form1());
|
Application.Run(new FormMonorailCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,4 +8,19 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Update="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
103
ProjectMonorail/ProjectMonorail/Properties/Resources.Designer.cs
generated
Normal file
103
ProjectMonorail/ProjectMonorail/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код создан программой.
|
||||||
|
// Исполняемая версия:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||||
|
// повторной генерации кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace ProjectMonorail.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||||
|
/// </summary>
|
||||||
|
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||||
|
// с помощью такого средства, как ResGen или Visual Studio.
|
||||||
|
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||||
|
// с параметром /str или перестройте свой проект VS.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources {
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
|
get {
|
||||||
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectMonorail.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||||
|
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrowDown {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrowDown", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrowLeft {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrowLeft", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrowRight {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrowRight", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrowUp {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrowUp", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
133
ProjectMonorail/ProjectMonorail/Properties/Resources.resx
Normal file
133
ProjectMonorail/ProjectMonorail/Properties/Resources.resx
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
|
<data name="arrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="arrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="arrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="arrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
BIN
ProjectMonorail/ProjectMonorail/Resources/arrowDown.png
Normal file
BIN
ProjectMonorail/ProjectMonorail/Resources/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 415 B |
BIN
ProjectMonorail/ProjectMonorail/Resources/arrowLeft.png
Normal file
BIN
ProjectMonorail/ProjectMonorail/Resources/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 411 B |
BIN
ProjectMonorail/ProjectMonorail/Resources/arrowRight.png
Normal file
BIN
ProjectMonorail/ProjectMonorail/Resources/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 352 B |
BIN
ProjectMonorail/ProjectMonorail/Resources/arrowUp.png
Normal file
BIN
ProjectMonorail/ProjectMonorail/Resources/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 412 B |
110
ProjectMonorail/ProjectMonorail/SetGeneric.cs
Normal file
110
ProjectMonorail/ProjectMonorail/SetGeneric.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
namespace ProjectMonorail.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
internal class SetGeneric<T> where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Список объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly List<T?> _places;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в списке
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Count;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальное количество объектов в списке
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _maxCount;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="monorail">Добавляемый монорельс</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T monorail)
|
||||||
|
{
|
||||||
|
return Insert(monorail, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="monorail">Добавляемый монорельс</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T monorail, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position > Count || Count >= _maxCount)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
_places.Insert(position, monorail);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return false;
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position > Count || Count >= _maxCount)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_places.Insert(position, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetMonorails(int? maxMonorails = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxMonorails.HasValue && i == maxMonorails.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
ProjectMonorail/ProjectMonorail/Status.cs
Normal file
14
ProjectMonorail/ProjectMonorail/Status.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace ProjectMonorail.MovementStrategy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Статус выполнения операции перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
|
||||||
|
InProgress,
|
||||||
|
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user