From 2cfb9544b2f67f6b48ae07f4096a5323f9969589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D1=8F=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=D1=84=D0=BE=D1=80=D0=BE=D0=B2=D0=B0?= Date: Sun, 2 Oct 2022 19:21:39 +0400 Subject: [PATCH 1/4] generic classes --- .../AccordionBus/MapWithSetBusesGeneric.cs | 182 ++++++++++++++++++ AccordionBus/AccordionBus/SetBusesGeneric.cs | 103 ++++++++++ 2 files changed, 285 insertions(+) create mode 100644 AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs create mode 100644 AccordionBus/AccordionBus/SetBusesGeneric.cs diff --git a/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs b/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs new file mode 100644 index 0000000..1fc2b82 --- /dev/null +++ b/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs @@ -0,0 +1,182 @@ +using AccordionBus; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccordionBus +{ + /// + /// Карта с набором объектов под нее + /// + /// + /// + internal class MapWithSetBusesGeneric + where T : class, IDrawningObject + where U : AbstractMap + { + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 400; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 100; + /// + /// Набор объектов + /// + private readonly SetBusesGeneric _setBuses; + /// + /// Карта + /// + private readonly U _map; + /// + /// Конструктор + /// + /// + /// + /// + public MapWithSetBusesGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setBuses = new SetBusesGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(MapWithSetBusesGeneric map, T bus) + { + return map._setBuses.Insert(bus); + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(MapWithSetBusesGeneric map, int position) + { + return map._setBuses.Remove(position); + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawBuses(gr); + return bmp; + } + /// + /// Просмотр объекта на карте + /// + /// + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setBuses.Count; i++) + { + var bus = _setBuses.Get(i); + if (bus != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, bus); + } + } + 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 = _setBuses.Count - 1; + for (int i = 0; i < _setBuses.Count; i++) + { + if (_setBuses.Get(i) == null) + { + for (; j > i; j--) + { + var bus = _setBuses.Get(j); + if (bus != null) + { + _setBuses.Insert(bus, i); + _setBuses.Remove(j); + break; + } + } + if (j <= i) + { + return; + } + } + } + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.White, 3); + Brush brush = new SolidBrush(Color.Gray); + g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight); + 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 DrawBuses(Graphics g) + { + int numberOfSeatsInWidth = _pictureWidth / _placeSizeWidth; + int numberOfSeatsInHeight = _pictureHeight / _placeSizeHeight; + int rightLine = (numberOfSeatsInWidth - 1) * _placeSizeWidth; + int bottomLine = (numberOfSeatsInHeight - 1) * _placeSizeHeight; + for (int i = 0; i < _setBuses.Count; i++) + { + _setBuses.Get(i)?.SetObject(rightLine - i % numberOfSeatsInWidth * _placeSizeWidth, bottomLine - i / numberOfSeatsInWidth * _placeSizeHeight, _pictureWidth, _pictureHeight); + _setBuses.Get(i)?.DrawningObject(g); + } + } + } +} \ No newline at end of file diff --git a/AccordionBus/AccordionBus/SetBusesGeneric.cs b/AccordionBus/AccordionBus/SetBusesGeneric.cs new file mode 100644 index 0000000..17ae571 --- /dev/null +++ b/AccordionBus/AccordionBus/SetBusesGeneric.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccordionBus +{ + /// + /// Параметризованный набор объектов + /// + /// + internal class SetBusesGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetBusesGeneric(int count) + { + _places = new T[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый автобус + /// + public bool Insert(T bus) + { + return Insert(bus, 0); + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый автобус + /// Позиция + /// + public bool Insert(T bus, int position) + { + //проверка позиции + if (position < 0 || position >= Count) + { + return false; + } + //поиск пустой позиции + int positionEmpty = position; + for (; positionEmpty < Count; positionEmpty++) + { + if (_places[positionEmpty] == null) + { + break; + } + } + if (positionEmpty == Count) + { + return false; + } + //сдвиг вправо + for (; positionEmpty > position; positionEmpty--) + { + _places[positionEmpty] = _places[positionEmpty - 1]; + } + _places[position] = bus; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + if (position < 0 || position >= Count) + { + return false; + } + _places[position] = null; + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T Get(int position) + { + if (position < 0 || position >= Count) + { + return null; + } + return _places[position]; + } + } +} \ No newline at end of file From 4c3bb413c2a28ba769786bcea56abe90118c6454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D1=8F=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=D1=84=D0=BE=D1=80=D0=BE=D0=B2=D0=B0?= Date: Sun, 2 Oct 2022 20:23:54 +0400 Subject: [PATCH 2/4] changes forms --- AccordionBus/AccordionBus/Direction.cs | 2 +- AccordionBus/AccordionBus/DrawningBus.cs | 2 +- AccordionBus/AccordionBus/EntityBus.cs | 2 +- AccordionBus/AccordionBus/FormBus.Designer.cs | 14 ++ AccordionBus/AccordionBus/FormBus.cs | 34 ++- AccordionBus/AccordionBus/FormMap.Designer.cs | 209 ----------------- AccordionBus/AccordionBus/FormMap.cs | 103 --------- .../FormMapWithSetBuses.Designer.cs | 212 ++++++++++++++++++ .../AccordionBus/FormMapWithSetBuses.cs | 163 ++++++++++++++ ...{FormMap.resx => FormMapWithSetBuses.resx} | 3 - AccordionBus/AccordionBus/Program.cs | 2 +- 11 files changed, 423 insertions(+), 323 deletions(-) delete mode 100644 AccordionBus/AccordionBus/FormMap.Designer.cs delete mode 100644 AccordionBus/AccordionBus/FormMap.cs create mode 100644 AccordionBus/AccordionBus/FormMapWithSetBuses.Designer.cs create mode 100644 AccordionBus/AccordionBus/FormMapWithSetBuses.cs rename AccordionBus/AccordionBus/{FormMap.resx => FormMapWithSetBuses.resx} (93%) diff --git a/AccordionBus/AccordionBus/Direction.cs b/AccordionBus/AccordionBus/Direction.cs index 673222e..6d6f7a9 100644 --- a/AccordionBus/AccordionBus/Direction.cs +++ b/AccordionBus/AccordionBus/Direction.cs @@ -9,7 +9,7 @@ namespace AccordionBus /// /// Направление перемещения /// - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/AccordionBus/AccordionBus/DrawningBus.cs b/AccordionBus/AccordionBus/DrawningBus.cs index 49f6e09..c048251 100644 --- a/AccordionBus/AccordionBus/DrawningBus.cs +++ b/AccordionBus/AccordionBus/DrawningBus.cs @@ -11,7 +11,7 @@ namespace AccordionBus /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// - internal class DrawningBus + public class DrawningBus { /// /// Класс-сущность diff --git a/AccordionBus/AccordionBus/EntityBus.cs b/AccordionBus/AccordionBus/EntityBus.cs index 2c621e0..5398756 100644 --- a/AccordionBus/AccordionBus/EntityBus.cs +++ b/AccordionBus/AccordionBus/EntityBus.cs @@ -9,7 +9,7 @@ namespace AccordionBus /// /// Класс-сущность "Автобус" /// - internal class EntityBus + public class EntityBus { /// /// Скорость diff --git a/AccordionBus/AccordionBus/FormBus.Designer.cs b/AccordionBus/AccordionBus/FormBus.Designer.cs index 0aa0400..5c42263 100644 --- a/AccordionBus/AccordionBus/FormBus.Designer.cs +++ b/AccordionBus/AccordionBus/FormBus.Designer.cs @@ -39,6 +39,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonCreateModif = new System.Windows.Forms.Button(); + this.buttonSelectBus = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -154,11 +155,23 @@ this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); // + // buttonSelectBus + // + this.buttonSelectBus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSelectBus.Location = new System.Drawing.Point(563, 382); + this.buttonSelectBus.Name = "buttonSelectBus"; + this.buttonSelectBus.Size = new System.Drawing.Size(94, 29); + this.buttonSelectBus.TabIndex = 8; + this.buttonSelectBus.Text = "Выбрать"; + this.buttonSelectBus.UseVisualStyleBackColor = true; + this.buttonSelectBus.Click += new System.EventHandler(this.ButtonSelectBus_Click); + // // FormBus // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSelectBus); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); @@ -190,5 +203,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonCreateModif; + private Button buttonSelectBus; } } \ No newline at end of file diff --git a/AccordionBus/AccordionBus/FormBus.cs b/AccordionBus/AccordionBus/FormBus.cs index 5e757eb..e60bf06 100644 --- a/AccordionBus/AccordionBus/FormBus.cs +++ b/AccordionBus/AccordionBus/FormBus.cs @@ -5,6 +5,10 @@ namespace AccordionBus public partial class FormBus : Form { private DrawningBus _bus; + /// + /// + /// + public DrawningBus SelectedBus { get; private set; } public FormBus() { InitializeComponent(); @@ -38,7 +42,13 @@ namespace AccordionBus private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _bus = new DrawningBus(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; + } + _bus = new DrawningBus(rnd.Next(100, 300), rnd.Next(1000, 2000), color); SetData(); Draw(); } @@ -86,12 +96,28 @@ namespace AccordionBus private void ButtonCreateModif_Click(object sender, EventArgs e) { Random rnd = new(); - _bus = new DrawningAccordionBus(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 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; + } + _bus = new DrawningAccordionBus(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); } + + private void ButtonSelectBus_Click(object sender, EventArgs e) + { + SelectedBus = _bus; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/AccordionBus/AccordionBus/FormMap.Designer.cs b/AccordionBus/AccordionBus/FormMap.Designer.cs deleted file mode 100644 index cb41360..0000000 --- a/AccordionBus/AccordionBus/FormMap.Designer.cs +++ /dev/null @@ -1,209 +0,0 @@ -namespace AccordionBus -{ - 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.pictureBoxBus = 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.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.buttonCreateModif = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).BeginInit(); - this.statusStrip.SuspendLayout(); - this.SuspendLayout(); - // - // pictureBoxBus - // - this.pictureBoxBus.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxBus.Location = new System.Drawing.Point(0, 0); - this.pictureBoxBus.Name = "pictureBoxBus"; - this.pictureBoxBus.Size = new System.Drawing.Size(800, 424); - this.pictureBoxBus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxBus.TabIndex = 0; - this.pictureBoxBus.TabStop = false; - // - // statusStrip - // - this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor}); - this.statusStrip.Location = new System.Drawing.Point(0, 424); - this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 26); - this.statusStrip.TabIndex = 1; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20); - this.toolStripStatusLabelSpeed.Text = "Скорость:"; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20); - this.toolStripStatusLabelWeight.Text = "Вес:"; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20); - this.toolStripStatusLabelBodyColor.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, 382); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(94, 29); - this.buttonCreate.TabIndex = 2; - this.buttonCreate.Text = "Создать"; - 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::AccordionBus.Properties.Resources.arrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(722, 345); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - 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::AccordionBus.Properties.Resources.arrowLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(686, 381); - 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::AccordionBus.Properties.Resources.arrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(722, 381); - 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); - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::AccordionBus.Properties.Resources.arrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(758, 381); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 6; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); - // - // 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(123, 382); - this.buttonCreateModif.Name = "buttonCreateModif"; - this.buttonCreateModif.Size = new System.Drawing.Size(117, 29); - this.buttonCreateModif.TabIndex = 7; - this.buttonCreateModif.Text = "Модификация"; - this.buttonCreateModif.UseVisualStyleBackColor = true; - this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_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(800, 450); - this.Controls.Add(this.comboBoxSelectorMap); - this.Controls.Add(this.buttonCreateModif); - 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.pictureBoxBus); - this.Controls.Add(this.statusStrip); - this.Name = "FormMap"; - this.Text = "Карта"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).EndInit(); - this.statusStrip.ResumeLayout(false); - this.statusStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private PictureBox pictureBoxBus; - private StatusStrip statusStrip; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelBodyColor; - private Button buttonCreate; - private Button buttonUp; - private Button buttonLeft; - private Button buttonDown; - private Button buttonRight; - private Button buttonCreateModif; - private ComboBox comboBoxSelectorMap; - } -} \ No newline at end of file diff --git a/AccordionBus/AccordionBus/FormMap.cs b/AccordionBus/AccordionBus/FormMap.cs deleted file mode 100644 index 322d682..0000000 --- a/AccordionBus/AccordionBus/FormMap.cs +++ /dev/null @@ -1,103 +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 AccordionBus -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - /// - /// Заполнение информации по объекту - /// - /// - private void SetData(DrawningBus bus) - { - toolStripStatusLabelSpeed.Text = $"Скорость: {bus.Bus.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {bus.Bus.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {bus.Bus.BodyColor.Name}"; - pictureBoxBus.Image = _abstractMap.CreateMap(pictureBoxBus.Width, pictureBoxBus.Height, - new DrawningObjectBus(bus)); - } - /// - /// Обработка нажатия кнопки "Создать" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var bus = new DrawningBus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetData(bus); - } - /// - /// Изменение размеров формы - /// - /// - /// - 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; - } - pictureBoxBus.Image = _abstractMap?.MoveObject(dir); - } - /// - /// Обработка нажатия кнопки "Модификация" - /// - /// - /// - private void ButtonCreateModif_Click(object sender, EventArgs e) - { - Random rnd = new(); - var bus = new DrawningAccordionBus(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)), Convert.ToBoolean(rnd.Next(0, 2))); - SetData(bus); - } - /// - /// Смена карты - /// - /// - /// - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Карта подземного туннеля": - _abstractMap = new UndergroundTunnelMap(); - break; - } - } - } -} diff --git a/AccordionBus/AccordionBus/FormMapWithSetBuses.Designer.cs b/AccordionBus/AccordionBus/FormMapWithSetBuses.Designer.cs new file mode 100644 index 0000000..e072b2e --- /dev/null +++ b/AccordionBus/AccordionBus/FormMapWithSetBuses.Designer.cs @@ -0,0 +1,212 @@ +namespace AccordionBus +{ + partial class FormMapWithSetBuses + { + /// + /// 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.groupBox1 = new System.Windows.Forms.GroupBox(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveBus = new System.Windows.Forms.Button(); + this.buttonAddBus = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.buttonRight); + this.groupBox1.Controls.Add(this.buttonDown); + this.groupBox1.Controls.Add(this.buttonLeft); + this.groupBox1.Controls.Add(this.buttonUp); + this.groupBox1.Controls.Add(this.maskedTextBoxPosition); + this.groupBox1.Controls.Add(this.buttonShowOnMap); + this.groupBox1.Controls.Add(this.buttonShowStorage); + this.groupBox1.Controls.Add(this.buttonRemoveBus); + this.groupBox1.Controls.Add(this.buttonAddBus); + this.groupBox1.Controls.Add(this.comboBoxSelectorMap); + this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBox1.Location = new System.Drawing.Point(599, 0); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(250, 525); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Инструменты"; + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::AccordionBus.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(151, 452); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 10; + this.buttonRight.UseVisualStyleBackColor = true; + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::AccordionBus.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(115, 452); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 9; + this.buttonDown.UseVisualStyleBackColor = true; + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::AccordionBus.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(79, 452); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 8; + this.buttonLeft.UseVisualStyleBackColor = true; + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::AccordionBus.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(115, 416); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 7; + this.buttonUp.UseVisualStyleBackColor = true; + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(22, 157); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(207, 27); + this.maskedTextBoxPosition.TabIndex = 6; + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(22, 353); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(207, 29); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(22, 272); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(207, 29); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonRemoveBus + // + this.buttonRemoveBus.Location = new System.Drawing.Point(22, 190); + this.buttonRemoveBus.Name = "buttonRemoveBus"; + this.buttonRemoveBus.Size = new System.Drawing.Size(207, 29); + this.buttonRemoveBus.TabIndex = 3; + this.buttonRemoveBus.Text = "Удалить автомобиль"; + this.buttonRemoveBus.UseVisualStyleBackColor = true; + this.buttonRemoveBus.Click += new System.EventHandler(this.ButtonRemoveBus_Click); + // + // buttonAddBus + // + this.buttonAddBus.Location = new System.Drawing.Point(22, 106); + this.buttonAddBus.Name = "buttonAddBus"; + this.buttonAddBus.Size = new System.Drawing.Size(207, 29); + this.buttonAddBus.TabIndex = 1; + this.buttonAddBus.Text = "Добавить автомобиль"; + this.buttonAddBus.UseVisualStyleBackColor = true; + this.buttonAddBus.Click += new System.EventHandler(this.ButtonAddBus_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Карта подземного туннеля"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(22, 26); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(207, 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(599, 525); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetBuses + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(849, 525); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.groupBox1); + this.Name = "FormMapWithSetBuses"; + this.Text = "Карта с набором объектов"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBox1; + private PictureBox pictureBox; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemoveBus; + private Button buttonAddBus; + private ComboBox comboBoxSelectorMap; + private Button buttonRight; + private Button buttonDown; + private Button buttonLeft; + private Button buttonUp; + } +} \ No newline at end of file diff --git a/AccordionBus/AccordionBus/FormMapWithSetBuses.cs b/AccordionBus/AccordionBus/FormMapWithSetBuses.cs new file mode 100644 index 0000000..2b38408 --- /dev/null +++ b/AccordionBus/AccordionBus/FormMapWithSetBuses.cs @@ -0,0 +1,163 @@ +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 AccordionBus +{ + public partial class FormMapWithSetBuses : Form + { + /// + /// Объект от класса карты с набором объектов + /// + private MapWithSetBusesGeneric _mapBusesCollectionGeneric; + /// + /// Конструктор + /// + public FormMapWithSetBuses() + { + InitializeComponent(); + } + /// + /// Выбор карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + case "Карта подземного туннеля": + map = new UndergroundTunnelMap(); + break; + } + if (map != null) + { + _mapBusesCollectionGeneric = new MapWithSetBusesGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapBusesCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddBus_Click(object sender, EventArgs e) + { + if (_mapBusesCollectionGeneric == null) + { + return; + } + FormBus form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectBus bus = new(form.SelectedBus); + if (form.SelectedBus == null || !(_mapBusesCollectionGeneric + bus)) + { + MessageBox.Show("Не удалось добавить объект"); + } + else + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapBusesCollectionGeneric.ShowSet(); + } + } + } + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveBus_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 (_mapBusesCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapBusesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapBusesCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapBusesCollectionGeneric.ShowSet(); + } + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapBusesCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapBusesCollectionGeneric.ShowOnMap(); + } + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapBusesCollectionGeneric == 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 = _mapBusesCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/AccordionBus/AccordionBus/FormMap.resx b/AccordionBus/AccordionBus/FormMapWithSetBuses.resx similarity index 93% rename from AccordionBus/AccordionBus/FormMap.resx rename to AccordionBus/AccordionBus/FormMapWithSetBuses.resx index 2c0949d..f298a7b 100644 --- a/AccordionBus/AccordionBus/FormMap.resx +++ b/AccordionBus/AccordionBus/FormMapWithSetBuses.resx @@ -57,7 +57,4 @@ 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/AccordionBus/AccordionBus/Program.cs b/AccordionBus/AccordionBus/Program.cs index a2e0775..d792190 100644 --- a/AccordionBus/AccordionBus/Program.cs +++ b/AccordionBus/AccordionBus/Program.cs @@ -11,7 +11,7 @@ namespace AccordionBus // 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 FormMapWithSetBuses()); } } } \ No newline at end of file From 560c451cce7340c978132bfbe18afbf26c321969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D1=8F=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=D1=84=D0=BE=D1=80=D0=BE=D0=B2=D0=B0?= Date: Sun, 2 Oct 2022 22:26:58 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BD=D0=B8=D0=BC=D0=B0=D0=B5=D0=BC=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0=20=D0=B8=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D0=BE=D1=82=D1=80=D0=B8?= =?UTF-8?q?=D1=81=D0=BE=D0=B2=D0=BA=D0=B8=20=D1=84=D0=BE=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetBuses.Designer.cs | 20 +++++++++++-------- .../AccordionBus/MapWithSetBusesGeneric.cs | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/AccordionBus/AccordionBus/FormMapWithSetBuses.Designer.cs b/AccordionBus/AccordionBus/FormMapWithSetBuses.Designer.cs index e072b2e..d4e9a77 100644 --- a/AccordionBus/AccordionBus/FormMapWithSetBuses.Designer.cs +++ b/AccordionBus/AccordionBus/FormMapWithSetBuses.Designer.cs @@ -57,9 +57,9 @@ this.groupBox1.Controls.Add(this.buttonAddBus); this.groupBox1.Controls.Add(this.comboBoxSelectorMap); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBox1.Location = new System.Drawing.Point(599, 0); + this.groupBox1.Location = new System.Drawing.Point(832, 0); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(250, 525); + this.groupBox1.Size = new System.Drawing.Size(250, 553); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Инструменты"; @@ -69,44 +69,48 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AccordionBus.Properties.Resources.arrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(151, 452); + this.buttonRight.Location = new System.Drawing.Point(151, 480); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 10; this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.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::AccordionBus.Properties.Resources.arrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(115, 452); + this.buttonDown.Location = new System.Drawing.Point(115, 480); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 9; this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.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::AccordionBus.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(79, 452); + this.buttonLeft.Location = new System.Drawing.Point(79, 480); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 8; this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.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::AccordionBus.Properties.Resources.arrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(115, 416); + this.buttonUp.Location = new System.Drawing.Point(115, 444); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 7; this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // // maskedTextBoxPosition // @@ -174,7 +178,7 @@ 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(599, 525); + this.pictureBox.Size = new System.Drawing.Size(832, 553); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -182,7 +186,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(849, 525); + this.ClientSize = new System.Drawing.Size(1082, 553); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBox1); this.Name = "FormMapWithSetBuses"; diff --git a/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs b/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs index 1fc2b82..76a2298 100644 --- a/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs +++ b/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs @@ -27,11 +27,11 @@ namespace AccordionBus /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 400; + private readonly int _placeSizeWidth = 350; /// /// Размер занимаемого объектом места (высота) /// - private readonly int _placeSizeHeight = 100; + private readonly int _placeSizeHeight = 80; /// /// Набор объектов /// @@ -155,7 +155,7 @@ namespace AccordionBus g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++) { g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); } From 4ca174f9f320577102bab8a759771186c22f1933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D1=8F=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=D1=84=D0=BE=D1=80=D0=BE=D0=B2=D0=B0?= Date: Tue, 4 Oct 2022 10:02:59 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=20=D1=82=D0=B8=D0=BF=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0?= =?UTF-8?q?=D1=89=D0=B0=D0=B5=D0=BC=D0=BE=D0=B3=D0=BE=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=BE?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20=D1=81=D0=BB=D0=BE?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=20=D0=B2=D1=8B=D1=87?= =?UTF-8?q?=D0=B8=D1=82=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AccordionBus/AccordionBus/FormMapWithSetBuses.cs | 4 ++-- .../AccordionBus/MapWithSetBusesGeneric.cs | 4 ++-- AccordionBus/AccordionBus/SetBusesGeneric.cs | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/AccordionBus/AccordionBus/FormMapWithSetBuses.cs b/AccordionBus/AccordionBus/FormMapWithSetBuses.cs index 2b38408..cdba42a 100644 --- a/AccordionBus/AccordionBus/FormMapWithSetBuses.cs +++ b/AccordionBus/AccordionBus/FormMapWithSetBuses.cs @@ -65,7 +65,7 @@ namespace AccordionBus if (form.ShowDialog() == DialogResult.OK) { DrawningObjectBus bus = new(form.SelectedBus); - if (form.SelectedBus == null || !(_mapBusesCollectionGeneric + bus)) + if (form.SelectedBus == null || (_mapBusesCollectionGeneric + bus == -1)) { MessageBox.Show("Не удалось добавить объект"); } @@ -92,7 +92,7 @@ namespace AccordionBus return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapBusesCollectionGeneric - pos) + if (_mapBusesCollectionGeneric - pos != -1) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapBusesCollectionGeneric.ShowSet(); diff --git a/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs b/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs index 76a2298..751f7b2 100644 --- a/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs +++ b/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs @@ -61,7 +61,7 @@ namespace AccordionBus /// /// /// - public static bool operator +(MapWithSetBusesGeneric map, T bus) + public static int operator +(MapWithSetBusesGeneric map, T bus) { return map._setBuses.Insert(bus); } @@ -71,7 +71,7 @@ namespace AccordionBus /// /// /// - public static bool operator -(MapWithSetBusesGeneric map, int position) + public static int operator -(MapWithSetBusesGeneric map, int position) { return map._setBuses.Remove(position); } diff --git a/AccordionBus/AccordionBus/SetBusesGeneric.cs b/AccordionBus/AccordionBus/SetBusesGeneric.cs index 17ae571..02c3c15 100644 --- a/AccordionBus/AccordionBus/SetBusesGeneric.cs +++ b/AccordionBus/AccordionBus/SetBusesGeneric.cs @@ -34,7 +34,7 @@ namespace AccordionBus /// /// Добавляемый автобус /// - public bool Insert(T bus) + public int Insert(T bus) { return Insert(bus, 0); } @@ -44,12 +44,12 @@ namespace AccordionBus /// Добавляемый автобус /// Позиция /// - public bool Insert(T bus, int position) + public int Insert(T bus, int position) { //проверка позиции if (position < 0 || position >= Count) { - return false; + return -1; } //поиск пустой позиции int positionEmpty = position; @@ -62,7 +62,7 @@ namespace AccordionBus } if (positionEmpty == Count) { - return false; + return -1; } //сдвиг вправо for (; positionEmpty > position; positionEmpty--) @@ -70,21 +70,21 @@ namespace AccordionBus _places[positionEmpty] = _places[positionEmpty - 1]; } _places[position] = bus; - return true; + return position; } /// /// Удаление объекта из набора с конкретной позиции /// /// /// - public bool Remove(int position) + public int Remove(int position) { if (position < 0 || position >= Count) { - return false; + return -1; } _places[position] = null; - return true; + return position; } /// /// Получение объекта из набора по позиции