Compare commits
No commits in common. "6711705a957194623922340865ca46464fbeb1ad" and "e71e32c73b68617d95dbfd8305464659fc7a4242" have entirely different histories.
6711705a95
...
e71e32c73b
@ -1,27 +1,24 @@
|
|||||||
namespace WarmlyLocomotive.MovementStrategy;
|
namespace WarmlyLocomotive;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum MovementDirection
|
public enum DirectionType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вверх
|
/// Вверх
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Up = 1,
|
Up = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вниз
|
/// Вниз
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Down = 2,
|
Down = 2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Влево
|
/// Влево
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вправо
|
/// Вправо
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Right = 4
|
Right = 4
|
||||||
}
|
|
||||||
|
}
|
@ -1,13 +1,14 @@
|
|||||||
using WarmlyLocomotive.Entities;
|
namespace WarmlyLocomotive;
|
||||||
|
|
||||||
namespace WarmlyLocomotive.Drawnings;
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
public class DrawningLocomotive
|
/// </summary>
|
||||||
|
public class DrawningWarmlyLocomotive
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityLocomotive? EntityLocomotive { get; protected set; }
|
public EntityWarmlyLocomotive? EntityWarmlyLocomotive { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -19,74 +20,38 @@ public class DrawningLocomotive
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки паровоза
|
/// Левая координата прорисовки паровоза
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected int? _startPosX;
|
private int? _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки паровоза
|
/// Верхняя кооридната прорисовки паровоза
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected int? _startPosY;
|
private int? _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки паровоза
|
/// Ширина прорисовки паровоза
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningLocomotiveWidth = 130;
|
private readonly int _drawningWarmlyLocomotiveWidth = 130;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки паровоза
|
/// Высота прорисовки паровоза
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningLocomotiveHeight = 40;
|
private readonly int _drawningWarmlyLocomotiveHeight = 50;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Координата X объекта
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? GetPosX => _startPosX;
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
/// <summary>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
/// Координата Y объекта
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
/// </summary>
|
/// <param name="chimney">Признак наличия дымохода</param>
|
||||||
public int? GetPosY => _startPosY;
|
/// <param name="compartment">Признак наличия отсека</param>
|
||||||
|
/// <param name="indicatingLine">Признак наличия обозначающей полосы</param>
|
||||||
/// <summary>
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool chimney, bool compartment, bool indicatingLine)
|
||||||
/// Ширина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int GetWidth => _drawningLocomotiveWidth;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Высота объекта
|
|
||||||
/// </summary>
|
|
||||||
public int GetHeight => _drawningLocomotiveHeight;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Пустой конструктор
|
|
||||||
/// </summary>
|
|
||||||
private DrawningLocomotive()
|
|
||||||
{
|
{
|
||||||
|
EntityWarmlyLocomotive = new EntityWarmlyLocomotive();
|
||||||
|
EntityWarmlyLocomotive.Init(speed, weight, bodyColor, additionalColor, chimney, compartment, indicatingLine);
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = null;
|
_startPosY = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
public DrawningLocomotive(int speed, double weight, Color bodyColor) : this()
|
|
||||||
{
|
|
||||||
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор для наследников
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="drawningLocomotiveWidth">Ширина прорисовки паровоза</param>
|
|
||||||
/// <param name="drawningLocomotiveHeight">Высота прорисовки паровоза</param>
|
|
||||||
protected DrawningLocomotive(int drawningLocomotiveWidth, int drawningLocomotiveHeight) : this()
|
|
||||||
{
|
|
||||||
_drawningLocomotiveWidth = drawningLocomotiveWidth;
|
|
||||||
_pictureHeight = drawningLocomotiveHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -98,7 +63,7 @@ public class DrawningLocomotive
|
|||||||
// TODO проверка, что объект "влезает" в размеры поля
|
// TODO проверка, что объект "влезает" в размеры поля
|
||||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||||
|
|
||||||
if (width > _drawningLocomotiveWidth && height > _drawningLocomotiveHeight)
|
if (width > _drawningWarmlyLocomotiveWidth && height > _drawningWarmlyLocomotiveHeight)
|
||||||
{
|
{
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
@ -110,14 +75,14 @@ public class DrawningLocomotive
|
|||||||
|
|
||||||
if (_startPosY.Value < 0) { _startPosY = 0; }
|
if (_startPosY.Value < 0) { _startPosY = 0; }
|
||||||
|
|
||||||
if (_startPosX.Value + _drawningLocomotiveWidth > _pictureWidth)
|
if (_startPosX.Value + _drawningWarmlyLocomotiveWidth > _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX = _pictureWidth - _drawningLocomotiveWidth;
|
_startPosX = _pictureWidth - _drawningWarmlyLocomotiveWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_startPosY.Value + _drawningLocomotiveHeight > _pictureHeight)
|
if (_startPosY.Value + _drawningWarmlyLocomotiveHeight > _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY = _pictureHeight - _drawningLocomotiveHeight;
|
_startPosY = _pictureHeight - _drawningWarmlyLocomotiveHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -145,18 +110,18 @@ public class DrawningLocomotive
|
|||||||
if (_startPosY.Value < 0) { _startPosY = 0; }
|
if (_startPosY.Value < 0) { _startPosY = 0; }
|
||||||
if (_startPosX.Value < 0) { _startPosX = 0; }
|
if (_startPosX.Value < 0) { _startPosX = 0; }
|
||||||
|
|
||||||
if (_startPosX.Value + _drawningLocomotiveWidth > _pictureWidth)
|
if (_startPosX.Value + _drawningWarmlyLocomotiveWidth > _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX = _pictureWidth - _drawningLocomotiveWidth;
|
_startPosX = _pictureWidth - _drawningWarmlyLocomotiveWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_startPosY.Value + _drawningLocomotiveHeight > _pictureHeight)
|
if (_startPosY.Value + _drawningWarmlyLocomotiveHeight > _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY = _pictureHeight - _drawningLocomotiveHeight;
|
_startPosY = _pictureHeight - _drawningWarmlyLocomotiveHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Изменение направления перемещения
|
/// Изменение направления перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -164,7 +129,7 @@ public class DrawningLocomotive
|
|||||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityWarmlyLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -172,30 +137,30 @@ public class DrawningLocomotive
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntityLocomotive.Step > 0)
|
if (_startPosX.Value - EntityWarmlyLocomotive.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityLocomotive.Step;
|
_startPosX -= (int)EntityWarmlyLocomotive.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntityLocomotive.Step > 0)
|
if (_startPosY.Value - EntityWarmlyLocomotive.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityLocomotive.Step;
|
_startPosY -= (int)EntityWarmlyLocomotive.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX.Value + EntityLocomotive.Step + _drawningLocomotiveWidth < _pictureWidth)
|
if (_startPosX.Value + EntityWarmlyLocomotive.Step + _drawningWarmlyLocomotiveWidth < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityLocomotive.Step;
|
_startPosX += (int)EntityWarmlyLocomotive.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY.Value + EntityLocomotive.Step + _drawningLocomotiveHeight < _pictureHeight)
|
if (_startPosY.Value + EntityWarmlyLocomotive.Step + _drawningWarmlyLocomotiveHeight < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityLocomotive.Step;
|
_startPosY += (int)EntityWarmlyLocomotive.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -207,66 +172,88 @@ public class DrawningLocomotive
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public virtual void DrawTransport(Graphics g)
|
public void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityWarmlyLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(EntityWarmlyLocomotive.AdditionalColor);
|
||||||
|
// обвесы
|
||||||
|
if (EntityWarmlyLocomotive.Chimney)
|
||||||
|
{
|
||||||
|
//труба
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 0, 10, 10);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 0, 10, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EntityWarmlyLocomotive.Compartment)
|
||||||
|
{
|
||||||
|
//топливо отсек
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 35, 20, 5);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 35, 20, 5);
|
||||||
|
}
|
||||||
|
|
||||||
//границы паровоза
|
//границы паровоза
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value + 15, 120, 15);
|
g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value + 20, 120, 15);
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 0, 110, 15);
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 5, 110, 15);
|
||||||
|
|
||||||
//кузов
|
//кузов
|
||||||
Brush bk = new SolidBrush(EntityLocomotive.BodyColor);
|
Brush bk = new SolidBrush(EntityWarmlyLocomotive.BodyColor);
|
||||||
g.FillRectangle(bk, _startPosX.Value + 0, _startPosY.Value + 15, 120, 15);
|
g.FillRectangle(bk, _startPosX.Value + 0, _startPosY.Value + 20, 120, 15);
|
||||||
g.FillRectangle(bk, _startPosX.Value + 10, _startPosY.Value + 0, 110, 15);
|
g.FillRectangle(bk, _startPosX.Value + 10, _startPosY.Value + 5, 110, 15);
|
||||||
|
|
||||||
//дверь
|
//дверь
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 5, 10, 22);
|
g.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 10, 10, 22);
|
||||||
|
|
||||||
//нос
|
//нос
|
||||||
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 15, _startPosX.Value + 10, _startPosY.Value + 0);
|
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 20, _startPosX.Value + 10, _startPosY.Value + 5);
|
||||||
|
|
||||||
//стекла
|
//стекла
|
||||||
Pen penBlue = new(Color.LightBlue);
|
Pen penBlue = new(Color.LightBlue);
|
||||||
Brush wt = new SolidBrush(Color.White);
|
Brush wt = new SolidBrush(Color.White);
|
||||||
g.FillRectangle(wt, _startPosX.Value + 15, _startPosY.Value + 2, 10, 10);
|
g.FillRectangle(wt, _startPosX.Value + 15, _startPosY.Value + 7, 10, 10);
|
||||||
g.DrawRectangle(penBlue, _startPosX.Value + 15, _startPosY.Value + 2, 10, 10);
|
g.DrawRectangle(penBlue, _startPosX.Value + 15, _startPosY.Value + 7, 10, 10);
|
||||||
g.FillRectangle(wt, _startPosX.Value + 30, _startPosY.Value + 2, 10, 10);
|
g.FillRectangle(wt, _startPosX.Value + 30, _startPosY.Value + 7, 10, 10);
|
||||||
g.DrawRectangle(penBlue, _startPosX.Value + 30, _startPosY.Value + 2, 10, 10);
|
g.DrawRectangle(penBlue, _startPosX.Value + 30, _startPosY.Value + 7, 10, 10);
|
||||||
g.FillRectangle(wt, _startPosX.Value + 107, _startPosY.Value + 2, 10, 10);
|
g.FillRectangle(wt, _startPosX.Value + 107, _startPosY.Value + 7, 10, 10);
|
||||||
g.DrawRectangle(penBlue, _startPosX.Value + 107, _startPosY.Value + 2, 10, 10);
|
g.DrawRectangle(penBlue, _startPosX.Value + 107, _startPosY.Value + 7, 10, 10);
|
||||||
|
|
||||||
//треугольники низ
|
//треугольники низ
|
||||||
Brush br = new SolidBrush(Color.Black);
|
Brush br = new SolidBrush(Color.Black);
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 30, 5);
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 35, 30, 5);
|
||||||
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 30, _startPosX.Value + 0, _startPosY.Value + 35);
|
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 35, _startPosX.Value + 0, _startPosY.Value + 40);
|
||||||
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 35, _startPosX.Value + 10, _startPosY.Value + 35);
|
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 40, _startPosX.Value + 10, _startPosY.Value + 40);
|
||||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 30, 30, 5);
|
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 35, 30, 5);
|
||||||
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 85, _startPosY.Value + 30, 30, 5);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 110, _startPosY.Value + 30, _startPosX.Value + 130, _startPosY.Value + 35);
|
|
||||||
g.DrawLine(pen, _startPosX.Value + 130, _startPosY.Value + 35, _startPosX.Value + 110, _startPosY.Value + 35);
|
|
||||||
g.FillRectangle(br, _startPosX.Value + 85, _startPosY.Value + 30, 30, 5);
|
|
||||||
|
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 85, _startPosY.Value + 35, 30, 5);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 110, _startPosY.Value + 35, _startPosX.Value + 130, _startPosY.Value + 40);
|
||||||
|
g.DrawLine(pen, _startPosX.Value + 130, _startPosY.Value + 40, _startPosX.Value + 110, _startPosY.Value + 40);
|
||||||
|
g.FillRectangle(br, _startPosX.Value + 85, _startPosY.Value + 35, 30, 5);
|
||||||
|
|
||||||
//зад.часть
|
//зад.часть
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value + 2, 5, 25);
|
g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value + 7, 5, 25);
|
||||||
g.FillRectangle(br, _startPosX.Value + 120, _startPosY.Value + 2, 5, 25);
|
g.FillRectangle(br, _startPosX.Value + 120, _startPosY.Value + 7, 5, 25);
|
||||||
|
|
||||||
//колеса
|
//колеса
|
||||||
g.FillEllipse(wt, _startPosX.Value + 10, _startPosY.Value + 30, 12, 11);
|
g.FillEllipse(wt, _startPosX.Value + 10, _startPosY.Value + 35, 12, 11);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 30, 12, 11);
|
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 12, 11);
|
||||||
|
|
||||||
g.FillEllipse(wt, _startPosX.Value + 30, _startPosY.Value + 30, 12, 11);
|
g.FillEllipse(wt, _startPosX.Value + 30, _startPosY.Value + 35, 12, 11);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 30, 12, 11);
|
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 35, 12, 11);
|
||||||
|
|
||||||
g.FillEllipse(wt, _startPosX.Value + 80, _startPosY.Value + 30, 12, 11);
|
g.FillEllipse(wt, _startPosX.Value + 80, _startPosY.Value + 35, 12, 11);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 30, 12, 11);
|
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 12, 11);
|
||||||
|
|
||||||
g.FillEllipse(wt, _startPosX.Value + 100, _startPosY.Value + 30, 12, 11);
|
g.FillEllipse(wt, _startPosX.Value + 100, _startPosY.Value + 35, 12, 11);
|
||||||
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 30, 12, 11);
|
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 35, 12, 11);
|
||||||
|
|
||||||
|
//линия
|
||||||
|
if (EntityWarmlyLocomotive.IndicatingLine)
|
||||||
|
{
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 20, 120, 2);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,32 +0,0 @@
|
|||||||
namespace WarmlyLocomotive.Drawnings;
|
|
||||||
/// <summary>
|
|
||||||
/// Направление перемещения
|
|
||||||
/// </summary>
|
|
||||||
public enum DirectionType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Неизвестное направление
|
|
||||||
/// </summary>
|
|
||||||
Unknow = -1,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вверх
|
|
||||||
/// </summary>
|
|
||||||
Up = 1,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вниз
|
|
||||||
/// </summary>
|
|
||||||
Down = 2,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Влево
|
|
||||||
/// </summary>
|
|
||||||
Left = 3,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вправо
|
|
||||||
/// </summary>
|
|
||||||
Right = 4
|
|
||||||
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
using WarmlyLocomotive.Entities;
|
|
||||||
|
|
||||||
namespace WarmlyLocomotive.Drawnings;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|
||||||
/// </summary>
|
|
||||||
public class DrawningWarmlyLocomotive : DrawningLocomotive
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="chimney">Признак наличия дымохода</param>
|
|
||||||
/// <param name="compartment">Признак наличия отсека</param>
|
|
||||||
/// <param name="indicatingLine">Признак наличия обозначающей полосы</param>
|
|
||||||
public DrawningWarmlyLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool chimney, bool compartment, bool indicatingLine) : base(130, 50)
|
|
||||||
{
|
|
||||||
EntityLocomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, additionalColor, chimney, compartment, indicatingLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (EntityLocomotive == null || EntityLocomotive is not EntityWarmlyLocomotive warmlyLocmotive || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
|
||||||
Brush additionalBrush = new SolidBrush(warmlyLocmotive.AdditionalColor);
|
|
||||||
|
|
||||||
// обвесы
|
|
||||||
if (warmlyLocmotive.Chimney)
|
|
||||||
{
|
|
||||||
//труба
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 0, 10, 10);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 0, 10, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (warmlyLocmotive.Compartment)
|
|
||||||
{
|
|
||||||
//топливо отсек
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 35, 20, 5);
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 35, 20, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
_startPosX += 0;
|
|
||||||
_startPosY += 5;
|
|
||||||
base.DrawTransport(g);
|
|
||||||
_startPosX -= 0;
|
|
||||||
_startPosY -= 5;
|
|
||||||
|
|
||||||
//линия
|
|
||||||
if (warmlyLocmotive.IndicatingLine)
|
|
||||||
{
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 20, 120, 2);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
namespace WarmlyLocomotive.Entities;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-сущность "Паровоз"
|
|
||||||
/// </summary>
|
|
||||||
public class EntityLocomotive
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Скорость
|
|
||||||
/// </summary>
|
|
||||||
public int Speed { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Вес
|
|
||||||
/// </summary>
|
|
||||||
public double Weight { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Основной цвет
|
|
||||||
/// </summary>
|
|
||||||
public Color BodyColor { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения автомобиля
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор сущности
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес тепловоза</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
public EntityLocomotive(int speed, double weight, Color bodyColor)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +1,21 @@
|
|||||||
namespace WarmlyLocomotive.Entities;
|
namespace WarmlyLocomotive;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "тепловоз"
|
/// Класс-сущность "тепловоз"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityWarmlyLocomotive : EntityLocomotive
|
public class EntityWarmlyLocomotive
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Основной цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color BodyColor { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -22,9 +32,12 @@ public class EntityWarmlyLocomotive : EntityLocomotive
|
|||||||
/// Признак (опция) наличия гоночной полосы
|
/// Признак (опция) наличия гоночной полосы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IndicatingLine { get; private set; }
|
public bool IndicatingLine { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Шаг перемещения автомобиля
|
||||||
|
/// </summary>
|
||||||
|
public double Step => Speed * 100 / Weight;
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация полей объекта-класса тепловоза
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес тепловоза</param>
|
/// <param name="weight">Вес тепловоза</param>
|
||||||
@ -33,11 +46,15 @@ public class EntityWarmlyLocomotive : EntityLocomotive
|
|||||||
/// <param name="chimney">Признак наличия трубы</param>
|
/// <param name="chimney">Признак наличия трубы</param>
|
||||||
/// <param name="compartment">Признак наличия топливного отсека</param>
|
/// <param name="compartment">Признак наличия топливного отсека</param>
|
||||||
/// <param name="indicatingLine">Признак наличия обозначающей полосы</param>
|
/// <param name="indicatingLine">Признак наличия обозначающей полосы</param>
|
||||||
public EntityWarmlyLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool chimney, bool compartment, bool indicatingLine) : base(speed, weight, bodyColor)
|
|
||||||
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool chimney, bool compartment, bool indicatingLine)
|
||||||
{
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
Chimney = chimney;
|
Chimney = chimney;
|
||||||
Compartment = compartment;
|
Compartment = compartment;
|
||||||
IndicatingLine = indicatingLine;
|
IndicatingLine = indicatingLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -34,9 +34,6 @@
|
|||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonCreateLocomotive = new Button();
|
|
||||||
comboBoxStrategy = new ComboBox();
|
|
||||||
buttonStrategyStep = new Button();
|
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -54,9 +51,9 @@
|
|||||||
buttonCreateWarmlyLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateWarmlyLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateWarmlyLocomotive.Location = new Point(12, 409);
|
buttonCreateWarmlyLocomotive.Location = new Point(12, 409);
|
||||||
buttonCreateWarmlyLocomotive.Name = "buttonCreateWarmlyLocomotive";
|
buttonCreateWarmlyLocomotive.Name = "buttonCreateWarmlyLocomotive";
|
||||||
buttonCreateWarmlyLocomotive.Size = new Size(156, 29);
|
buttonCreateWarmlyLocomotive.Size = new Size(94, 29);
|
||||||
buttonCreateWarmlyLocomotive.TabIndex = 1;
|
buttonCreateWarmlyLocomotive.TabIndex = 1;
|
||||||
buttonCreateWarmlyLocomotive.Text = "создать локомотив";
|
buttonCreateWarmlyLocomotive.Text = "создать";
|
||||||
buttonCreateWarmlyLocomotive.UseVisualStyleBackColor = true;
|
buttonCreateWarmlyLocomotive.UseVisualStyleBackColor = true;
|
||||||
buttonCreateWarmlyLocomotive.Click += ButtonCreateWarmlyLocomotive_Click;
|
buttonCreateWarmlyLocomotive.Click += ButtonCreateWarmlyLocomotive_Click;
|
||||||
//
|
//
|
||||||
@ -108,45 +105,11 @@
|
|||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += ButtonMove_Click;
|
buttonUp.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonCreateLocomotive
|
|
||||||
//
|
|
||||||
buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreateLocomotive.Location = new Point(174, 409);
|
|
||||||
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
|
|
||||||
buttonCreateLocomotive.Size = new Size(156, 29);
|
|
||||||
buttonCreateLocomotive.TabIndex = 6;
|
|
||||||
buttonCreateLocomotive.Text = "создать паровоз";
|
|
||||||
buttonCreateLocomotive.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreateLocomotive.Click += ButtonCreateLocomotive_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
|
||||||
//
|
|
||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxStrategy.FormattingEnabled = true;
|
|
||||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру ", "К краю" });
|
|
||||||
comboBoxStrategy.Location = new Point(637, 12);
|
|
||||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
|
||||||
comboBoxStrategy.Size = new Size(151, 28);
|
|
||||||
comboBoxStrategy.TabIndex = 7;
|
|
||||||
//
|
|
||||||
// buttonStrategyStep
|
|
||||||
//
|
|
||||||
buttonStrategyStep.Location = new Point(694, 46);
|
|
||||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
|
||||||
buttonStrategyStep.Size = new Size(94, 29);
|
|
||||||
buttonStrategyStep.TabIndex = 8;
|
|
||||||
buttonStrategyStep.Text = "Шаг";
|
|
||||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
|
||||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
|
||||||
//
|
|
||||||
// FormWarmlyLocomotive
|
// FormWarmlyLocomotive
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
Controls.Add(buttonStrategyStep);
|
|
||||||
Controls.Add(comboBoxStrategy);
|
|
||||||
Controls.Add(buttonCreateLocomotive);
|
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
@ -167,8 +130,5 @@
|
|||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonCreateLocomotive;
|
|
||||||
private ComboBox comboBoxStrategy;
|
|
||||||
private Button buttonStrategyStep;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,4 @@
|
|||||||
using WarmlyLocomotive.Drawnings;
|
namespace WarmlyLocomotive;
|
||||||
using WarmlyLocomotive.MovementStrategy;
|
|
||||||
|
|
||||||
namespace WarmlyLocomotive;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Форма работы с объектом "тепловоз"
|
/// Форма работы с объектом "тепловоз"
|
||||||
@ -11,12 +8,7 @@ public partial class FormWarmlyLocomotive : Form
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поле-объект для прорисовки объекта
|
/// Поле-объект для прорисовки объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningLocomotive? _drawningLocomotive;
|
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Стратегия перемещения
|
|
||||||
/// </summary>
|
|
||||||
private AbstractStrategy? _strategy;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор формы
|
/// Конструктор формы
|
||||||
@ -24,7 +16,6 @@ public partial class FormWarmlyLocomotive : Form
|
|||||||
public FormWarmlyLocomotive()
|
public FormWarmlyLocomotive()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_strategy = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -32,59 +23,35 @@ public partial class FormWarmlyLocomotive : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningLocomotive == null)
|
if (_drawningWarmlyLocomotive == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
|
Bitmap bmp = new(pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningLocomotive.DrawTransport(gr);
|
_drawningWarmlyLocomotive.DrawTransport(gr);
|
||||||
pictureBoxWarmlyLocomotive.Image = bmp;
|
pictureBoxWarmlyLocomotive.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создание объекта класса-перемещения
|
/// Обработка нажатия кнопки "Создать"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">Тип создаваемого объекта</param>
|
/// <param name="sender"></param>
|
||||||
private void CreateObject(string type)
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreateWarmlyLocomotive_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
switch (type)
|
_drawningWarmlyLocomotive = new DrawningWarmlyLocomotive();
|
||||||
{
|
_drawningWarmlyLocomotive.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
case nameof(DrawningLocomotive):
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
_drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000),
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
break;
|
_drawningWarmlyLocomotive.SetPictureSize(pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
|
||||||
case nameof(DrawningWarmlyLocomotive):
|
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
_drawningLocomotive = new DrawningWarmlyLocomotive(random.Next(100, 300), random.Next(1000, 3000),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_drawningLocomotive.SetPictureSize(pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
|
|
||||||
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
_strategy = null;
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
Draw();
|
Draw();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Создать локомотив"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonCreateWarmlyLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarmlyLocomotive));
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Создать паровоз"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -92,72 +59,30 @@ public partial class FormWarmlyLocomotive : Form
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningLocomotive == null)
|
if (_drawningWarmlyLocomotive == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result = _drawningLocomotive.MoveTransport(DirectionType.Up);
|
result = _drawningWarmlyLocomotive.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result = _drawningLocomotive.MoveTransport(DirectionType.Down);
|
result = _drawningWarmlyLocomotive.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result = _drawningLocomotive.MoveTransport(DirectionType.Left);
|
result = _drawningWarmlyLocomotive.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result = _drawningLocomotive.MoveTransport(DirectionType.Right);
|
result = _drawningWarmlyLocomotive.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Шаг"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_drawningLocomotive == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (comboBoxStrategy.Enabled)
|
|
||||||
{
|
|
||||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
||||||
{
|
|
||||||
0 => new MoveToCenter(),
|
|
||||||
1 => new MoveToBorder(),
|
|
||||||
_ => null,
|
|
||||||
};
|
|
||||||
if (_strategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_strategy.SetData(new MoveableLocomotive(_drawningLocomotive),
|
|
||||||
pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
|
|
||||||
}
|
|
||||||
if (_strategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
comboBoxStrategy.Enabled = false;
|
|
||||||
_strategy.MakeStep();
|
|
||||||
Draw();
|
|
||||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
||||||
{
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
_strategy = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,140 +0,0 @@
|
|||||||
namespace WarmlyLocomotive.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Класс-стратегия перемещения объекта
|
|
||||||
/// </summary>
|
|
||||||
public abstract class AbstractStrategy
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещаемый объект
|
|
||||||
/// </summary>
|
|
||||||
private IMoveableObject? _moveableObject;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Статус перемещения
|
|
||||||
/// </summary>
|
|
||||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина поля
|
|
||||||
/// </summary>
|
|
||||||
protected int FieldWidth { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Высота поля
|
|
||||||
/// </summary>
|
|
||||||
protected int FieldHeight { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Статус перемещения
|
|
||||||
/// </summary>
|
|
||||||
public StrategyStatus GetStatus() { return _state; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Установка данных
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
|
||||||
/// <param name="width">Ширина поля</param>
|
|
||||||
/// <param name="height">Высота поля</param>
|
|
||||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
|
||||||
{
|
|
||||||
if (moveableObject == null)
|
|
||||||
{
|
|
||||||
_state = StrategyStatus.NotInit;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_state = StrategyStatus.InProgress;
|
|
||||||
_moveableObject = moveableObject;
|
|
||||||
FieldWidth = width;
|
|
||||||
FieldHeight = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения
|
|
||||||
/// </summary>
|
|
||||||
public void MakeStep()
|
|
||||||
{
|
|
||||||
if (_state != StrategyStatus.InProgress)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsTargetDestinaion())
|
|
||||||
{
|
|
||||||
_state = StrategyStatus.Finish;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MoveToTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение влево
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вправо
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
|
|
||||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вверх
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение вниз
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Параметры объекта
|
|
||||||
/// </summary>
|
|
||||||
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected int? GetStep()
|
|
||||||
{
|
|
||||||
if (_state != StrategyStatus.InProgress)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _moveableObject?.GetStep;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение к цели
|
|
||||||
/// </summary>
|
|
||||||
protected abstract void MoveToTarget();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Достигнута ли цель
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected abstract bool IsTargetDestinaion();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Попытка перемещения в требуемом направлении
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="movementDirection">Направление</param>
|
|
||||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
|
||||||
private bool MoveTo(MovementDirection movementDirection)
|
|
||||||
{
|
|
||||||
if (_state != StrategyStatus.InProgress)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
namespace WarmlyLocomotive.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Интерфейс для работы с перемещаемым объектом
|
|
||||||
/// </summary>
|
|
||||||
public interface IMoveableObject
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Получение координаты объекта
|
|
||||||
/// </summary>
|
|
||||||
ObjectParameters? GetObjectPosition { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг объекта
|
|
||||||
/// </summary>
|
|
||||||
int GetStep { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Попытка переместить объект в указанном направлении
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction">Направление</param>
|
|
||||||
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
|
||||||
bool TryMoveObject(MovementDirection direction);
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
namespace WarmlyLocomotive.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Стратегия перемещения объекта в правый кран экрана
|
|
||||||
/// </summary>
|
|
||||||
public class MoveToBorder : AbstractStrategy
|
|
||||||
{
|
|
||||||
protected override bool IsTargetDestinaion()
|
|
||||||
{
|
|
||||||
ObjectParameters? objParams = GetObjectParameters;
|
|
||||||
if (objParams == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth &&
|
|
||||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void MoveToTarget()
|
|
||||||
{
|
|
||||||
ObjectParameters? objParams = GetObjectParameters;
|
|
||||||
|
|
||||||
if (objParams == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
|
|
||||||
|
|
||||||
if (Math.Abs(diffX) > GetStep())
|
|
||||||
{
|
|
||||||
if (diffX > 0)
|
|
||||||
{
|
|
||||||
MoveLeft();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MoveRight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight;
|
|
||||||
|
|
||||||
if (Math.Abs(diffY) > GetStep())
|
|
||||||
{
|
|
||||||
if (diffY > 0)
|
|
||||||
{
|
|
||||||
MoveUp();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MoveDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
namespace WarmlyLocomotive.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Стратегия перемещения объекта в центр экрана
|
|
||||||
/// </summary>
|
|
||||||
public class MoveToCenter : AbstractStrategy
|
|
||||||
{
|
|
||||||
protected override bool IsTargetDestinaion()
|
|
||||||
{
|
|
||||||
ObjectParameters? objParams = GetObjectParameters;
|
|
||||||
|
|
||||||
if (objParams == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
|
||||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void MoveToTarget()
|
|
||||||
{
|
|
||||||
ObjectParameters? objParams = GetObjectParameters;
|
|
||||||
|
|
||||||
if (objParams == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
|
||||||
|
|
||||||
if (Math.Abs(diffX) > GetStep())
|
|
||||||
{
|
|
||||||
if (diffX > 0)
|
|
||||||
{
|
|
||||||
MoveLeft();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MoveRight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
|
||||||
|
|
||||||
if (Math.Abs(diffY) > GetStep())
|
|
||||||
{
|
|
||||||
if (diffY > 0)
|
|
||||||
{
|
|
||||||
MoveUp();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MoveDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
using WarmlyLocomotive.Drawnings;
|
|
||||||
|
|
||||||
namespace WarmlyLocomotive.MovementStrategy;
|
|
||||||
|
|
||||||
// <summary>
|
|
||||||
/// Класс-реализация IMoveableObject с использованием DrawningLocomotive
|
|
||||||
/// </summary>
|
|
||||||
public class MoveableLocomotive : IMoveableObject
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Поле-объект класса DrawningLocomotive или его наследника
|
|
||||||
/// </summary>
|
|
||||||
private readonly DrawningLocomotive? _locomotive = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="locomotive">Объект класса DrawningLocomotive</param>
|
|
||||||
public MoveableLocomotive(DrawningLocomotive locomotive)
|
|
||||||
{
|
|
||||||
_locomotive = locomotive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectParameters? GetObjectPosition
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_locomotive == null || _locomotive.EntityLocomotive == null || !_locomotive.GetPosX.HasValue || !_locomotive.GetPosY.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new ObjectParameters(_locomotive.GetPosX.Value, _locomotive.GetPosY.Value, _locomotive.GetWidth, _locomotive.GetHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int GetStep => (int)(_locomotive?.EntityLocomotive?.Step ?? 0);
|
|
||||||
|
|
||||||
public bool TryMoveObject(MovementDirection direction)
|
|
||||||
{
|
|
||||||
if (_locomotive == null || _locomotive.EntityLocomotive == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return _locomotive.MoveTransport(GetDirectionType(direction));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Конвертация из MovementDirection в DirectionType
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction">MovementDirection</param>
|
|
||||||
/// <returns>DirectionType</returns>
|
|
||||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
|
||||||
{
|
|
||||||
return direction switch
|
|
||||||
{
|
|
||||||
MovementDirection.Left => DirectionType.Left,
|
|
||||||
MovementDirection.Right => DirectionType.Right,
|
|
||||||
MovementDirection.Up => DirectionType.Up,
|
|
||||||
MovementDirection.Down => DirectionType.Down,
|
|
||||||
_ => DirectionType.Unknow,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
namespace WarmlyLocomotive.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Параметры-координаты объекта
|
|
||||||
/// </summary>
|
|
||||||
public class ObjectParameters
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Координата X
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _x;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Координата Y
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _y;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ширина объекта
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _width;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Высота объекта
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _height;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Левая граница
|
|
||||||
/// </summary>
|
|
||||||
public int LeftBorder => _x;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Верхняя граница
|
|
||||||
/// </summary>
|
|
||||||
public int TopBorder => _y;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Правая граница
|
|
||||||
/// </summary>
|
|
||||||
public int RightBorder => _x + _width;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Нижняя граница
|
|
||||||
/// </summary>
|
|
||||||
public int DownBorder => _y + _height;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Середина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Середина объекта
|
|
||||||
/// </summary>
|
|
||||||
public int ObjectMiddleVertical => _y + _height / 2;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">Координата X</param>
|
|
||||||
/// <param name="y">Координата Y</param>
|
|
||||||
/// <param name="width">Ширина объекта</param>
|
|
||||||
/// <param name="height">Высота объекта</param>
|
|
||||||
public ObjectParameters(int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
_x = x;
|
|
||||||
_y = y;
|
|
||||||
_width = width;
|
|
||||||
_height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
namespace WarmlyLocomotive.MovementStrategy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Статус выполнения операции перемещения
|
|
||||||
/// </summary>
|
|
||||||
public enum StrategyStatus
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Все готово к началу
|
|
||||||
/// </summary>
|
|
||||||
NotInit,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Выполняется
|
|
||||||
/// </summary>
|
|
||||||
InProgress,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Завершено
|
|
||||||
/// </summary>
|
|
||||||
Finish
|
|
||||||
}
|
|
31
lab_1/lab_1.sln
Normal file
31
lab_1/lab_1.sln
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.7.34024.191
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab_1", "lab_1\lab_1.vcxproj", "{88F6E495-8313-457C-8B37-34F8848D95C3}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{88F6E495-8313-457C-8B37-34F8848D95C3}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{88F6E495-8313-457C-8B37-34F8848D95C3}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{88F6E495-8313-457C-8B37-34F8848D95C3}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{88F6E495-8313-457C-8B37-34F8848D95C3}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{88F6E495-8313-457C-8B37-34F8848D95C3}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{88F6E495-8313-457C-8B37-34F8848D95C3}.Release|x64.Build.0 = Release|x64
|
||||||
|
{88F6E495-8313-457C-8B37-34F8848D95C3}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{88F6E495-8313-457C-8B37-34F8848D95C3}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {AFE935BC-7614-4661-8922-8FCC085EA88C}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
50
lab_1/lab_1/Lab_1.c
Normal file
50
lab_1/lab_1/Lab_1.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
//ñîçäàíèå ñòðóêòóðû
|
||||||
|
struct medicine {
|
||||||
|
char name[10];
|
||||||
|
int index;
|
||||||
|
struct medicine* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct medicine* first = NULL;
|
||||||
|
|
||||||
|
void sortMedicine(struct medicine* list);
|
||||||
|
|
||||||
|
struct medicine* create(struct medicine* end, int n, char* p) {
|
||||||
|
struct medicine* tmp;
|
||||||
|
|
||||||
|
tmp = (struct medicine*)malloc(sizeof(struct medicine));
|
||||||
|
|
||||||
|
tmp->index = n;
|
||||||
|
strcpy(tmp->name, p);
|
||||||
|
|
||||||
|
if (end == NULL) {
|
||||||
|
tmp->next = NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tmp->next = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void print(struct medicine *p) {
|
||||||
|
do {
|
||||||
|
printf("%10s (%d) -> ", p->name, p->index);
|
||||||
|
} while ((p = p->next) != NULL);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
first = NULL;
|
||||||
|
printList();
|
||||||
|
addElement("bimbim", 2);
|
||||||
|
printList();
|
||||||
|
}
|
135
lab_1/lab_1/lab_1.vcxproj
Normal file
135
lab_1/lab_1/lab_1.vcxproj
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{88f6e495-8313-457c-8b37-34f8848d95c3}</ProjectGuid>
|
||||||
|
<RootNamespace>lab1</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Lab_1.c" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
22
lab_1/lab_1/lab_1.vcxproj.filters
Normal file
22
lab_1/lab_1/lab_1.vcxproj.filters
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Исходные файлы">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы заголовков">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы ресурсов">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Lab_1.c">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
Loading…
Reference in New Issue
Block a user