PIbd-11 Tarasov V.D. LabWork 2 Simple #2

Closed
ENDORFIT wants to merge 3 commits from LabWork_2 into LabWork_1
27 changed files with 907 additions and 231 deletions

View File

@ -33,7 +33,10 @@
buttonMove_Left = new Button();
buttonMove_Up = new Button();
pictureBoxMonorail = new PictureBox();
buttonCreateModernMonorail = new Button();
buttonCreateMonorail = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit();
SuspendLayout();
//
@ -42,10 +45,9 @@
buttonMove_Right.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonMove_Right.BackgroundImage = Properties.Resources.ArrowRight;
buttonMove_Right.BackgroundImageLayout = ImageLayout.Stretch;
buttonMove_Right.Location = new Point(875, 569);
buttonMove_Right.Margin = new Padding(3, 4, 3, 4);
buttonMove_Right.Location = new Point(766, 427);
buttonMove_Right.Name = "buttonMove_Right";
buttonMove_Right.Size = new Size(40, 47);
buttonMove_Right.Size = new Size(35, 35);
buttonMove_Right.TabIndex = 0;
buttonMove_Right.UseVisualStyleBackColor = true;
buttonMove_Right.Click += ButtonMove_Click;
@ -55,10 +57,9 @@
buttonMove_Down.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonMove_Down.BackgroundImage = Properties.Resources.ArrowDown;
buttonMove_Down.BackgroundImageLayout = ImageLayout.Stretch;
buttonMove_Down.Location = new Point(829, 569);
buttonMove_Down.Margin = new Padding(3, 4, 3, 4);
buttonMove_Down.Location = new Point(725, 427);
buttonMove_Down.Name = "buttonMove_Down";
buttonMove_Down.Size = new Size(40, 47);
buttonMove_Down.Size = new Size(35, 35);
buttonMove_Down.TabIndex = 1;
buttonMove_Down.UseVisualStyleBackColor = true;
buttonMove_Down.Click += ButtonMove_Click;
@ -68,10 +69,9 @@
buttonMove_Left.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonMove_Left.BackgroundImage = Properties.Resources.ArrowLeft;
buttonMove_Left.BackgroundImageLayout = ImageLayout.Stretch;
buttonMove_Left.Location = new Point(782, 569);
buttonMove_Left.Margin = new Padding(3, 4, 3, 4);
buttonMove_Left.Location = new Point(684, 427);
buttonMove_Left.Name = "buttonMove_Left";
buttonMove_Left.Size = new Size(40, 47);
buttonMove_Left.Size = new Size(35, 35);
buttonMove_Left.TabIndex = 2;
buttonMove_Left.UseVisualStyleBackColor = true;
buttonMove_Left.Click += ButtonMove_Click;
@ -81,10 +81,9 @@
buttonMove_Up.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonMove_Up.BackgroundImage = Properties.Resources.ArrowUp;
buttonMove_Up.BackgroundImageLayout = ImageLayout.Stretch;
buttonMove_Up.Location = new Point(829, 515);
buttonMove_Up.Margin = new Padding(3, 4, 3, 4);
buttonMove_Up.Location = new Point(725, 386);
buttonMove_Up.Name = "buttonMove_Up";
buttonMove_Up.Size = new Size(40, 47);
buttonMove_Up.Size = new Size(35, 35);
buttonMove_Up.TabIndex = 3;
buttonMove_Up.UseVisualStyleBackColor = true;
buttonMove_Up.Click += ButtonMove_Click;
@ -94,36 +93,67 @@
pictureBoxMonorail.Dock = DockStyle.Fill;
pictureBoxMonorail.ImageLocation = "";
pictureBoxMonorail.Location = new Point(0, 0);
pictureBoxMonorail.Margin = new Padding(3, 4, 3, 4);
pictureBoxMonorail.Name = "pictureBoxMonorail";
pictureBoxMonorail.Size = new Size(929, 632);
pictureBoxMonorail.Size = new Size(813, 474);
pictureBoxMonorail.TabIndex = 4;
pictureBoxMonorail.TabStop = false;
//
// buttonCreateModernMonorail
//
buttonCreateModernMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateModernMonorail.Location = new Point(12, 439);
buttonCreateModernMonorail.Name = "buttonCreateModernMonorail";
buttonCreateModernMonorail.Size = new Size(220, 23);
buttonCreateModernMonorail.TabIndex = 5;
buttonCreateModernMonorail.Text = "Создать современный монорельс";
buttonCreateModernMonorail.UseVisualStyleBackColor = true;
buttonCreateModernMonorail.Click += ButtonCreateModernMonorail_Click;
//
// buttonCreateMonorail
//
buttonCreateMonorail.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateMonorail.Location = new Point(14, 585);
buttonCreateMonorail.Margin = new Padding(3, 4, 3, 4);
buttonCreateMonorail.Location = new Point(238, 439);
buttonCreateMonorail.Name = "buttonCreateMonorail";
buttonCreateMonorail.Size = new Size(86, 31);
buttonCreateMonorail.TabIndex = 5;
buttonCreateMonorail.Text = "Создать";
buttonCreateMonorail.Size = new Size(194, 23);
buttonCreateMonorail.TabIndex = 6;
buttonCreateMonorail.Text = "Создать монорельс";
buttonCreateMonorail.UseVisualStyleBackColor = true;
buttonCreateMonorail.Click += ButtonCreateMonorail_Click;
buttonCreateMonorail.Click += buttonCreateMonorail_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
comboBoxStrategy.Location = new Point(680, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(121, 23);
comboBoxStrategy.TabIndex = 7;
//
// buttonStrategyStep
//
buttonStrategyStep.Location = new Point(704, 41);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(75, 23);
buttonStrategyStep.TabIndex = 8;
buttonStrategyStep.Text = "Шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
buttonStrategyStep.Click += buttonStrategyStep_Click;
//
// FormMonorail
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(929, 632);
ClientSize = new Size(813, 474);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateMonorail);
Controls.Add(buttonCreateModernMonorail);
Controls.Add(buttonMove_Up);
Controls.Add(buttonMove_Left);
Controls.Add(buttonMove_Down);
Controls.Add(buttonMove_Right);
Controls.Add(pictureBoxMonorail);
Margin = new Padding(3, 4, 3, 4);
Name = "FormMonorail";
Text = "Монорельс";
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).EndInit();
@ -137,6 +167,9 @@
private Button buttonMove_Left;
private Button buttonMove_Up;
private PictureBox pictureBoxMonorail;
private Button buttonCreateModernMonorail;
private Button buttonCreateMonorail;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
}

View File

@ -0,0 +1,163 @@
using ProjectMonorail.Scripts.Monorail.Drawnings;
using ProjectMonorail.Scripts.Monorail.MovementStrategy;
namespace ProjectMonorail
{
/// <summary>
/// Форма работы с объектом "Монорельс"
/// </summary>
public partial class FormMonorail : Form
{
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawingMonorail? _drawningMonorail;
/// <summary>
/// Стратегия перемещения
/// </summary>
private AbstractStrategy? _strategy;
/// <summary>
/// Конструктор формы
/// </summary>
public FormMonorail()
{
InitializeComponent();
_strategy = null;
}
/// <summary>
/// Метод для прорисовки автомобиля
/// </summary>
private void Draw()
{
if (_drawningMonorail == null) return;
Bitmap bmp = new(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningMonorail.DrawTransport(gr);
pictureBoxMonorail.Image = bmp;
}
/// <summary>
/// Обработка кнопок перемешения
/// </summary>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningMonorail == null) return;
string name = ((Button)sender).Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonMove_Up":
result = _drawningMonorail.MoveTransport(DirectionType.Up);
break;
case "buttonMove_Down":
result = _drawningMonorail.MoveTransport(DirectionType.Down);
break;
case "buttonMove_Right":
result = _drawningMonorail.MoveTransport(DirectionType.Right);
break;
case "buttonMove_Left":
result = _drawningMonorail.MoveTransport(DirectionType.Left);
break;
}
if (result) Draw();
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создоваемого объекта</param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawingMonorail):
_drawningMonorail = new DrawingMonorail(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(DrawingModernMonorail):
bool randomTrack = Convert.ToBoolean(random.Next(0, 2));
_drawningMonorail = new DrawingModernMonorail(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)),
randomTrack,
(randomTrack ? Convert.ToBoolean(random.Next(0, 2)) : true));
break;
default:
return;
}
_drawningMonorail.SetPictureSize(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
_drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Создать современный монорельс"
/// </summary>
private void ButtonCreateModernMonorail_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawingModernMonorail));
}
/// <summary>
/// Обработка нажатия кнопки "Создать монорельс"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateMonorail_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawingMonorail));
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawningMonorail == null) return;
if (comboBoxStrategy.Enabled)
{
_strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToRightDownBorder(),
_ => null,
};
if (_strategy == null)
{
return;
}
_strategy.SetData(new MoveableMonorail(_drawningMonorail), pictureBoxMonorail.Width, pictureBoxMonorail.Height);
}
if (_strategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == StrategyStatus.Finish)
{
comboBoxStrategy.Enabled = true;
_strategy = null;
}
}
}
}

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 77 KiB

View File

@ -0,0 +1,33 @@
namespace ProjectMonorail.Scripts.Monorail.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
}
}

View File

@ -0,0 +1,137 @@
using System.Drawing.Drawing2D;
using ProjectMonorail.Scripts.Monorail.Entities;
namespace ProjectMonorail.Scripts.Monorail.Drawnings
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingModernMonorail : DrawingMonorail
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="monorailTrack">Признак наличия монорельсового пути</param>
/// <param name="cabin">Признак наличия кабиныы</param>
public DrawingModernMonorail(int speed, double weight, Color bodyColor, Color additionalColor, bool monorailTrack, bool cabin) : base((cabin ? 170 : 90), 40)
{
EntityMonorail = new EntityModernMonorail(speed, weight, bodyColor, additionalColor, monorailTrack, cabin);
}
/// <summary>
/// Прорисовка объекта
/// </summary>
public override void DrawTransport(Graphics g)
{
if (EntityMonorail == null || EntityMonorail is not EntityModernMonorail entityModernMonorail || !_startPositionX.HasValue || !_startPositionY.HasValue) return;
Pen pen_Body = new Pen(EntityMonorail.BodyColor, 1.5f);
Pen pen_Additional = new Pen(entityModernMonorail.AdditionalColor, 1.5f);
Brush brush_Body = new SolidBrush(EntityMonorail.BodyColor);
Brush brush_Additional = new SolidBrush(entityModernMonorail.AdditionalColor);
base.DrawTransport(g);
//Перекраска окон первого монорельса
g.DrawRectangle(pen_Additional, _startPositionX.Value + 14, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Additional, _startPositionX.Value + 21, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Additional, _startPositionX.Value + 70, _startPositionY.Value + 2, 5, 6);
if (entityModernMonorail.MonorailTrack)
{
if (entityModernMonorail.Cabin)
{
g.FillRectangle(brush_Additional, _startPositionX.Value, _startPositionY.Value + 35, 170, 5);
}
else
{
g.FillRectangle(brush_Additional, _startPositionX.Value, _startPositionY.Value + 35, 86, 5);
}
}
//Колеса
Brush brush_White = new SolidBrush(Color.White);
g.FillEllipse(brush_White, _startPositionX.Value + 10, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value + 10, _startPositionY.Value + 30, 10, 10);
g.FillEllipse(brush_White, _startPositionX.Value + 25, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value + 25, _startPositionY.Value + 30, 10, 10);
g.FillEllipse(brush_White, _startPositionX.Value + 65, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value + 65, _startPositionY.Value + 30, 10, 10);
g.FillEllipse(brush_White, _startPositionX.Value + 50, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value + 50, _startPositionY.Value + 30, 10, 10);
if (entityModernMonorail.Cabin)
{
int offset = 170;
//Кузов монорельса
GraphicsPath pointsMonorailBody_RightBody = new GraphicsPath();
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 8 + offset, _startPositionY.Value + 10, _startPositionX.Value - 13 + offset, _startPositionY.Value);
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 13 + offset, _startPositionY.Value, _startPositionX.Value - 80 + offset, _startPositionY.Value);
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 80 + offset, _startPositionY.Value, _startPositionX.Value - 80 + offset, _startPositionY.Value + 25);
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 80 + offset, _startPositionY.Value + 25, _startPositionX.Value - 8 + offset, _startPositionY.Value + 25);
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 8 + offset, _startPositionY.Value + 25, _startPositionX.Value - 8 + offset, _startPositionY.Value + 10);
g.DrawLine(pen_Body, _startPositionX.Value - 8 + offset, _startPositionY.Value + 10, _startPositionX.Value - 30 + offset, _startPositionY.Value + 10);
g.DrawLine(pen_Body, _startPositionX.Value - 39 + offset, _startPositionY.Value + 10, _startPositionX.Value - 80 + offset, _startPositionY.Value + 10);
g.DrawPath(pen_Body, pointsMonorailBody_RightBody);
//Дверь
g.DrawRectangle(pen_Body, _startPositionX.Value - 39 + offset, _startPositionY.Value + 5, 9, 15);
//Окна
g.DrawRectangle(pen_Additional, _startPositionX.Value - 20 + offset, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Additional, _startPositionX.Value - 27 + offset, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Additional, _startPositionX.Value - 76 + offset, _startPositionY.Value + 2, 5, 6);
//Связка монорельса
g.FillRectangle(brush_Body, _startPositionX.Value - 87 + offset, _startPositionY.Value + 2, 7, 22);
//Нижняя часть монорельса
PointF[] pointsLowerPartMonorail_2_LeftSide = new PointF[8];
pointsLowerPartMonorail_2_LeftSide[0] = new PointF(_startPositionX.Value + offset, _startPositionY.Value + 30);
pointsLowerPartMonorail_2_LeftSide[1] = new PointF(_startPositionX.Value - 8 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_LeftSide[2] = new PointF(_startPositionX.Value - 72 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_LeftSide[3] = new PointF(_startPositionX.Value - 36 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_LeftSide[4] = new PointF(_startPositionX.Value - 36 + offset, _startPositionY.Value + 32);
pointsLowerPartMonorail_2_LeftSide[5] = new PointF(_startPositionX.Value - 15 + offset, _startPositionY.Value + 32);
pointsLowerPartMonorail_2_LeftSide[6] = new PointF(_startPositionX.Value - 15 + offset, _startPositionY.Value + 35);
pointsLowerPartMonorail_2_LeftSide[7] = new PointF(_startPositionX.Value + offset, _startPositionY.Value + 32);
g.FillPolygon(brush_Body, pointsLowerPartMonorail_2_LeftSide);
PointF[] pointsLowerPartMonorail_2_RightSide = new PointF[7];
pointsLowerPartMonorail_2_RightSide[0] = new PointF(_startPositionX.Value - 86 + offset, _startPositionY.Value + 30);
pointsLowerPartMonorail_2_RightSide[1] = new PointF(_startPositionX.Value - 80 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_RightSide[2] = new PointF(_startPositionX.Value - 50 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_RightSide[3] = new PointF(_startPositionX.Value - 50 + offset, _startPositionY.Value + 32);
pointsLowerPartMonorail_2_RightSide[4] = new PointF(_startPositionX.Value - 69 + offset, _startPositionY.Value + 32);
pointsLowerPartMonorail_2_RightSide[5] = new PointF(_startPositionX.Value - 79 + offset, _startPositionY.Value + 35);
pointsLowerPartMonorail_2_RightSide[6] = new PointF(_startPositionX.Value - 86 + offset, _startPositionY.Value + 32);
g.FillPolygon(brush_Body, pointsLowerPartMonorail_2_RightSide);
g.FillRectangle(brush_Body, _startPositionX.Value - 80 + offset, _startPositionY.Value + 25, 70, 3);
//Колеса
g.FillEllipse(brush_White, _startPositionX.Value - 20 + offset, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value - 20 + offset, _startPositionY.Value + 30, 10, 10);
g.FillEllipse(brush_White, _startPositionX.Value - 35 + offset, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value - 35 + offset, _startPositionY.Value + 30, 10, 10);
g.FillEllipse(brush_White, _startPositionX.Value - 75 + offset, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value - 75 + offset, _startPositionY.Value + 30, 10, 10);
g.FillEllipse(brush_White, _startPositionX.Value - 60 + offset, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value - 60 + offset, _startPositionY.Value + 30, 10, 10);
}
}
}
}

View File

@ -1,13 +1,17 @@
using System.Drawing.Drawing2D;
using ProjectMonorail.Scripts.Monorail.Entities;
using System.Drawing.Drawing2D;
namespace ProjectMonorail.Scripts.Locomative
namespace ProjectMonorail.Scripts.Monorail.Drawnings
{
public class DrawMonorail
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение базового объекта-сущности
/// </summary>
public class DrawingMonorail
Review

Имя элемента проекта не соответствует указанному в задании

Имя элемента проекта не соответствует указанному в задании
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityMonorail? EntityMonorail { get; private set; }
public EntityMonorail? EntityMonorail { get; protected set; }
/// <summary>
/// Ширина окна
@ -20,45 +24,78 @@ namespace ProjectMonorail.Scripts.Locomative
private int? _pictureHeight;
/// <summary>
/// Левая координата прорисовки автомобиля
/// Левая координата прорисовки монорельса
/// </summary>
private int? _startPositionX;
protected int? _startPositionX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// Верхняя кооридната прорисовки монорельса
/// </summary>
private int? _startPositionY;
protected int? _startPositionY;
/// <summary>
/// Ширина прорисовки автомобиля
/// Ширина прорисовки монорельса
/// </summary>
private int _drawningMonorailWidth = 110;
private readonly int _drawningMonorailWidth = 90;
/// <summary>
/// Высота прорисовки автомобиля
/// Высота прорисовки монорельса
/// </summary>
private readonly int _drawningMonorailHeight = 40;
/// <summary>
/// Инициализация свойств
/// Координаты X объекта
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="monorailTrack">Признак наличия монорельсового пути</param>
/// <param name="cabin">Признак наличия кабиныы</param>
public void Initialization(int speed, double weight, Color bodyColor, Color additionalColor, bool monorailTrack, bool cabin)
public int? GetPositionX => _startPositionX;
/// <summary>
/// Координаты Y объекта
/// </summary>
public int? GetPositionY => _startPositionY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _drawningMonorailWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _drawningMonorailHeight;
/// <summary>
/// Пустой конструкотор
/// </summary>
private DrawingMonorail()
{
EntityMonorail = new EntityMonorail();
EntityMonorail.Initialization(speed, weight, bodyColor, additionalColor, monorailTrack, cabin);
_drawningMonorailWidth = cabin ? 170 : 90;
_pictureWidth = null;
_pictureHeight = null;
_startPositionX = null;
_startPositionY = null;
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawingMonorail(int speed, double weight, Color bodyColor) : this()
{
EntityMonorail = new EntityMonorail(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наследников
/// </summary>
/// <param name="drawningMonorailWidth">Ширина прорисовки монорельса</param>
/// <param name="drawningMonorailHeight">Высота прорисовки монорельса</param>
protected DrawingMonorail(int drawningMonorailWidth, int drawningMonorailHeight) : this()
{
_drawningMonorailWidth = drawningMonorailWidth;
_drawningMonorailHeight = drawningMonorailHeight;
}
/// <summary>
/// Установка границ поля
/// </summary>
@ -69,7 +106,7 @@ namespace ProjectMonorail.Scripts.Locomative
{
// TODO проверка, что объект "влезает" в размеры поля
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
if (_drawningMonorailWidth > width || _drawningMonorailHeight > height) return false;
if (_drawningMonorailWidth > width || _drawningMonorailHeight > height) return false;
if (_startPositionX.HasValue && _startPositionY.HasValue)
{
@ -164,15 +201,13 @@ namespace ProjectMonorail.Scripts.Locomative
/// <summary>
/// Прорисовка объекта
/// </summary>
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (EntityMonorail == null || !_startPositionX.HasValue || !_startPositionY.HasValue) return;
Pen pen_Body = new Pen(EntityMonorail.BodyColor, 1.5f);
Pen pen_Additional = new Pen(EntityMonorail.AdditionalColor, 1.5f);
Brush brush_Body = new SolidBrush(EntityMonorail.BodyColor);
Brush brush_Additional = new SolidBrush(EntityMonorail.AdditionalColor);
//Кузов монорельса
@ -190,9 +225,9 @@ namespace ProjectMonorail.Scripts.Locomative
g.DrawRectangle(pen_Body, _startPositionX.Value + 30, _startPositionY.Value + 5, 9, 15);
//Окна
g.DrawRectangle(pen_Additional, _startPositionX.Value + 14, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Additional, _startPositionX.Value + 21, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Additional, _startPositionX.Value + 70, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Body, _startPositionX.Value + 14, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Body, _startPositionX.Value + 21, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Body, _startPositionX.Value + 70, _startPositionY.Value + 2, 5, 6);
//Связка монорельса
g.FillRectangle(brush_Body, _startPositionX.Value + 80, _startPositionY.Value + 2, 7, 22);
@ -220,18 +255,6 @@ namespace ProjectMonorail.Scripts.Locomative
g.FillPolygon(brush_Body, pointsLowerPartMonorail_RightSide);
g.FillRectangle(brush_Body, _startPositionX.Value + 8, _startPositionY.Value + 25, 70, 3);
if (EntityMonorail.MonorailTrack)
{
if (EntityMonorail.Cabin)
{
g.FillRectangle(brush_Additional, _startPositionX.Value, _startPositionY.Value + 35, 170, 5);
}
else
{
g.FillRectangle(brush_Additional, _startPositionX.Value, _startPositionY.Value + 35, 86, 5);
}
}
//Колеса
Brush brush_White = new SolidBrush(Color.White);
g.FillEllipse(brush_White, _startPositionX.Value + 10, _startPositionY.Value + 30, 10, 10);
@ -245,70 +268,6 @@ namespace ProjectMonorail.Scripts.Locomative
g.FillEllipse(brush_White, _startPositionX.Value + 50, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value + 50, _startPositionY.Value + 30, 10, 10);
if (EntityMonorail.Cabin)
{
int offset = 170;
//Кузов монорельса
GraphicsPath pointsMonorailBody_RightBody = new GraphicsPath();
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 8 + offset, _startPositionY.Value + 10, _startPositionX.Value - 13 + offset, _startPositionY.Value);
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 13 + offset, _startPositionY.Value, _startPositionX.Value - 80 + offset, _startPositionY.Value);
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 80 + offset, _startPositionY.Value, _startPositionX.Value - 80 + offset, _startPositionY.Value + 25);
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 80 + offset, _startPositionY.Value + 25, _startPositionX.Value - 8 + offset, _startPositionY.Value + 25);
pointsMonorailBody_RightBody.AddLine(_startPositionX.Value - 8 + offset, _startPositionY.Value + 25, _startPositionX.Value - 8 + offset, _startPositionY.Value + 10);
g.DrawLine(pen_Body, _startPositionX.Value - 8 + offset, _startPositionY.Value + 10, _startPositionX.Value - 30 + offset, _startPositionY.Value + 10);
g.DrawLine(pen_Body, _startPositionX.Value - 39 + offset, _startPositionY.Value + 10, _startPositionX.Value - 80 + offset, _startPositionY.Value + 10);
g.DrawPath(pen_Body, pointsMonorailBody_RightBody);
//Дверь
g.DrawRectangle(pen_Body, _startPositionX.Value - 39 + offset, _startPositionY.Value + 5, 9, 15);
//Окна
g.DrawRectangle(pen_Additional, _startPositionX.Value - 20 + offset, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Additional, _startPositionX.Value - 27 + offset, _startPositionY.Value + 2, 5, 6);
g.DrawRectangle(pen_Additional, _startPositionX.Value - 76 + offset, _startPositionY.Value + 2, 5, 6);
//Связка монорельса
g.FillRectangle(brush_Body, _startPositionX.Value - 87 + offset, _startPositionY.Value + 2, 7, 22);
//Нижняя часть монорельса
PointF[] pointsLowerPartMonorail_2_LeftSide = new PointF[8];
pointsLowerPartMonorail_2_LeftSide[0] = new PointF(_startPositionX.Value + offset, _startPositionY.Value + 30);
pointsLowerPartMonorail_2_LeftSide[1] = new PointF(_startPositionX.Value - 8 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_LeftSide[2] = new PointF(_startPositionX.Value - 72 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_LeftSide[3] = new PointF(_startPositionX.Value - 36 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_LeftSide[4] = new PointF(_startPositionX.Value - 36 + offset, _startPositionY.Value + 32);
pointsLowerPartMonorail_2_LeftSide[5] = new PointF(_startPositionX.Value - 15 + offset, _startPositionY.Value + 32);
pointsLowerPartMonorail_2_LeftSide[6] = new PointF(_startPositionX.Value - 15 + offset, _startPositionY.Value + 35);
pointsLowerPartMonorail_2_LeftSide[7] = new PointF(_startPositionX.Value + offset, _startPositionY.Value + 32);
g.FillPolygon(brush_Body, pointsLowerPartMonorail_2_LeftSide);
PointF[] pointsLowerPartMonorail_2_RightSide = new PointF[7];
pointsLowerPartMonorail_2_RightSide[0] = new PointF(_startPositionX.Value - 86 + offset, _startPositionY.Value + 30);
pointsLowerPartMonorail_2_RightSide[1] = new PointF(_startPositionX.Value - 80 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_RightSide[2] = new PointF(_startPositionX.Value - 50 + offset, _startPositionY.Value + 25);
pointsLowerPartMonorail_2_RightSide[3] = new PointF(_startPositionX.Value - 50 + offset, _startPositionY.Value + 32);
pointsLowerPartMonorail_2_RightSide[4] = new PointF(_startPositionX.Value - 69 + offset, _startPositionY.Value + 32);
pointsLowerPartMonorail_2_RightSide[5] = new PointF(_startPositionX.Value - 79 + offset, _startPositionY.Value + 35);
pointsLowerPartMonorail_2_RightSide[6] = new PointF(_startPositionX.Value - 86 + offset, _startPositionY.Value + 32);
g.FillPolygon(brush_Body, pointsLowerPartMonorail_2_RightSide);
g.FillRectangle(brush_Body, _startPositionX.Value - 80 + offset, _startPositionY.Value + 25, 70, 3);
//Колеса
g.FillEllipse(brush_White, _startPositionX.Value - 20 + offset, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value - 20 + offset, _startPositionY.Value + 30, 10, 10);
g.FillEllipse(brush_White, _startPositionX.Value - 35 + offset, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value - 35 + offset, _startPositionY.Value + 30, 10, 10);
g.FillEllipse(brush_White, _startPositionX.Value - 75 + offset, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value - 75 + offset, _startPositionY.Value + 30, 10, 10);
g.FillEllipse(brush_White, _startPositionX.Value - 60 + offset, _startPositionY.Value + 30, 10, 10);
g.DrawEllipse(pen_Body, _startPositionX.Value - 60 + offset, _startPositionY.Value + 30, 10, 10);
}
}
}
}

View File

@ -1,22 +1,10 @@
namespace ProjectMonorail
namespace ProjectMonorail.Scripts.Monorail.Entities
{
public class EntityMonorail
/// <summary>
/// Класс-сущности "Современный монорельс"
/// </summary>
public class EntityModernMonorail : EntityMonorail
{
/// <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,11 +20,6 @@
/// </summary>
public bool Cabin { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Инициальзация полей объекта-класса спортивного автомобиля
/// </summary>
@ -46,11 +29,8 @@
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="monorailTrack">Признак наличия монорельсового пути</param>
/// <param name="cabin">Признак наличия кабины</param>
public void Initialization(int speed, double weight, Color bodyColor, Color additionalColor, bool monorailTrack, bool cabin)
public EntityModernMonorail(int speed, double weight, Color bodyColor, Color additionalColor, bool monorailTrack, bool cabin) : base(speed, weight, bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
MonorailTrack = monorailTrack;
Cabin = cabin;

View File

@ -0,0 +1,41 @@
namespace ProjectMonorail.Scripts.Monorail.Entities
{
/// <summary>
/// Класс-сущности "Монорельс"
/// </summary>
public class EntityMonorail
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color 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 EntityMonorail(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -0,0 +1,133 @@
namespace ProjectMonorail.Scripts.Monorail.MovementStrategy
{
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;
}
}
}

View File

@ -0,0 +1,25 @@
namespace ProjectMonorail.Scripts.Monorail.MovementStrategy
{
/// <summary>
/// Интерфейс для работы с перемещаемым объектом
/// </summary>I
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);
}
}

View File

@ -0,0 +1,52 @@
namespace ProjectMonorail.Scripts.Monorail.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();
}
}
}
}
}

View File

@ -0,0 +1,36 @@
namespace ProjectMonorail.Scripts.Monorail.MovementStrategy
{
/// <summary>
/// Стратегия перемещения объекта в левый нижний угл экрана
/// </summary>
public class MoveToRightDownBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null) return false;
return objParams.RightBorder + GetStep() >= FieldWidth
&& objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null) return;
int diffX = objParams.LeftBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
MoveRight();
}
int diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,61 @@
using ProjectMonorail.Scripts.Monorail.Drawnings;
namespace ProjectMonorail.Scripts.Monorail.MovementStrategy
{
/// <summary>
/// Класс-реализация IMoveableObject с использованием DrawingMonorail
/// </summary>
public class MoveableMonorail : IMoveableObject
{
/// <summary>
/// Поле-объект класса DrawingMonorail или его наследника
/// </summary>
private readonly DrawingMonorail _drawingMonorail;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="drawingMonorail">Объект класса DrawingMonorail</param>
public MoveableMonorail(DrawingMonorail drawingMonorail)
{
_drawingMonorail = drawingMonorail;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawingMonorail == null || _drawingMonorail.EntityMonorail == null || !_drawingMonorail.GetPositionX.HasValue || !_drawingMonorail.GetPositionY.HasValue) return null;
return new ObjectParameters(_drawingMonorail.GetPositionX.Value, _drawingMonorail.GetPositionY.Value, _drawingMonorail.GetWidth, _drawingMonorail.GetHeight);
}
}
public int GetStep => (int)(_drawingMonorail?.EntityMonorail?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_drawingMonorail == null || _drawingMonorail.EntityMonorail == null)
{
return false;
}
return _drawingMonorail.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,
};
}
}
}

View File

@ -1,9 +1,9 @@
namespace ProjectMonorail.Scripts
namespace ProjectMonorail.Scripts.Monorail.MovementStrategy
{
/// <summary>
/// Направление перемещения
/// </summary>
public enum DirectionType
public enum MovementDirection
{
/// <summary>
/// Вверх
@ -24,5 +24,6 @@
/// Вправо
/// </summary>
Right = 4
}
}

View File

@ -0,0 +1,74 @@
namespace ProjectMonorail.Scripts.Monorail.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;
}
}
}

View File

@ -0,0 +1,23 @@
namespace ProjectMonorail.Scripts.Monorail.MovementStrategy
{
/// <summary>
/// Статус выполнения операции перемещения
/// </summary>
public enum StrategyStatus
{
/// <summary>
/// Все готово к началу
/// </summary>
NotInit,
/// <summary>
/// Выполняется
/// </summary>
InProgress,
/// <summary>
/// Завершено
/// </summary>
Finish
}
}

View File

@ -1,75 +0,0 @@
using ProjectMonorail.Scripts.Locomative;
namespace ProjectMonorail
{
public partial class FormMonorail : Form
{
private DrawMonorail? _drawningMonorail;
public FormMonorail()
{
InitializeComponent();
}
/// <summary>
/// Метод для прорисовки автомобиля
/// </summary>
private void Draw ()
{
if (_drawningMonorail == null) return;
Bitmap bmp = new(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningMonorail.DrawTransport(gr);
pictureBoxMonorail.Image = bmp;
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
private void ButtonCreateMonorail_Click(object sender, EventArgs e)
{
Random random = new();
_drawningMonorail = new DrawMonorail();
_drawningMonorail.Initialization(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)));
_drawningMonorail.SetPictureSize(pictureBoxMonorail.Width, pictureBoxMonorail.Height);
_drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
/// Обработка кнопок перемешения
/// </summary>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningMonorail == null) return;
string name = ((Button)sender).Name ?? string.Empty;
bool result = false;
switch(name)
{
case "buttonMove_Up":
result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Up);
break;
case "buttonMove_Down":
result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Down);
break;
case "buttonMove_Right":
result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Right);
break;
case "buttonMove_Left":
result = _drawningMonorail.MoveTransport(Scripts.DirectionType.Left);
break;
}
if (result) Draw();
}
}
}