Добавление родителей и ввод конструкторов

This commit is contained in:
vkobi 2024-03-12 19:32:46 +04:00
parent e71e32c73b
commit 7b607d826f
11 changed files with 267 additions and 387 deletions

View File

@ -1,4 +1,4 @@
namespace WarmlyLocomotive;
namespace WarmlyLocomotive.Drawnings;
/// <summary>
/// Направление перемещения
/// </summary>

View File

@ -1,14 +1,13 @@
namespace WarmlyLocomotive;
using WarmlyLocomotive.Entities;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningWarmlyLocomotive
namespace WarmlyLocomotive.Drawnings;
public class DrawningLocomotive
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityWarmlyLocomotive? EntityWarmlyLocomotive { get; private set; }
public EntityLocomotive? EntityLocomotive { get; protected set; }
/// <summary>
/// Ширина окна
/// </summary>
@ -20,38 +19,53 @@ public class DrawningWarmlyLocomotive
/// <summary>
/// Левая координата прорисовки паровоза
/// </summary>
private int? _startPosX;
protected int? _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки паровоза
/// </summary>
private int? _startPosY;
protected int? _startPosY;
/// <summary>
/// Ширина прорисовки паровоза
/// </summary>
private readonly int _drawningWarmlyLocomotiveWidth = 130;
private readonly int _drawningLocomotiveWidth = 130;
/// <summary>
/// Высота прорисовки паровоза
/// </summary>
private readonly int _drawningWarmlyLocomotiveHeight = 50;
private readonly int _drawningLocomotiveHeight = 40;
/// <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 void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool chimney, bool compartment, bool indicatingLine)
private DrawningLocomotive()
{
EntityWarmlyLocomotive = new EntityWarmlyLocomotive();
EntityWarmlyLocomotive.Init(speed, weight, bodyColor, additionalColor, chimney, compartment, indicatingLine);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = 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>
@ -63,7 +77,7 @@ public class DrawningWarmlyLocomotive
// TODO проверка, что объект "влезает" в размеры поля
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
if (width > _drawningWarmlyLocomotiveWidth && height > _drawningWarmlyLocomotiveHeight)
if (width > _drawningLocomotiveWidth && height > _drawningLocomotiveHeight)
{
_pictureWidth = width;
_pictureHeight = height;
@ -75,14 +89,14 @@ public class DrawningWarmlyLocomotive
if (_startPosY.Value < 0) { _startPosY = 0; }
if (_startPosX.Value + _drawningWarmlyLocomotiveWidth > _pictureWidth)
if (_startPosX.Value + _drawningLocomotiveWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningWarmlyLocomotiveWidth;
_startPosX = _pictureWidth - _drawningLocomotiveWidth;
}
if (_startPosY.Value + _drawningWarmlyLocomotiveHeight > _pictureHeight)
if (_startPosY.Value + _drawningLocomotiveHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningWarmlyLocomotiveHeight;
_startPosY = _pictureHeight - _drawningLocomotiveHeight;
}
}
return true;
@ -110,14 +124,14 @@ public class DrawningWarmlyLocomotive
if (_startPosY.Value < 0) { _startPosY = 0; }
if (_startPosX.Value < 0) { _startPosX = 0; }
if (_startPosX.Value + _drawningWarmlyLocomotiveWidth > _pictureWidth)
if (_startPosX.Value + _drawningLocomotiveWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningWarmlyLocomotiveWidth;
_startPosX = _pictureWidth - _drawningLocomotiveWidth;
}
if (_startPosY.Value + _drawningWarmlyLocomotiveHeight > _pictureHeight)
if (_startPosY.Value + _drawningLocomotiveHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningWarmlyLocomotiveHeight;
_startPosY = _pictureHeight - _drawningLocomotiveHeight;
}
}
}
@ -129,7 +143,7 @@ public class DrawningWarmlyLocomotive
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityWarmlyLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
@ -137,30 +151,30 @@ public class DrawningWarmlyLocomotive
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityWarmlyLocomotive.Step > 0)
if (_startPosX.Value - EntityLocomotive.Step > 0)
{
_startPosX -= (int)EntityWarmlyLocomotive.Step;
_startPosX -= (int)EntityLocomotive.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityWarmlyLocomotive.Step > 0)
if (_startPosY.Value - EntityLocomotive.Step > 0)
{
_startPosY -= (int)EntityWarmlyLocomotive.Step;
_startPosY -= (int)EntityLocomotive.Step;
}
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + EntityWarmlyLocomotive.Step + _drawningWarmlyLocomotiveWidth < _pictureWidth)
if (_startPosX.Value + EntityLocomotive.Step + _drawningLocomotiveWidth < _pictureWidth)
{
_startPosX += (int)EntityWarmlyLocomotive.Step;
_startPosX += (int)EntityLocomotive.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + EntityWarmlyLocomotive.Step + _drawningWarmlyLocomotiveHeight < _pictureHeight)
if (_startPosY.Value + EntityLocomotive.Step + _drawningLocomotiveHeight < _pictureHeight)
{
_startPosY += (int)EntityWarmlyLocomotive.Step;
_startPosY += (int)EntityLocomotive.Step;
}
return true;
default:
@ -172,88 +186,66 @@ public class DrawningWarmlyLocomotive
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (EntityWarmlyLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityLocomotive == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
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 + 20, 120, 15);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 5, 110, 15);
g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value + 15, 120, 15);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 0, 110, 15);
//кузов
Brush bk = new SolidBrush(EntityWarmlyLocomotive.BodyColor);
g.FillRectangle(bk, _startPosX.Value + 0, _startPosY.Value + 20, 120, 15);
g.FillRectangle(bk, _startPosX.Value + 10, _startPosY.Value + 5, 110, 15);
Brush bk = new SolidBrush(EntityLocomotive.BodyColor);
g.FillRectangle(bk, _startPosX.Value + 0, _startPosY.Value + 15, 120, 15);
g.FillRectangle(bk, _startPosX.Value + 10, _startPosY.Value + 0, 110, 15);
//дверь
g.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 10, 10, 22);
g.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 5, 10, 22);
//нос
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 20, _startPosX.Value + 10, _startPosY.Value + 5);
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 15, _startPosX.Value + 10, _startPosY.Value + 0);
//стекла
Pen penBlue = new(Color.LightBlue);
Brush wt = new SolidBrush(Color.White);
g.FillRectangle(wt, _startPosX.Value + 15, _startPosY.Value + 7, 10, 10);
g.DrawRectangle(penBlue, _startPosX.Value + 15, _startPosY.Value + 7, 10, 10);
g.FillRectangle(wt, _startPosX.Value + 30, _startPosY.Value + 7, 10, 10);
g.DrawRectangle(penBlue, _startPosX.Value + 30, _startPosY.Value + 7, 10, 10);
g.FillRectangle(wt, _startPosX.Value + 107, _startPosY.Value + 7, 10, 10);
g.DrawRectangle(penBlue, _startPosX.Value + 107, _startPosY.Value + 7, 10, 10);
g.FillRectangle(wt, _startPosX.Value + 15, _startPosY.Value + 2, 10, 10);
g.DrawRectangle(penBlue, _startPosX.Value + 15, _startPosY.Value + 2, 10, 10);
g.FillRectangle(wt, _startPosX.Value + 30, _startPosY.Value + 2, 10, 10);
g.DrawRectangle(penBlue, _startPosX.Value + 30, _startPosY.Value + 2, 10, 10);
g.FillRectangle(wt, _startPosX.Value + 107, _startPosY.Value + 2, 10, 10);
g.DrawRectangle(penBlue, _startPosX.Value + 107, _startPosY.Value + 2, 10, 10);
//треугольники низ
Brush br = new SolidBrush(Color.Black);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 35, 30, 5);
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 35, _startPosX.Value + 0, _startPosY.Value + 40);
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 40, _startPosX.Value + 10, _startPosY.Value + 40);
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 35, 30, 5);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 30, 5);
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 30, _startPosX.Value + 0, _startPosY.Value + 35);
g.DrawLine(pen, _startPosX.Value + 0, _startPosY.Value + 35, _startPosX.Value + 10, _startPosY.Value + 35);
g.FillRectangle(br, _startPosX.Value + 10, _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 + 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 + 120, _startPosY.Value + 7, 5, 25);
g.FillRectangle(br, _startPosX.Value + 120, _startPosY.Value + 7, 5, 25);
g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value + 2, 5, 25);
g.FillRectangle(br, _startPosX.Value + 120, _startPosY.Value + 2, 5, 25);
//колеса
g.FillEllipse(wt, _startPosX.Value + 10, _startPosY.Value + 35, 12, 11);
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 12, 11);
g.FillEllipse(wt, _startPosX.Value + 10, _startPosY.Value + 30, 12, 11);
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 30, 12, 11);
g.FillEllipse(wt, _startPosX.Value + 30, _startPosY.Value + 35, 12, 11);
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 35, 12, 11);
g.FillEllipse(wt, _startPosX.Value + 30, _startPosY.Value + 30, 12, 11);
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 30, 12, 11);
g.FillEllipse(wt, _startPosX.Value + 80, _startPosY.Value + 35, 12, 11);
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 12, 11);
g.FillEllipse(wt, _startPosX.Value + 100, _startPosY.Value + 35, 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);
g.FillEllipse(wt, _startPosX.Value + 80, _startPosY.Value + 30, 12, 11);
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 30, 12, 11);
}
g.FillEllipse(wt, _startPosX.Value + 100, _startPosY.Value + 30, 12, 11);
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 30, 12, 11);
}
}

View File

@ -0,0 +1,63 @@
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);
}
}
}

View File

@ -0,0 +1,40 @@
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;
}
}

View File

@ -1,21 +1,11 @@
namespace WarmlyLocomotive;
namespace WarmlyLocomotive.Entities;
/// <summary>
/// Класс-сущность "тепловоз"
/// </summary>
public class EntityWarmlyLocomotive
public class EntityWarmlyLocomotive : 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>
@ -32,12 +22,9 @@ public class EntityWarmlyLocomotive
/// Признак (опция) наличия гоночной полосы
/// </summary>
public bool IndicatingLine { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса тепловоза
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес тепловоза</param>
@ -46,12 +33,8 @@ public class EntityWarmlyLocomotive
/// <param name="chimney">Признак наличия трубы</param>
/// <param name="compartment">Признак наличия топливного отсека</param>
/// <param name="indicatingLine">Признак наличия обозначающей полосы</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool chimney, bool compartment, bool indicatingLine)
public EntityWarmlyLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, bool chimney, bool compartment, bool indicatingLine) : base(speed, weight, bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Chimney = chimney;
Compartment = compartment;

View File

@ -34,6 +34,7 @@
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonCreateLocomotive = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit();
SuspendLayout();
//
@ -51,9 +52,9 @@
buttonCreateWarmlyLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateWarmlyLocomotive.Location = new Point(12, 409);
buttonCreateWarmlyLocomotive.Name = "buttonCreateWarmlyLocomotive";
buttonCreateWarmlyLocomotive.Size = new Size(94, 29);
buttonCreateWarmlyLocomotive.Size = new Size(156, 29);
buttonCreateWarmlyLocomotive.TabIndex = 1;
buttonCreateWarmlyLocomotive.Text = "создать";
buttonCreateWarmlyLocomotive.Text = "создать локомотив";
buttonCreateWarmlyLocomotive.UseVisualStyleBackColor = true;
buttonCreateWarmlyLocomotive.Click += ButtonCreateWarmlyLocomotive_Click;
//
@ -105,11 +106,23 @@
buttonUp.UseVisualStyleBackColor = true;
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;
//
// FormWarmlyLocomotive
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonCreateLocomotive);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
@ -130,5 +143,6 @@
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
private Button buttonCreateLocomotive;
}
}

View File

@ -1,4 +1,6 @@
namespace WarmlyLocomotive;
using WarmlyLocomotive.Drawnings;
namespace WarmlyLocomotive;
/// <summary>
/// Форма работы с объектом "тепловоз"
@ -8,7 +10,7 @@ public partial class FormWarmlyLocomotive : Form
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
private DrawningLocomotive? _drawningLocomotive;
/// <summary>
/// Конструктор формы
@ -23,35 +25,57 @@ public partial class FormWarmlyLocomotive : Form
/// </summary>
private void Draw()
{
if (_drawningWarmlyLocomotive == null)
if (_drawningLocomotive == null)
{
return;
}
Bitmap bmp = new(pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningWarmlyLocomotive.DrawTransport(gr);
_drawningLocomotive.DrawTransport(gr);
pictureBoxWarmlyLocomotive.Image = bmp;
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateWarmlyLocomotive_Click(object sender, EventArgs e)
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
Random random = new();
_drawningWarmlyLocomotive = new DrawningWarmlyLocomotive();
_drawningWarmlyLocomotive.Init(random.Next(100, 300), random.Next(1000, 3000),
switch (type)
{
case nameof(DrawningLocomotive):
_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)));
break;
case nameof(DrawningWarmlyLocomotive):
_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)));
_drawningWarmlyLocomotive.SetPictureSize(pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
break;
default:
return;
}
_drawningLocomotive.SetPictureSize(pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
_drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
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>
@ -59,27 +83,29 @@ public partial class FormWarmlyLocomotive : Form
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningWarmlyLocomotive == null)
if (_drawningLocomotive == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result = _drawningWarmlyLocomotive.MoveTransport(DirectionType.Up);
result = _drawningLocomotive.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawningWarmlyLocomotive.MoveTransport(DirectionType.Down);
result = _drawningLocomotive.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _drawningWarmlyLocomotive.MoveTransport(DirectionType.Left);
result = _drawningLocomotive.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawningWarmlyLocomotive.MoveTransport(DirectionType.Right);
result = _drawningLocomotive.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();

View File

@ -1,31 +0,0 @@

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

View File

@ -1,50 +0,0 @@
#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();
}

View File

@ -1,135 +0,0 @@
<?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>

View File

@ -1,22 +0,0 @@
<?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>