diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/AbstractMap.cs b/LocomotivesAdvanced/LocomotivesAdvanced/AbstractMap.cs
new file mode 100644
index 0000000..1396939
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/AbstractMap.cs
@@ -0,0 +1,243 @@
+namespace WarmlyLocomotove
+{
+ internal abstract class AbstractMap
+ {
+ ///
+ /// Поле от интерфейса прорисовки
+ ///
+ private IDrawningObject _drawningObject = null;
+ ///
+ /// Массив карты
+ ///
+ protected int[,] _map = null;
+ ///
+ /// Ширина карты (графической панели)
+ ///
+ protected int _width;
+ ///
+ /// Высота карты (графической панели)
+ ///
+ protected int _height;
+ ///
+ /// Ширина ячейки
+ ///
+ protected float _size_x;
+ ///
+ /// Высота ячейки
+ ///
+ protected float _size_y;
+ protected readonly Random _random = new();
+ ///
+ /// Доступная для движения ячейка
+ ///
+ protected readonly int _freeRoad = 0;
+ ///
+ /// Недоступная для движения ячейка
+ ///
+ protected readonly int _barrier = 1;
+ ///
+ /// Наполнение графической панели
+ ///
+ /// Ширина
+ /// Высота
+ ///
+ ///
+ public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
+ {
+ _width = width;
+ _height = height;
+ _drawningObject = drawningObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+ ///
+ /// Получение координат отрисовываемого объекта в массиве
+ ///
+ ///
+ public (int Top, int Bottom, int Left, int Right) GetObjectCoordinates()
+ {
+ return
+ (
+ (int)(_drawningObject.GetCurrentPosition().Top / _size_y),
+ (int)(_drawningObject.GetCurrentPosition().Bottom / _size_y),
+ (int)(_drawningObject.GetCurrentPosition().Left / _size_x),
+ (int)(_drawningObject.GetCurrentPosition().Right / _size_x)
+ );
+ }
+ ///
+ /// Проверка возможности движения в данном направлении
+ ///
+ /// Направление
+ ///
+ private bool AbleToMove(Direction direction)
+ {
+ switch (direction)
+ {
+ case Direction.Up:
+ if (GetObjectCoordinates().Top - 1 < 0)
+ {
+ return false;
+ }
+ break;
+ case Direction.Down:
+ if (GetObjectCoordinates().Bottom + 1 > _map.GetLength(0))
+ {
+ return false;
+ }
+ break;
+ case Direction.Left:
+ if (GetObjectCoordinates().Left - 1 < 0)
+ {
+ return false;
+ }
+ break;
+ case Direction.Right:
+ if (GetObjectCoordinates().Right + 1 > _map.GetLength(1))
+ {
+ return false;
+ }
+ break;
+ }
+ for (int i = GetObjectCoordinates().Left; i <= GetObjectCoordinates().Right; i++)
+ {
+ for (int j = GetObjectCoordinates().Top; j <= GetObjectCoordinates().Bottom; j++)
+ {
+ if (i - 1 < 0 || j - 1 < 0 || i + 1 > _map.GetLength(0) || j + 1 > _map.GetLength(1))
+ {
+ return false;
+ }
+ switch (direction)
+ {
+ case Direction.Up:
+ if (_map[i, j - 1] == _barrier)
+ {
+ return false;
+ }
+ break;
+ case Direction.Down:
+ if (_map[i, j + 1] == _barrier)
+ {
+ return false;
+ }
+ break;
+ case Direction.Left:
+ if (_map[i - 1, j] == _barrier)
+ {
+ return false;
+ }
+ break;
+ case Direction.Right:
+ if (_map[i + 1, j] == _barrier)
+ {
+ return false;
+ }
+ break;
+ }
+ }
+ }
+ return true;
+ }
+ ///
+ /// Проверка возможности установить объект на карте
+ ///
+ ///
+ private bool AbleToSetObject()
+ {
+ for (int i = GetObjectCoordinates().Left; i <= GetObjectCoordinates().Right; i++)
+ {
+ for (int j = GetObjectCoordinates().Top; j <= GetObjectCoordinates().Bottom; j++)
+ {
+ if (_map[i, j] == _barrier || i < 0 || j < 0)
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ ///
+ /// Передвижение объекта по карте
+ ///
+ /// Направление
+ ///
+ public Bitmap MoveObject(Direction direction)
+ {
+ if (!AbleToMove(direction))
+ {
+ return DrawMapWithObject();
+ }
+ _drawningObject.MoveObject(direction);
+ return DrawMapWithObject();
+ }
+ ///
+ /// Создание объекта на карте
+ ///
+ /// Возможность создать объект
+ private bool SetObjectOnMap()
+ {
+ if (_drawningObject == null || _map == null)
+ {
+ return false;
+ }
+ int x = _random.Next(10, 100);
+ int y = _random.Next(10, 100);
+ _drawningObject.SetObject(x, y, _width, _height);
+ if (!AbleToSetObject())
+ {
+ return false;
+ }
+ return true;
+ }
+ ///
+ /// Отрисовка карты
+ ///
+ ///
+ private Bitmap DrawMapWithObject()
+ {
+ Bitmap bmp = new(_width, _height);
+ if (_drawningObject == null || _map == null)
+ {
+ return bmp;
+ }
+ Graphics gr = Graphics.FromImage(bmp);
+ for (int i = 0; i < _map.GetLength(0); ++i)
+ {
+ for (int j = 0; j < _map.GetLength(1); ++j)
+ {
+ if (_map[i, j] == _freeRoad)
+ {
+ DrawRoadPart(gr, i, j);
+ }
+ else if (_map[i, j] == _barrier)
+ {
+ DrawBarrierPart(gr, i, j);
+ }
+ }
+ }
+ _drawningObject.DrawningObject(gr);
+ return bmp;
+ }
+ ///
+ /// Генерация массива карты
+ ///
+ protected abstract void GenerateMap();
+ ///
+ /// Отрисовка ячейки со свободным пространством (дорогой)
+ ///
+ ///
+ ///
+ ///
+ protected abstract void DrawRoadPart(Graphics g, int i, int j);
+ ///
+ /// Отрисовка ячейки с барьером
+ ///
+ ///
+ ///
+ ///
+ protected abstract void DrawBarrierPart(Graphics g, int i, int j);
+ }
+}
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/CrossMap.cs b/LocomotivesAdvanced/LocomotivesAdvanced/CrossMap.cs
new file mode 100644
index 0000000..a2ef599
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/CrossMap.cs
@@ -0,0 +1,52 @@
+namespace WarmlyLocomotove
+{
+ ///
+ /// Карта в виде креста
+ ///
+ internal class CrossMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Red);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush roadColor = new SolidBrush(Color.Transparent);
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * _size_x, _size_y);
+ }
+ protected override void GenerateMap()
+ {
+ _map = new int[100, 100];
+ _size_x = (float)_width / _map.GetLength(0);
+ _size_y = (float)_height / _map.GetLength(1);
+ for (int i = 0; i < _map.GetLength(0); i++)
+ {
+ for (int j = 0; j < _map.GetLength(1); j++)
+ {
+ _map[i, j] = _freeRoad;
+ }
+ }
+ for (int i = 45; i < 55; i++)
+ {
+ for (int j = 15; j < 85; j++)
+ {
+ _map[i, j] = _barrier;
+ }
+ }
+ for (int i = 45; i < 55; i++)
+ {
+ for (int j = 30; j < 80; j++)
+ {
+ _map[j, i] = _barrier;
+ }
+ }
+ }
+ }
+}
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/Direction.cs b/LocomotivesAdvanced/LocomotivesAdvanced/Direction.cs
index e2e73c9..12f3478 100644
--- a/LocomotivesAdvanced/LocomotivesAdvanced/Direction.cs
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/Direction.cs
@@ -5,6 +5,10 @@
///
internal enum Direction
{
+ ///
+ /// никуда
+ ///
+ None = 0,
///
/// вверх
///
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs
index a976aab..3d488c6 100644
--- a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningLocomotive.cs
@@ -8,7 +8,7 @@
///
/// Класс-сущность
///
- public EntityLocomotive Locomotive { get; private set; }
+ public EntityLocomotive Locomotive { get; protected set; }
///
/// Класс отрисовки колёс
///
@@ -16,11 +16,11 @@
///
/// Левая координата отрисовки локомотива
///
- private float _startPosX;
+ protected float _startPosX;
///
/// Верхняя координата отрисовки локомотива
///
- private float _startPosY;
+ protected float _startPosY;
///
/// Ширина окна отрисовки
///
@@ -43,13 +43,26 @@
/// Скорость
/// Вес
/// Цвет кузова
- public void Init(int speed, float weight, Color bodyColor)
+ public DrawningLocomotive(int speed, float weight, Color bodyColor)
{
- Locomotive = new EntityLocomotive();
- Locomotive.Init(speed, weight, bodyColor);
+ Locomotive = new EntityLocomotive(speed, weight, bodyColor);
Wheels = new DrawningWheels();
}
///
+ /// Конструктор для изменения размеров локомотива
+ ///
+ /// Скорость
+ /// Вес
+ /// Цвет кузова
+ /// Ширина локомотива
+ /// Высота локомотива
+ protected DrawningLocomotive(int speed, float weight, Color bodyColor, int locomotiveWidth, int locomotiveHeight)
+ : this(speed, weight, bodyColor)
+ {
+ _locomotiveWidth = locomotiveWidth;
+ _locomotiveHeight = locomotiveHeight;
+ }
+ ///
/// Установка начальной позиции локомотива
///
/// Левая координата
@@ -117,7 +130,7 @@
/// Метод отрисовки локомотива
///
/// Графика
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
@@ -188,5 +201,13 @@
_startPosY = _pictureHeight.Value - _locomotiveHeight;
}
}
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ public (float Top, float Bottom, float Left, float Right) GetCurrentPosition()
+ {
+ return (_startPosY, _startPosY + _locomotiveHeight, _startPosX, _startPosX + _locomotiveWidth);
+ }
}
}
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningObjectLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningObjectLocomotive.cs
new file mode 100644
index 0000000..22e963f
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningObjectLocomotive.cs
@@ -0,0 +1,35 @@
+namespace WarmlyLocomotove
+{
+///
+/// Класс-наследник от интерфейса (реализация)
+///
+ internal class DrawningObjectLocomotive : IDrawningObject
+ {
+ ///
+ /// Объект от класса отрисовки локомотива
+ ///
+ private DrawningLocomotive _locomotive = null;
+ public DrawningObjectLocomotive(DrawningLocomotive locomotive)
+ {
+ _locomotive = locomotive;
+ }
+ public float Step => _locomotive?.Locomotive?.Step ?? 0;
+ public (float Top, float Bottom, float Left, float Right) GetCurrentPosition()
+ {
+ return _locomotive?.GetCurrentPosition() ?? default;
+ }
+ public void MoveObject(Direction direction)
+ {
+ _locomotive?.MoveLocomotive(direction);
+ }
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _locomotive.SetPosition(x, y, width, height);
+ }
+ public void DrawningObject(Graphics g)
+ {
+ _locomotive.DrawTransport(g);
+ }
+
+ }
+}
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningWarmlyLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningWarmlyLocomotive.cs
new file mode 100644
index 0000000..58d9182
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningWarmlyLocomotive.cs
@@ -0,0 +1,61 @@
+namespace WarmlyLocomotove
+{
+ ///
+ /// Класс-наследник от класса отрисовки локомотива
+ ///
+ internal class DrawningWarmlyLocomotive : DrawningLocomotive
+ {
+ ///
+ /// Конструктор, передаём в protected конструктор базового класса обычные параметры и вводим новые
+ ///
+ /// Скорость
+ /// Вес
+ /// Цвет кузова
+ /// Ширина локомотива
+ /// Высота локомотива
+ /// Дополнительный цвет
+ /// Признак наличия трубы
+ /// Признак наличия топливного бака
+ public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, int locomotiveWidth, int locomotiveHeight, Color additionalColor, bool hasPipe, bool hasFuelTank) : base(speed, weight, bodyColor, locomotiveWidth, locomotiveHeight)
+ {
+ Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, additionalColor, hasPipe, hasFuelTank);
+ }
+ ///
+ /// Отрисовываем базовую часть локомотива и добавляем дополнительные элементы, если они есть
+ ///
+ ///
+ public override void DrawTransport(Graphics g)
+ {
+ if (Locomotive is not EntityWarmlyLocomotive warmlyLocomotive)
+ {
+ return;
+ }
+ //Прорисовка трубы
+ if (warmlyLocomotive.HasPipe)
+ {
+ Pen pen = new Pen(Color.Black);
+ Brush brAdditionalColor = new SolidBrush(warmlyLocomotive.AdditionalColor);
+ g.FillRectangle(brAdditionalColor, _startPosX + 20, _startPosY, 25, 10);
+ g.DrawRectangle(pen, _startPosX + 20, _startPosY, 25, 10);
+ g.FillRectangle(brAdditionalColor, _startPosX + 25, _startPosY + 10, 15, 20);
+ g.DrawRectangle(pen, _startPosX + 25, _startPosY + 10, 15, 20);
+ }
+ _startPosY += 30;
+ base.DrawTransport(g);
+ _startPosY -= 30;
+ //Прорисовка топливного бака
+ if (warmlyLocomotive.HasFuelTank)
+ {
+ Pen pen = new Pen(Color.Black);
+ Brush brAdditionalColor = new SolidBrush(warmlyLocomotive.AdditionalColor);
+ Pen penYellow = new Pen(Color.Yellow);
+ g.FillRectangle(brAdditionalColor, _startPosX + 80, _startPosY + 40, 45, 20);
+ g.DrawRectangle(pen, _startPosX + 80, _startPosY + 40, 45, 20);
+ for (int i = (int)_startPosX + 100; i < (int)_startPosX + 110; i++)
+ {
+ g.DrawLine(penYellow, _startPosX + 105, _startPosY + 45, i, _startPosY + 55);
+ }
+ }
+ }
+ }
+}
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/EntityLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/EntityLocomotive.cs
index d4a6653..927a9b7 100644
--- a/LocomotivesAdvanced/LocomotivesAdvanced/EntityLocomotive.cs
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/EntityLocomotive.cs
@@ -22,12 +22,12 @@
///
public float Step => Speed * 100 / Weight;
///
- /// Инициализация полей объекта-класса локомотива
+ /// Конструктор (инициализация полей объекта-класса локомотива)
///
/// скорость
/// вес
/// цвет кузова
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityLocomotive(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/EntityWarmlyLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/EntityWarmlyLocomotive.cs
new file mode 100644
index 0000000..385ee71
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/EntityWarmlyLocomotive.cs
@@ -0,0 +1,36 @@
+namespace WarmlyLocomotove
+{
+ ///
+ /// Класс-наследник от класса-сущности локомотива (усложнённый локомотив/тепловоз)
+ ///
+ internal class EntityWarmlyLocomotive : EntityLocomotive
+ {
+ ///
+ /// Дополнительный цвет
+ ///
+ public Color AdditionalColor { get; private set; }
+ ///
+ /// Признак наличия трубы
+ ///
+ public bool HasPipe { get; private set; }
+ ///
+ /// Признак наличия топливного бака
+ ///
+ public bool HasFuelTank { get; private set; }
+ ///
+ /// Инициализация свойств усложнённого локомотива (тепловоза)
+ ///
+ /// Скорость
+ /// Вес
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия трубы
+ /// Признак наличия топливного бака
+ public EntityWarmlyLocomotive(int speed, float weight, Color bodyColor, Color additionalColor, bool hasPipe, bool hasFuelTank) : base (speed, weight, bodyColor)
+ {
+ AdditionalColor = additionalColor;
+ HasPipe = hasPipe;
+ HasFuelTank = hasFuelTank;
+ }
+ }
+}
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs
index dba6a69..507a2cc 100644
--- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.Designer.cs
@@ -40,6 +40,10 @@
this.buttonUp = new System.Windows.Forms.Button();
this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown();
this.labelWheelsNumber = new System.Windows.Forms.Label();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
+ this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit();
@@ -62,7 +66,10 @@
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
- this.toolStripStatusLabelBodyColor});
+ this.toolStripStatusLabelBodyColor,
+ this.toolStripStatusLabelAdditionalColor,
+ this.toolStripStatusLabelHasPipe,
+ this.toolStripStatusLabelHasFuelTank});
this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
@@ -180,11 +187,41 @@
this.labelWheelsNumber.TabIndex = 8;
this.labelWheelsNumber.Text = "Число колёс:";
//
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateModif.Location = new System.Drawing.Point(108, 395);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(98, 30);
+ this.buttonCreateModif.TabIndex = 9;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
+ // toolStripStatusLabelAdditionalColor
+ //
+ this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor";
+ this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17);
+ this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: ";
+ //
+ // toolStripStatusLabelHasPipe
+ //
+ this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe";
+ this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17);
+ this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: ";
+ //
+ // toolStripStatusLabelHasFuelTank
+ //
+ this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank";
+ this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17);
+ this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: ";
+ //
// FormLocomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.labelWheelsNumber);
this.Controls.Add(this.numericUpDownWheelsNumber);
this.Controls.Add(this.buttonUp);
@@ -219,5 +256,9 @@
private Button buttonUp;
private NumericUpDown numericUpDownWheelsNumber;
private Label labelWheelsNumber;
+ private Button buttonCreateModif;
+ private ToolStripStatusLabel toolStripStatusLabelAdditionalColor;
+ private ToolStripStatusLabel toolStripStatusLabelHasPipe;
+ private ToolStripStatusLabel toolStripStatusLabelHasFuelTank;
}
}
\ No newline at end of file
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs
index bbe402b..d763077 100644
--- a/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormLocomotive.cs
@@ -22,6 +22,34 @@
pictureBoxLocomotive.Image = bmp;
}
///
+ /// Заполнение информации по объекту
+ ///
+ /// Объект от класса отрисовки или его наследника
+ private void SetData(DrawningLocomotive locomotive)
+ {
+ Random rnd = new();
+ toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}";
+ toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д";
+ toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д";
+ toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д";
+ _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
+ }
+ ///
+ /// Заполнение дополнительной информации по объекту (только для усложнённого объекта)
+ ///
+ /// Объект от наследника класса отрисовки
+ private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive)
+ {
+ if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive)
+ {
+ toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}";
+ toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}";
+ toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}";
+ }
+ }
+ ///
/// Метод обработки нажатия на кнопку "Создать"
///
///
@@ -29,12 +57,9 @@
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _locomotive = new DrawningLocomotive();
- _locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ _locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
- toolStripStatusLabelSpeed.Text = $"Скорость: {_locomotive.Locomotive.Speed}";
- toolStripStatusLabelWeight.Text = $"Вес: {_locomotive.Locomotive.Weight}";
- toolStripStatusLabelBodyColor.Text = $"Цвет: {_locomotive.Locomotive.BodyColor.Name}";
+ SetData(_locomotive);
_locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
Draw();
}
@@ -74,5 +99,24 @@
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
Draw();
}
+ ///
+ /// Метод обработки нажатия на кнопку "Модификация"
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ 160, 115,
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Convert.ToBoolean(rnd.Next(0, 2)),
+ Convert.ToBoolean(rnd.Next(0, 2)));
+ SetData(_locomotive);
+ SetAdditionalData((DrawningWarmlyLocomotive)_locomotive);
+ _locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
+ Draw();
+ }
}
}
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.Designer.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.Designer.cs
new file mode 100644
index 0000000..b963495
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.Designer.cs
@@ -0,0 +1,280 @@
+namespace WarmlyLocomotove
+{
+ partial class FormMap
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox();
+ this.statusStrip = new System.Windows.Forms.StatusStrip();
+ this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelAdditionalColor = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelHasPipe = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelHasFuelTank = new System.Windows.Forms.ToolStripStatusLabel();
+ this.buttonCreate = new System.Windows.Forms.Button();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
+ this.labelWheelsNumber = new System.Windows.Forms.Label();
+ this.numericUpDownWheelsNumber = new System.Windows.Forms.NumericUpDown();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
+ this.statusStrip.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).BeginInit();
+ this.SuspendLayout();
+ //
+ // pictureBoxLocomotive
+ //
+ this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxLocomotive.MinimumSize = new System.Drawing.Size(1, 1);
+ this.pictureBoxLocomotive.Name = "pictureBoxLocomotive";
+ this.pictureBoxLocomotive.Size = new System.Drawing.Size(800, 450);
+ this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBoxLocomotive.TabIndex = 0;
+ this.pictureBoxLocomotive.TabStop = false;
+ //
+ // statusStrip
+ //
+ this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusLabelSpeed,
+ this.toolStripStatusLabelWeight,
+ this.toolStripStatusLabelBodyColor,
+ this.toolStripStatusLabelAdditionalColor,
+ this.toolStripStatusLabelHasPipe,
+ this.toolStripStatusLabelHasFuelTank});
+ this.statusStrip.Location = new System.Drawing.Point(0, 428);
+ this.statusStrip.Name = "statusStrip";
+ this.statusStrip.Size = new System.Drawing.Size(800, 22);
+ this.statusStrip.TabIndex = 1;
+ this.statusStrip.Text = "statusStrip1";
+ //
+ // toolStripStatusLabelSpeed
+ //
+ this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
+ this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17);
+ this.toolStripStatusLabelSpeed.Text = "Скорость: ";
+ //
+ // toolStripStatusLabelWeight
+ //
+ this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
+ this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
+ this.toolStripStatusLabelWeight.Text = "Вес: ";
+ //
+ // toolStripStatusLabelBodyColor
+ //
+ this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
+ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17);
+ this.toolStripStatusLabelBodyColor.Text = "Цвет: ";
+ //
+ // toolStripStatusLabelAdditionalColor
+ //
+ this.toolStripStatusLabelAdditionalColor.Name = "toolStripStatusLabelAdditionalColor";
+ this.toolStripStatusLabelAdditionalColor.Size = new System.Drawing.Size(137, 17);
+ this.toolStripStatusLabelAdditionalColor.Text = "Дополнительный цвет: ";
+ //
+ // toolStripStatusLabelHasPipe
+ //
+ this.toolStripStatusLabelHasPipe.Name = "toolStripStatusLabelHasPipe";
+ this.toolStripStatusLabelHasPipe.Size = new System.Drawing.Size(99, 17);
+ this.toolStripStatusLabelHasPipe.Text = "Наличие трубы: ";
+ //
+ // toolStripStatusLabelHasFuelTank
+ //
+ this.toolStripStatusLabelHasFuelTank.Name = "toolStripStatusLabelHasFuelTank";
+ this.toolStripStatusLabelHasFuelTank.Size = new System.Drawing.Size(158, 17);
+ this.toolStripStatusLabelHasFuelTank.Text = "Наличие топливного бака: ";
+ //
+ // buttonCreate
+ //
+ this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreate.Location = new System.Drawing.Point(12, 395);
+ this.buttonCreate.Name = "buttonCreate";
+ this.buttonCreate.Size = new System.Drawing.Size(90, 30);
+ this.buttonCreate.TabIndex = 2;
+ this.buttonCreate.Text = "Создать";
+ this.buttonCreate.UseVisualStyleBackColor = true;
+ this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowRight;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(758, 395);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 3;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonLeft
+ //
+ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowLeft;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(686, 395);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 4;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowDown;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(722, 395);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 5;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.ArrowUp;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(722, 359);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 6;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Карта с крестом",
+ "Карта с дорожками"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(141, 23);
+ this.comboBoxSelectorMap.TabIndex = 7;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
+ //
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateModif.Location = new System.Drawing.Point(108, 395);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(109, 30);
+ this.buttonCreateModif.TabIndex = 8;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
+ // labelWheelsNumber
+ //
+ this.labelWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.labelWheelsNumber.AutoSize = true;
+ this.labelWheelsNumber.Location = new System.Drawing.Point(560, 403);
+ this.labelWheelsNumber.Name = "labelWheelsNumber";
+ this.labelWheelsNumber.Size = new System.Drawing.Size(80, 15);
+ this.labelWheelsNumber.TabIndex = 10;
+ this.labelWheelsNumber.Text = "Число колёс:";
+ //
+ // numericUpDownWheelsNumber
+ //
+ this.numericUpDownWheelsNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.numericUpDownWheelsNumber.Location = new System.Drawing.Point(646, 401);
+ this.numericUpDownWheelsNumber.Maximum = new decimal(new int[] {
+ 4,
+ 0,
+ 0,
+ 0});
+ this.numericUpDownWheelsNumber.Minimum = new decimal(new int[] {
+ 2,
+ 0,
+ 0,
+ 0});
+ this.numericUpDownWheelsNumber.Name = "numericUpDownWheelsNumber";
+ this.numericUpDownWheelsNumber.ReadOnly = true;
+ this.numericUpDownWheelsNumber.Size = new System.Drawing.Size(29, 23);
+ this.numericUpDownWheelsNumber.TabIndex = 9;
+ this.numericUpDownWheelsNumber.Value = new decimal(new int[] {
+ 2,
+ 0,
+ 0,
+ 0});
+ //
+ // FormMap
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.labelWheelsNumber);
+ this.Controls.Add(this.numericUpDownWheelsNumber);
+ this.Controls.Add(this.buttonCreateModif);
+ this.Controls.Add(this.comboBoxSelectorMap);
+ this.Controls.Add(this.buttonUp);
+ this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.buttonLeft);
+ this.Controls.Add(this.buttonRight);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.statusStrip);
+ this.Controls.Add(this.pictureBoxLocomotive);
+ this.Name = "FormMap";
+ this.Text = "Локомотив";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit();
+ this.statusStrip.ResumeLayout(false);
+ this.statusStrip.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWheelsNumber)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxLocomotive;
+ private StatusStrip statusStrip;
+ private ToolStripStatusLabel toolStripStatusLabelSpeed;
+ private ToolStripStatusLabel toolStripStatusLabelWeight;
+ private ToolStripStatusLabel toolStripStatusLabelBodyColor;
+ private Button buttonCreate;
+ private Button buttonRight;
+ private Button buttonLeft;
+ private Button buttonDown;
+ private Button buttonUp;
+ private ComboBox comboBoxSelectorMap;
+ private Button buttonCreateModif;
+ private ToolStripStatusLabel toolStripStatusLabelAdditionalColor;
+ private ToolStripStatusLabel toolStripStatusLabelHasPipe;
+ private ToolStripStatusLabel toolStripStatusLabelHasFuelTank;
+ private Label labelWheelsNumber;
+ private NumericUpDown numericUpDownWheelsNumber;
+ }
+}
\ No newline at end of file
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.cs b/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.cs
new file mode 100644
index 0000000..274255b
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.cs
@@ -0,0 +1,123 @@
+namespace WarmlyLocomotove
+{
+ public partial class FormMap : Form
+ {
+ ///
+ /// Создание объекта от абстрактного класса карты
+ ///
+ private AbstractMap _abstractMap;
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+ ///
+ /// Заполнение информации по объекту
+ ///
+ /// Объект от класса отрисовки или его наследника
+ private void SetData(DrawningLocomotive locomotive)
+ {
+ toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}";
+ toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д";
+ toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д";
+ toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д";
+ pictureBoxLocomotive.Image = _abstractMap.CreateMap(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height,
+ new DrawningObjectLocomotive(locomotive));
+ }
+ ///
+ /// Заполнение дополнительной информации по объекту (только для усложнённого объекта)
+ ///
+ /// Объект от наследника класса отрисовки
+ private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive)
+ {
+ if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive)
+ {
+ toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}";
+ toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}";
+ toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}";
+ }
+ }
+ ///
+ /// Обработка нажатия кнопки "Создать"
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
+ SetData(locomotive);
+ }
+ ///
+ /// Перемещение объекта по форме
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ //получаем имя кнопки
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ Direction dir = Direction.None;
+ switch (name)
+ {
+ case "buttonUp":
+ dir = Direction.Up;
+ break;
+ case "buttonDown":
+ dir = Direction.Down;
+ break;
+ case "buttonLeft":
+ dir = Direction.Left;
+ break;
+ case "buttonRight":
+ dir = Direction.Right;
+ break;
+ }
+ pictureBoxLocomotive.Image = _abstractMap?.MoveObject(dir);
+ }
+ ///
+ /// Обработка нажатия кнопки "Модификация"
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ 160, 85,
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Convert.ToBoolean(rnd.Next(0, 2)),
+ Convert.ToBoolean(rnd.Next(0, 2)));
+ locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
+ SetData(locomotive);
+ SetAdditionalData(locomotive);
+ }
+ ///
+ /// Смена карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ _abstractMap = new SimpleMap();
+ break;
+ case "Карта с крестом":
+ _abstractMap = new CrossMap();
+ break;
+ case "Карта с дорожками":
+ _abstractMap = new RoadsMap();
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.resx b/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.resx
new file mode 100644
index 0000000..2c0949d
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/FormMap.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningObject.cs b/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningObject.cs
new file mode 100644
index 0000000..aba66f1
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningObject.cs
@@ -0,0 +1,36 @@
+namespace WarmlyLocomotove
+{
+ ///
+ /// Интерфейс для отрисовки
+ ///
+ internal interface IDrawningObject
+ {
+ ///
+ /// Шаг перемещения объекта
+ ///
+ public float Step { get; }
+ ///
+ /// Установка позиции объекта
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина полотна
+ /// Высота полотна
+ void SetObject(int x, int y, int width, int height);
+ ///
+ /// Изменение направления пермещения объекта
+ ///
+ /// Направление
+ void MoveObject(Direction direction);
+ ///
+ /// Отрисовка объекта
+ ///
+ ///
+ void DrawningObject(Graphics g);
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ (float Top, float Bottom, float Left, float Right) GetCurrentPosition();
+ }
+}
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs b/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs
index ae74cc8..49fcafd 100644
--- a/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/Program.cs
@@ -8,7 +8,7 @@ namespace WarmlyLocomotove
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormLocomotive());
+ Application.Run(new FormMap());
}
}
}
\ No newline at end of file
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/RoadsMap.cs b/LocomotivesAdvanced/LocomotivesAdvanced/RoadsMap.cs
new file mode 100644
index 0000000..09ae2f6
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/RoadsMap.cs
@@ -0,0 +1,45 @@
+namespace WarmlyLocomotove
+{
+ ///
+ /// Карта в виде дорожек
+ ///
+ internal class RoadsMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Blue);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush roadColor = new SolidBrush(Color.Green);
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * _size_x, _size_y);
+ }
+ protected override void GenerateMap()
+ {
+ _map = new int[100, 100];
+ _size_x = (float)_width / _map.GetLength(0);
+ _size_y = (float)_height / _map.GetLength(1);
+ for (int i = 0; i < _map.GetLength(0); i++)
+ {
+ for (int j = 0; j < _map.GetLength(1); j++)
+ {
+ _map[i, j] = _freeRoad;
+ }
+ }
+ for (int i = 25; i < _map.GetLength(1) - 20; i++)
+ {
+ for (int j = 30; j < _map.GetLength(0); j += 20)
+ {
+ _map[i, j] = _barrier;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/SimpleMap.cs b/LocomotivesAdvanced/LocomotivesAdvanced/SimpleMap.cs
new file mode 100644
index 0000000..81d89f6
--- /dev/null
+++ b/LocomotivesAdvanced/LocomotivesAdvanced/SimpleMap.cs
@@ -0,0 +1,49 @@
+namespace WarmlyLocomotove
+{
+ ///
+ /// Карта с 50-ю барьерами в случайных местах
+ ///
+ internal class SimpleMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Black);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush roadColor = new SolidBrush(Color.Gray);
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void GenerateMap()
+ {
+ _map = new int[100, 100];
+ _size_x = (float)_width / _map.GetLength(0);
+ _size_y = (float)_height / _map.GetLength(1);
+ int counter = 0;
+ for (int i = 0; i < _map.GetLength(0); i++)
+ {
+ for (int j = 0; j < _map.GetLength(1); j++)
+ {
+ _map[i, j] = _freeRoad;
+ }
+ }
+ while (counter < 50)
+ {
+ int x = _random.Next(0, 100);
+ int y = _random.Next(0, 100);
+ if (_map[x, y] == _freeRoad)
+ {
+ _map[x, y] = _barrier;
+ counter++;
+ }
+ }
+ }
+ }
+}