From a2333c47e3ca6178eee0726764af6a073617b832 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 1 Oct 2022 22:26:45 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BF=D0=B8=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20generic?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapWithSetLocomotivesGeneric.cs | 141 ++++++++++++++++++ .../Locomotive/SetLocomotivesGeneric.cs | 74 +++++++++ 2 files changed, 215 insertions(+) create mode 100644 Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs create mode 100644 Locomotive/Locomotive/SetLocomotivesGeneric.cs diff --git a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs new file mode 100644 index 0000000..7b14c97 --- /dev/null +++ b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class MapWithSetLocomotivesGeneric + where T : class, IDrawningObject + where U : AbstractMap + { + /// Ширина окна отрисовки + private readonly int _pictureWidth; + /// Высота окна отрисовки + private readonly int _pictureHeight; + /// Размер занимаемого объектом места (ширина) + private readonly int _placeSizeWidth = 210; + /// Размер занимаемого объектом места (высота) + private readonly int _placeSizeHeight = 90; + /// Набор объектов + private readonly SetLocomotivesGeneric _setLocomotives; + /// Карта + private readonly U _map; + /// Конструктор + public MapWithSetLocomotivesGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setLocomotives = new SetLocomotivesGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + /// Перегрузка оператора сложения + public static bool operator +(MapWithSetLocomotivesGeneric map, T locomotive) + { + return map._setLocomotives.Insert(locomotive); + } + /// Перегрузка оператора вычитания + public static bool operator -(MapWithSetLocomotivesGeneric map, int position) + { + return map._setLocomotives.Remove(position); + } + /// Вывод всего набора объектов + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawLocomotives(gr); + return bmp; + } + /// Просмотр объекта на карте + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setLocomotives.Count; i++) + { + var locomotive = _setLocomotives.Get(i); + if (locomotive != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive); + } + } + return new(_pictureWidth, _pictureHeight); + } + /// Перемещение объекта по крате + public Bitmap MoveObject(Direction direction) + { + if (_map != null) + { + return _map.MoveObject(direction); + } + return new(_pictureWidth, _pictureHeight); + } + /// "Взбалтываем" набор, чтобы все элементы оказались в начале + private void Shaking() + { + int j = _setLocomotives.Count - 1; + for (int i = 0; i < _setLocomotives.Count; i++) + { + if (_setLocomotives.Get(i) == null) + { + for (; j > i; j--) + { + var locomotive = _setLocomotives.Get(j); + if (locomotive != null) + { + _setLocomotives.Insert(locomotive, i); + _setLocomotives.Remove(j); + break; + } + } + if (j <= i) + { + return; + } + } + } + } + /// Метод отрисовки фона + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { //линия рамзетки места + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * + _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, + (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + } + } + /// Метод прорисовки объектов + private void DrawLocomotives(Graphics g) + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int curWidth = 0; + int curHeight = 0; + + for (int i = 0; i < _setLocomotives.Count; i++) + { + // установка позиции + _setLocomotives.Get(i)?.SetObject(curWidth * _placeSizeWidth, curHeight * _placeSizeHeight, _pictureWidth, _pictureHeight); + _setLocomotives.Get(i)?.DrawningObject(g); + if (curWidth < width) curWidth++; + else + { + curWidth = 0; + curHeight++; + } + } + } + + } +} diff --git a/Locomotive/Locomotive/SetLocomotivesGeneric.cs b/Locomotive/Locomotive/SetLocomotivesGeneric.cs new file mode 100644 index 0000000..62acb9c --- /dev/null +++ b/Locomotive/Locomotive/SetLocomotivesGeneric.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class SetLocomotivesGeneric + where T : class + { + private readonly T[] _places; + + /// Количество объектов в массиве + public int Count => _places.Length; + /// Конструктор + public SetLocomotivesGeneric(int count) + { + _places = new T[count]; + } + /// Добавление объекта в набор + public bool Insert(T locomotive) + { + return Insert(locomotive, 0); + } + /// Добавление объекта в набор на конкретную позицию + public bool Insert(T locomotive, int position) + { + if (position >= _places.Length|| position < 0) return false; + + if (_places[position] == null) + { + _places[position] = locomotive; + return true; + } + + int emptyEl = -1; + + for (int i = position + 1; i < Count; i++) + { + if (_places[i] == null) emptyEl = i; + break; + } + + if (emptyEl == -1) + { + return false; + } + + for (int i = emptyEl; i > position; i--) + { + _places[i] = _places[i - 1]; + } + _places[position] = locomotive; + return true; + } + /// Удаление объекта из набора с конкретной позиции + public bool Remove(int position) + { + if (position >= _places.Length || position < 0) return false; + _places[position] = null; + return true; + } + /// Получение объекта из набора по позиции + public T Get(int position) + { + if (position >= _places.Length || position < 0) + { + return null; + } + return _places[position]; + } + } +} -- 2.25.1 From 966de1e5610b635b2135ec9acde308ab8d2def39 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 1 Oct 2022 22:36:21 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20Sele?= =?UTF-8?q?ct=20=D0=B8=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82=D0=B2=D0=BE?= =?UTF-8?q?=20SelectedLocomotive=20=D0=B2=20FormLocomotive,=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=B0=20=D0=BD=D0=B5=D0=BA?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D1=85=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/Direction.cs | 2 +- Locomotive/Locomotive/DrawningLocomotive.cs | 2 +- Locomotive/Locomotive/EntityLocomotive.cs | 2 +- Locomotive/Locomotive/FormLocomotive.Designer.cs | 13 +++++++++++++ Locomotive/Locomotive/FormLocomotive.cs | 8 ++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Locomotive/Locomotive/Direction.cs b/Locomotive/Locomotive/Direction.cs index 81100fc..d2e53fb 100644 --- a/Locomotive/Locomotive/Direction.cs +++ b/Locomotive/Locomotive/Direction.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Locomotive { //Направление перемещения - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index ee0f470..1f4968b 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Locomotive { //Класс, отвечающий за отрисовку - internal class DrawningLocomotive + public class DrawningLocomotive { /// Класс-сущность public EntityLocomotive Locomotive { get; protected set; } diff --git a/Locomotive/Locomotive/EntityLocomotive.cs b/Locomotive/Locomotive/EntityLocomotive.cs index a546746..866c5a2 100644 --- a/Locomotive/Locomotive/EntityLocomotive.cs +++ b/Locomotive/Locomotive/EntityLocomotive.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Locomotive { - internal class EntityLocomotive + public class EntityLocomotive { /// Скорость public int Speed { get; private set; } diff --git a/Locomotive/Locomotive/FormLocomotive.Designer.cs b/Locomotive/Locomotive/FormLocomotive.Designer.cs index 12c5cba..f57cf18 100644 --- a/Locomotive/Locomotive/FormLocomotive.Designer.cs +++ b/Locomotive/Locomotive/FormLocomotive.Designer.cs @@ -39,6 +39,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonCreateModified = new System.Windows.Forms.Button(); + this.buttonSelectLocomotive = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -154,11 +155,22 @@ this.buttonCreateModified.UseVisualStyleBackColor = true; this.buttonCreateModified.Click += new System.EventHandler(this.buttonCreateModified_Click); // + // buttonSelectLocomotive + // + this.buttonSelectLocomotive.Location = new System.Drawing.Point(507, 377); + this.buttonSelectLocomotive.Name = "buttonSelectLocomotive"; + this.buttonSelectLocomotive.Size = new System.Drawing.Size(105, 29); + this.buttonSelectLocomotive.TabIndex = 8; + this.buttonSelectLocomotive.Text = "Select"; + this.buttonSelectLocomotive.UseVisualStyleBackColor = true; + this.buttonSelectLocomotive.Click += new System.EventHandler(this.buttonSelectLocomotive_Click); + // // FormLocomotive // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(778, 442); + this.Controls.Add(this.buttonSelectLocomotive); this.Controls.Add(this.buttonCreateModified); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); @@ -190,5 +202,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonCreateModified; + private Button buttonSelectLocomotive; } } \ No newline at end of file diff --git a/Locomotive/Locomotive/FormLocomotive.cs b/Locomotive/Locomotive/FormLocomotive.cs index 4e56d30..567dcdb 100644 --- a/Locomotive/Locomotive/FormLocomotive.cs +++ b/Locomotive/Locomotive/FormLocomotive.cs @@ -4,6 +4,8 @@ namespace Locomotive { private DrawningLocomotive _locomotive; + public DrawningLocomotive SelectedLocomotive { get; private set; } + public FormLocomotive() { InitializeComponent(); @@ -75,5 +77,11 @@ namespace Locomotive SetData(); Draw(); } + + private void buttonSelectLocomotive_Click(object sender, EventArgs e) + { + SelectedLocomotive = _locomotive; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file -- 2.25.1 From 5f94bebf5483d17bcf197aa7fa43ce65ddfd516d Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 2 Oct 2022 00:03:48 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20WithSetLocomoti?= =?UTF-8?q?ves?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetLocomotives.Designer.cs | 212 ++++++++++++++++++ .../Locomotive/FormMapWithSetLocomotives.cs | 137 +++++++++++ .../Locomotive/FormMapWithSetLocomotives.resx | 60 +++++ Locomotive/Locomotive/Program.cs | 2 +- .../Locomotive/SetLocomotivesGeneric.cs | 7 +- 5 files changed, 415 insertions(+), 3 deletions(-) create mode 100644 Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs create mode 100644 Locomotive/Locomotive/FormMapWithSetLocomotives.cs create mode 100644 Locomotive/Locomotive/FormMapWithSetLocomotives.resx diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs new file mode 100644 index 0000000..110cc39 --- /dev/null +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs @@ -0,0 +1,212 @@ +namespace Locomotive +{ + partial class FormMapWithSetLocomotives + { + /// + /// 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.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveLocomotive = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddLocomotive = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxTools + // + this.groupBoxTools.Controls.Add(this.buttonLeft); + this.groupBoxTools.Controls.Add(this.buttonRight); + this.groupBoxTools.Controls.Add(this.buttonDown); + this.groupBoxTools.Controls.Add(this.buttonUp); + this.groupBoxTools.Controls.Add(this.buttonShowOnMap); + this.groupBoxTools.Controls.Add(this.buttonShowStorage); + this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive); + this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); + this.groupBoxTools.Controls.Add(this.buttonAddLocomotive); + this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); + this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBoxTools.Location = new System.Drawing.Point(580, 0); + this.groupBoxTools.Name = "groupBoxTools"; + this.groupBoxTools.Size = new System.Drawing.Size(220, 504); + this.groupBoxTools.TabIndex = 0; + this.groupBoxTools.TabStop = false; + this.groupBoxTools.Text = "Tools"; + // + // buttonLeft + // + this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(42, 446); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(40, 40); + this.buttonLeft.TabIndex = 7; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonRight + // + this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(134, 446); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(40, 40); + this.buttonRight.TabIndex = 7; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonDown + // + this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(88, 446); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(40, 40); + this.buttonDown.TabIndex = 7; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonUp + // + this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(88, 400); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(40, 40); + this.buttonUp.TabIndex = 6; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(7, 282); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(207, 29); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Show on Map"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(7, 247); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(207, 29); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Show Storage"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click); + // + // buttonRemoveLocomotive + // + this.buttonRemoveLocomotive.Location = new System.Drawing.Point(7, 211); + this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive"; + this.buttonRemoveLocomotive.Size = new System.Drawing.Size(207, 30); + this.buttonRemoveLocomotive.TabIndex = 3; + this.buttonRemoveLocomotive.Text = "Remove Locomotive"; + this.buttonRemoveLocomotive.UseVisualStyleBackColor = true; + this.buttonRemoveLocomotive.Click += new System.EventHandler(this.buttonRemoveLocomotive_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 159); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(208, 27); + this.maskedTextBoxPosition.TabIndex = 2; + // + // buttonAddLocomotive + // + this.buttonAddLocomotive.Location = new System.Drawing.Point(6, 96); + this.buttonAddLocomotive.Name = "buttonAddLocomotive"; + this.buttonAddLocomotive.Size = new System.Drawing.Size(208, 29); + this.buttonAddLocomotive.TabIndex = 1; + this.buttonAddLocomotive.Text = "Add Locomotive"; + this.buttonAddLocomotive.UseVisualStyleBackColor = true; + this.buttonAddLocomotive.Click += new System.EventHandler(this.buttonAddLocomotive_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Simple Map", + "Spike Map", + "Rail Map"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 39); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(208, 28); + this.comboBoxSelectorMap.TabIndex = 0; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); + // + // pictureBox + // + this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(580, 504); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetLocomotives + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 504); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.groupBoxTools); + this.Name = "FormMapWithSetLocomotives"; + this.Text = "FormMapWithSetLocomotives"; + this.groupBoxTools.ResumeLayout(false); + this.groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxTools; + private PictureBox pictureBox; + private ComboBox comboBoxSelectorMap; + private Button buttonAddLocomotive; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonRemoveLocomotive; + private Button buttonShowStorage; + private Button buttonShowOnMap; + private Button buttonUp; + private Button buttonDown; + private Button buttonRight; + private Button buttonLeft; + } +} \ No newline at end of file diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs new file mode 100644 index 0000000..55ec098 --- /dev/null +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Locomotive +{ + public partial class FormMapWithSetLocomotives : Form + { + /// Объект от класса карты с набором объектов + private MapWithSetLocomotivesGeneric _mapLocomotivesCollectionGeneric; + public FormMapWithSetLocomotives() + { + InitializeComponent(); + } + /// Выбор карты + private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Simple Map": + map = new SimpleMap(); + break; + case "Spike Map": + map = new SpikeMap(); + break; + case "Rail Map": + map = new RailroadMap(); + break; + } + if (map != null) + { + _mapLocomotivesCollectionGeneric = new MapWithSetLocomotivesGeneric + (pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapLocomotivesCollectionGeneric = null; + } + } + /// Добавление объекта + private void buttonAddLocomotive_Click(object sender, EventArgs e) + { + if (_mapLocomotivesCollectionGeneric == null) + { + return; + } + FormLocomotive form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); + if (_mapLocomotivesCollectionGeneric + locomotive) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// Удаление объекта + private void buttonRemoveLocomotive_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_mapLocomotivesCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// Вывод набора + private void buttonShowStorage_Click(object sender, EventArgs e) + { + if (_mapLocomotivesCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); + } + /// Вывод карты + private void buttonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapLocomotivesCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowOnMap(); + } + /// Перемещение + private void buttonMove_Click(object sender, EventArgs e) + { + if (_mapLocomotivesCollectionGeneric == null) + { + return; + } + //получаем имя кнопки + 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; + } + pictureBox.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.resx b/Locomotive/Locomotive/FormMapWithSetLocomotives.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/Locomotive/Locomotive/Program.cs b/Locomotive/Locomotive/Program.cs index 5663e56..ceb3e6a 100644 --- a/Locomotive/Locomotive/Program.cs +++ b/Locomotive/Locomotive/Program.cs @@ -11,7 +11,7 @@ namespace Locomotive // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMap()); + Application.Run(new FormMapWithSetLocomotives()); } } } \ No newline at end of file diff --git a/Locomotive/Locomotive/SetLocomotivesGeneric.cs b/Locomotive/Locomotive/SetLocomotivesGeneric.cs index 62acb9c..1397e44 100644 --- a/Locomotive/Locomotive/SetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/SetLocomotivesGeneric.cs @@ -38,8 +38,11 @@ namespace Locomotive for (int i = position + 1; i < Count; i++) { - if (_places[i] == null) emptyEl = i; - break; + if (_places[i] == null) + { + emptyEl = i; + break; + } } if (emptyEl == -1) -- 2.25.1 From 498cac408801c32f9db225ae0fcc374b90fbeef0 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 2 Oct 2022 01:03:22 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=B5=D0=BF=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 2 +- .../MapWithSetLocomotivesGeneric.cs | 43 +++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 1f4968b..d2b363a 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -107,7 +107,7 @@ namespace Locomotive } Pen pen = new(Color.Black); //тело - g.FillRectangle(new SolidBrush(Color.MediumBlue), _startPosX , _startPosY, 110 - 10, 50 - 10); + g.FillRectangle(new SolidBrush(Color.White), _startPosX , _startPosY, 110 - 10, 50 - 10); //окна g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 10, _startPosY + 10, 10, 10); g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 30, _startPosY + 10, 10, 10); diff --git a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs index 7b14c97..3a9f8cc 100644 --- a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs @@ -102,18 +102,43 @@ namespace Locomotive /// Метод отрисовки фона private void DrawBackground(Graphics g) { - Pen pen = new(Color.Black, 3); - for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + Pen pen; + + for (int j = _placeSizeHeight; j < _pictureHeight; j+= _placeSizeHeight) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) - { //линия рамзетки места - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * - _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + //нижняя линия рельс + pen = new(Color.Black, 5); + + g.DrawLine(pen, 0, j, _pictureWidth, j); + for (int i = 0; i < _pictureWidth; i+=20) + { + g.DrawLine(pen, i, j, i, j + 10); + } + g.DrawLine(pen, 0, j + 10, _pictureWidth, j + 10); + + //верхняя линия рельс + + pen = new(Color.DarkGray, 4); + + g.DrawLine(pen, 0, j - 20, _pictureWidth, j - 20); + for (int i = 0; i < _pictureWidth; i += 20) + { + g.DrawLine(pen, i, j - 20, i, j - 10); + } + g.DrawLine(pen, 0, j - 10, _pictureWidth, j - 10); + + //фонари + for (int i = _placeSizeWidth; i < _pictureWidth; i += _placeSizeWidth) + { + pen = new(Color.Black, 10); + g.DrawLine(pen, i, j - _placeSizeHeight + 20, i, j); + pen = new(Color.Yellow, 20); + g.DrawLine(pen, i, j - _placeSizeHeight + 18, i, j - _placeSizeHeight + 38); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, - (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } } + + /// Метод прорисовки объектов private void DrawLocomotives(Graphics g) { @@ -126,7 +151,7 @@ namespace Locomotive for (int i = 0; i < _setLocomotives.Count; i++) { // установка позиции - _setLocomotives.Get(i)?.SetObject(curWidth * _placeSizeWidth, curHeight * _placeSizeHeight, _pictureWidth, _pictureHeight); + _setLocomotives.Get(i)?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); _setLocomotives.Get(i)?.DrawningObject(g); if (curWidth < width) curWidth++; else -- 2.25.1 From d3ec22f37a296f5d0cb3cffc0ecaf977890a6f65 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 3 Oct 2022 01:01:33 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=20=D1=86=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20FormMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/FormLocomotive.cs | 26 ++- Locomotive/Locomotive/FormMap.Designer.cs | 210 ---------------------- Locomotive/Locomotive/FormMap.cs | 99 ---------- Locomotive/Locomotive/FormMap.resx | 63 ------- 4 files changed, 23 insertions(+), 375 deletions(-) delete mode 100644 Locomotive/Locomotive/FormMap.Designer.cs delete mode 100644 Locomotive/Locomotive/FormMap.cs delete mode 100644 Locomotive/Locomotive/FormMap.resx diff --git a/Locomotive/Locomotive/FormLocomotive.cs b/Locomotive/Locomotive/FormLocomotive.cs index 567dcdb..7d782f5 100644 --- a/Locomotive/Locomotive/FormLocomotive.cs +++ b/Locomotive/Locomotive/FormLocomotive.cs @@ -30,7 +30,13 @@ namespace Locomotive private void buttonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _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))); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color); _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); SetData(); Draw(); @@ -67,9 +73,23 @@ namespace Locomotive private void buttonCreateModified_Click(object sender, EventArgs e) { Random rnd = new(); + + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } + _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)), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + color, + dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); diff --git a/Locomotive/Locomotive/FormMap.Designer.cs b/Locomotive/Locomotive/FormMap.Designer.cs deleted file mode 100644 index e885489..0000000 --- a/Locomotive/Locomotive/FormMap.Designer.cs +++ /dev/null @@ -1,210 +0,0 @@ -namespace Locomotive -{ - 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.statusStrip1 = new System.Windows.Forms.StatusStrip(); - this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonCreateModified = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit(); - this.statusStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // pictureBoxLocomotive - // - this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0); - this.pictureBoxLocomotive.Name = "pictureBoxLocomotive"; - this.pictureBoxLocomotive.Size = new System.Drawing.Size(778, 416); - this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxLocomotive.TabIndex = 0; - this.pictureBoxLocomotive.TabStop = false; - // - // statusStrip1 - // - this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelColor}); - this.statusStrip1.Location = new System.Drawing.Point(0, 416); - this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(778, 26); - this.statusStrip1.TabIndex = 1; - this.statusStrip1.Text = "statusStrip1"; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(51, 20); - this.toolStripStatusLabelSpeed.Text = "Speed"; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(56, 20); - this.toolStripStatusLabelWeight.Text = "Weight"; - // - // toolStripStatusLabelColor - // - this.toolStripStatusLabelColor.Name = "toolStripStatusLabelColor"; - this.toolStripStatusLabelColor.Size = new System.Drawing.Size(45, 20); - this.toolStripStatusLabelColor.Text = "Color"; - // - // 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, 377); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(94, 29); - this.buttonCreate.TabIndex = 2; - this.buttonCreate.Text = "Create "; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); - // - // buttonUp - // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(680, 320); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(40, 40); - this.buttonUp.TabIndex = 3; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.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::Locomotive.Properties.Resources.left_arrow; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(634, 366); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(40, 40); - 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::Locomotive.Properties.Resources.down_arrow; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(680, 366); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(40, 40); - this.buttonDown.TabIndex = 5; - this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(726, 366); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(40, 40); - this.buttonRight.TabIndex = 6; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonCreateModified - // - this.buttonCreateModified.Location = new System.Drawing.Point(112, 377); - this.buttonCreateModified.Name = "buttonCreateModified"; - this.buttonCreateModified.Size = new System.Drawing.Size(94, 29); - this.buttonCreateModified.TabIndex = 7; - this.buttonCreateModified.Text = "Modified"; - this.buttonCreateModified.UseVisualStyleBackColor = true; - this.buttonCreateModified.Click += new System.EventHandler(this.buttonCreateModified_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(151, 28); - this.comboBoxSelectorMap.TabIndex = 8; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); - // - // FormMap - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(778, 442); - this.Controls.Add(this.comboBoxSelectorMap); - this.Controls.Add(this.buttonCreateModified); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.pictureBoxLocomotive); - this.Controls.Add(this.statusStrip1); - this.Name = "FormMap"; - this.Text = "Map"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit(); - this.statusStrip1.ResumeLayout(false); - this.statusStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private PictureBox pictureBoxLocomotive; - private StatusStrip statusStrip1; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelColor; - private Button buttonCreate; - private Button buttonUp; - private Button buttonLeft; - private Button buttonDown; - private Button buttonRight; - private Button buttonCreateModified; - private ComboBox comboBoxSelectorMap; - } -} \ No newline at end of file diff --git a/Locomotive/Locomotive/FormMap.cs b/Locomotive/Locomotive/FormMap.cs deleted file mode 100644 index 4333523..0000000 --- a/Locomotive/Locomotive/FormMap.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Locomotive -{ - 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}"; - toolStripStatusLabelColor.Text = $"Цвет: { locomotive.Locomotive.BodyColor.Name}"; - pictureBoxLocomotive.Image = _abstractMap.CreateMap(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height, - new DrawningObjectLocomotive(locomotive)); - } - - /// Обработка нажатия кнопки "Создать" - private void buttonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var car = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetData(car); - } - - /// Изменение размеров формы - 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 buttonCreateModified_Click(object sender, EventArgs e) - { - Random rnd = new(); - var car = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, - 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, - 256)), - 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(car); - } - - /// Смена карты - private void comboBoxSelectorMap_SelectedIndexChanged(object sender, - EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Карта с шипами": - _abstractMap = new SpikeMap(); - break; - case "Карта с рельсами": - _abstractMap = new RailroadMap(); - break; - - } - } - } -} diff --git a/Locomotive/Locomotive/FormMap.resx b/Locomotive/Locomotive/FormMap.resx deleted file mode 100644 index 5cb320f..0000000 --- a/Locomotive/Locomotive/FormMap.resx +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 -- 2.25.1 From e1b431152bac388f6462e6ccb47645d9037497e2 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 3 Oct 2022 15:20:30 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=BA=D0=BE=D0=BC=D0=BE=D1=82=D0=B8=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index d2b363a..827d7d2 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -107,11 +107,11 @@ namespace Locomotive } Pen pen = new(Color.Black); //тело - g.FillRectangle(new SolidBrush(Color.White), _startPosX , _startPosY, 110 - 10, 50 - 10); + g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Brown), _startPosX , _startPosY, 110 - 10, 50 - 10); //окна - g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 10, _startPosY + 10, 10, 10); - g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 30, _startPosY + 10, 10, 10); - g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 80, _startPosY + 10, 10, 10); + g.FillRectangle(new SolidBrush(Color.Blue), _startPosX + 10, _startPosY + 10, 10, 10); + g.FillRectangle(new SolidBrush(Color.Blue), _startPosX + 30, _startPosY + 10, 10, 10); + g.FillRectangle(new SolidBrush(Color.Blue), _startPosX + 80, _startPosY + 10, 10, 10); //дверь g.DrawRectangle(pen, _startPosX + 50, _startPosY + 10, 10, 20); //колеса -- 2.25.1 From ca917f05112283c9fe8a3167d39c418c47d6e857 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 3 Oct 2022 16:17:27 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=9B=D0=B0=D0=B13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Locomotive/FormMapWithSetLocomotives.cs | 4 ++-- .../MapWithSetLocomotivesGeneric.cs | 4 ++-- .../Locomotive/SetLocomotivesGeneric.cs | 19 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs index 55ec098..34f705f 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs @@ -55,7 +55,7 @@ namespace Locomotive if (form.ShowDialog() == DialogResult.OK) { DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); - if (_mapLocomotivesCollectionGeneric + locomotive) + if (_mapLocomotivesCollectionGeneric + locomotive != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); @@ -78,7 +78,7 @@ namespace Locomotive return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapLocomotivesCollectionGeneric - pos) + if (_mapLocomotivesCollectionGeneric - pos is not null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); diff --git a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs index 3a9f8cc..71eaad3 100644 --- a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs @@ -33,12 +33,12 @@ namespace Locomotive _map = map; } /// Перегрузка оператора сложения - public static bool operator +(MapWithSetLocomotivesGeneric map, T locomotive) + public static int operator +(MapWithSetLocomotivesGeneric map, T locomotive) { return map._setLocomotives.Insert(locomotive); } /// Перегрузка оператора вычитания - public static bool operator -(MapWithSetLocomotivesGeneric map, int position) + public static T operator -(MapWithSetLocomotivesGeneric map, int position) { return map._setLocomotives.Remove(position); } diff --git a/Locomotive/Locomotive/SetLocomotivesGeneric.cs b/Locomotive/Locomotive/SetLocomotivesGeneric.cs index 1397e44..5deb455 100644 --- a/Locomotive/Locomotive/SetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/SetLocomotivesGeneric.cs @@ -19,19 +19,19 @@ namespace Locomotive _places = new T[count]; } /// Добавление объекта в набор - public bool Insert(T locomotive) + public int Insert(T locomotive) { return Insert(locomotive, 0); } /// Добавление объекта в набор на конкретную позицию - public bool Insert(T locomotive, int position) + public int Insert(T locomotive, int position) { - if (position >= _places.Length|| position < 0) return false; + if (position >= _places.Length|| position < 0) return -1; if (_places[position] == null) { _places[position] = locomotive; - return true; + return position; } int emptyEl = -1; @@ -47,7 +47,7 @@ namespace Locomotive if (emptyEl == -1) { - return false; + return -1; } for (int i = emptyEl; i > position; i--) @@ -55,14 +55,15 @@ namespace Locomotive _places[i] = _places[i - 1]; } _places[position] = locomotive; - return true; + return position; } /// Удаление объекта из набора с конкретной позиции - public bool Remove(int position) + public T Remove(int position) { - if (position >= _places.Length || position < 0) return false; + if (position >= _places.Length || position < 0) return null; + T result = _places[position]; _places[position] = null; - return true; + return result; } /// Получение объекта из набора по позиции public T Get(int position) -- 2.25.1