From e527ff439b5a99192014caee8e45d1eca4b0bc86 Mon Sep 17 00:00:00 2001 From: shadowik Date: Sun, 11 Dec 2022 23:00:22 +0400 Subject: [PATCH 1/5] Initial --- .../DoubleDeckerBus/BusCompareByColor.cs | 17 ++ .../DoubleDeckerBus/BusCompareByType.cs | 56 ++++++ .../DoubleDeckerBus/DrawingObjectBus.cs | 33 +++- .../FormMapWithSetBuses.Designer.cs | 169 ++++++++++-------- .../DoubleDeckerBus/FormMapWithSetBuses.cs | 14 ++ .../DoubleDeckerBus/IDrawingObject.cs | 2 +- .../DoubleDeckerBus/MapWithSetBusesGeneric.cs | 6 +- .../DoubleDeckerBus/SetBusesGeneric.cs | 11 +- 8 files changed, 227 insertions(+), 81 deletions(-) create mode 100644 DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs create mode 100644 DoubleDeckerBus/DoubleDeckerBus/BusCompareByType.cs diff --git a/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs new file mode 100644 index 0000000..ed65f61 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus +{ + internal class BusCompareByColor : IComparer + { + public int Compare(IDrawingObject? x, IDrawingObject? y) + { + // TODO реализовать + throw new NotImplementedException(); + } + } +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/BusCompareByType.cs b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByType.cs new file mode 100644 index 0000000..ffcc286 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByType.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus +{ + internal class BusCompareByType : IComparer + { + public int Compare(IDrawingObject? x, IDrawingObject? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xBus = x as DrawingObjectBus; + var yBus = y as DrawingObjectBus; + if (xBus == null && yBus == null) + { + return 0; + } + if (xBus == null && yBus != null) + { + return 1; + } + if (xBus != null && yBus == null) + { + return -1; + } + if (xBus.GetBus.GetType().Name != yBus.GetBus.GetType().Name) + { + if (xBus.GetBus.GetType().Name == "DrawingBus") + { + return -1; + } + return 1; + } + var speedCompare = xBus.GetBus.Bus.Speed.CompareTo(yBus.GetBus.Bus.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xBus.GetBus.Bus.Weight.CompareTo(yBus.GetBus.Bus.Weight); + } + } +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs index f881878..b1deb0d 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs @@ -59,7 +59,38 @@ namespace DoubleDeckerBus public DrawingBus getBus() { - return _bus; + throw new NotImplementedException(); } + + public bool Equals(IDrawingObject? other) + { + if (other == null) + { + return false; + } + var otherBus = other as DrawingObjectBus; + if (otherBus == null) + { + return false; + } + var bus = _bus.Bus; + var otherCarCar = otherBus._bus.Bus; + if (bus.Speed != otherCarCar.Speed) + { + return false; + } + if (bus.Weight != otherCarCar.Weight) + { + return false; + } + if (bus.BodyColor != otherCarCar.BodyColor) + { + return false; + } + // TODO доделать проверки в случае продвинутого объекта + return true; + } + + public DrawingBus GetBus => _bus; } } diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.Designer.cs b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.Designer.cs index aaaad2f..3f4dbfc 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.Designer.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.Designer.cs @@ -39,8 +39,6 @@ this.buttonDown = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); - this.button1 = new System.Windows.Forms.Button(); - this.buttonShowStorage = new System.Windows.Forms.Button(); this.buttonDeleteBus = new System.Windows.Forms.Button(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonAddBus = new System.Windows.Forms.Button(); @@ -51,6 +49,10 @@ this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.button1 = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.ButtonSortByColor = new System.Windows.Forms.Button(); + this.ButtonSortByType = new System.Windows.Forms.Button(); this.groupBoxSettings.SuspendLayout(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); @@ -59,6 +61,8 @@ // // groupBoxSettings // + this.groupBoxSettings.Controls.Add(this.ButtonSortByColor); + this.groupBoxSettings.Controls.Add(this.ButtonSortByType); this.groupBoxSettings.Controls.Add(this.groupBox1); this.groupBoxSettings.Controls.Add(this.buttonRight); this.groupBoxSettings.Controls.Add(this.buttonDown); @@ -70,11 +74,9 @@ this.groupBoxSettings.Controls.Add(this.maskedTextBoxPosition); this.groupBoxSettings.Controls.Add(this.buttonAddBus); this.groupBoxSettings.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxSettings.Location = new System.Drawing.Point(737, 28); - this.groupBoxSettings.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxSettings.Location = new System.Drawing.Point(645, 24); this.groupBoxSettings.Name = "groupBoxSettings"; - this.groupBoxSettings.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.groupBoxSettings.Size = new System.Drawing.Size(229, 829); + this.groupBoxSettings.Size = new System.Drawing.Size(200, 710); this.groupBoxSettings.TabIndex = 0; this.groupBoxSettings.TabStop = false; this.groupBoxSettings.Text = "Инструменты"; @@ -86,11 +88,9 @@ this.groupBox1.Controls.Add(this.ButtonAddMap); this.groupBox1.Controls.Add(this.textBoxNewMapName); this.groupBox1.Controls.Add(this.comboBoxSelectorMap); - this.groupBox1.Location = new System.Drawing.Point(0, 29); - this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBox1.Location = new System.Drawing.Point(0, 22); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.groupBox1.Size = new System.Drawing.Size(229, 452); + this.groupBox1.Size = new System.Drawing.Size(200, 339); this.groupBox1.TabIndex = 11; this.groupBox1.TabStop = false; this.groupBox1.Text = "Карты"; @@ -98,20 +98,18 @@ // listBoxMaps // this.listBoxMaps.FormattingEnabled = true; - this.listBoxMaps.ItemHeight = 20; - this.listBoxMaps.Location = new System.Drawing.Point(7, 200); - this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.listBoxMaps.ItemHeight = 15; + this.listBoxMaps.Location = new System.Drawing.Point(6, 150); this.listBoxMaps.Name = "listBoxMaps"; - this.listBoxMaps.Size = new System.Drawing.Size(214, 164); + this.listBoxMaps.Size = new System.Drawing.Size(188, 124); this.listBoxMaps.TabIndex = 4; this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged); // // ButtonDeleteMap // - this.ButtonDeleteMap.Location = new System.Drawing.Point(7, 373); - this.ButtonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonDeleteMap.Location = new System.Drawing.Point(6, 280); this.ButtonDeleteMap.Name = "ButtonDeleteMap"; - this.ButtonDeleteMap.Size = new System.Drawing.Size(222, 71); + this.ButtonDeleteMap.Size = new System.Drawing.Size(194, 53); this.ButtonDeleteMap.TabIndex = 3; this.ButtonDeleteMap.Text = "Удалить карту"; this.ButtonDeleteMap.UseVisualStyleBackColor = true; @@ -119,10 +117,9 @@ // // ButtonAddMap // - this.ButtonAddMap.Location = new System.Drawing.Point(7, 112); - this.ButtonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonAddMap.Location = new System.Drawing.Point(6, 84); this.ButtonAddMap.Name = "ButtonAddMap"; - this.ButtonAddMap.Size = new System.Drawing.Size(222, 71); + this.ButtonAddMap.Size = new System.Drawing.Size(194, 53); this.ButtonAddMap.TabIndex = 2; this.ButtonAddMap.Text = "Добавить карту"; this.ButtonAddMap.UseVisualStyleBackColor = true; @@ -130,19 +127,17 @@ // // textBoxNewMapName // - this.textBoxNewMapName.Location = new System.Drawing.Point(7, 29); - this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxNewMapName.Location = new System.Drawing.Point(6, 22); this.textBoxNewMapName.Name = "textBoxNewMapName"; - this.textBoxNewMapName.Size = new System.Drawing.Size(214, 27); + this.textBoxNewMapName.Size = new System.Drawing.Size(188, 23); this.textBoxNewMapName.TabIndex = 1; // // comboBoxSelectorMap // this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 73); - this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 55); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(214, 28); + this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23); this.comboBoxSelectorMap.TabIndex = 0; // // buttonRight @@ -150,9 +145,10 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.RightArrow; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(125, 760); + this.buttonRight.Location = new System.Drawing.Point(109, 658); + this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 29); + this.buttonRight.Size = new System.Drawing.Size(26, 22); this.buttonRight.TabIndex = 10; this.buttonRight.Text = " "; this.buttonRight.UseVisualStyleBackColor = true; @@ -163,9 +159,10 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.DownArrow; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(98, 785); + this.buttonDown.Location = new System.Drawing.Point(86, 677); + this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 29); + this.buttonDown.Size = new System.Drawing.Size(26, 22); this.buttonDown.TabIndex = 9; this.buttonDown.Text = " "; this.buttonDown.UseVisualStyleBackColor = true; @@ -176,9 +173,10 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.LeftArrow; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(72, 760); + this.buttonLeft.Location = new System.Drawing.Point(63, 658); + this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 29); + this.buttonLeft.Size = new System.Drawing.Size(26, 22); this.buttonLeft.TabIndex = 8; this.buttonLeft.Text = " "; this.buttonLeft.UseVisualStyleBackColor = true; @@ -189,42 +187,20 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.UpArrow; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(97, 735); + this.buttonUp.Location = new System.Drawing.Point(85, 639); + this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 29); + this.buttonUp.Size = new System.Drawing.Size(26, 22); this.buttonUp.TabIndex = 7; this.buttonUp.Text = " "; this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // - // button1 - // - this.button1.Location = new System.Drawing.Point(7, 695); - this.button1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(208, 47); - this.button1.TabIndex = 5; - this.button1.Text = "Посмотреть карту"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.ButtonShowOnMap_Click); - // - // buttonShowStorage - // - this.buttonShowStorage.Location = new System.Drawing.Point(7, 640); - this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.buttonShowStorage.Name = "buttonShowStorage"; - this.buttonShowStorage.Size = new System.Drawing.Size(208, 47); - this.buttonShowStorage.TabIndex = 4; - this.buttonShowStorage.Text = "Посмотреть хранилище"; - this.buttonShowStorage.UseVisualStyleBackColor = true; - this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); - // // buttonDeleteBus // - this.buttonDeleteBus.Location = new System.Drawing.Point(7, 584); - this.buttonDeleteBus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDeleteBus.Location = new System.Drawing.Point(6, 522); this.buttonDeleteBus.Name = "buttonDeleteBus"; - this.buttonDeleteBus.Size = new System.Drawing.Size(215, 48); + this.buttonDeleteBus.Size = new System.Drawing.Size(188, 36); this.buttonDeleteBus.TabIndex = 3; this.buttonDeleteBus.Text = "Удалить автобус"; this.buttonDeleteBus.UseVisualStyleBackColor = true; @@ -232,19 +208,17 @@ // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 545); - this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 493); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(214, 27); + this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23); this.maskedTextBoxPosition.TabIndex = 2; // // buttonAddBus // - this.buttonAddBus.Location = new System.Drawing.Point(7, 489); - this.buttonAddBus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAddBus.Location = new System.Drawing.Point(6, 451); this.buttonAddBus.Name = "buttonAddBus"; - this.buttonAddBus.Size = new System.Drawing.Size(215, 48); + this.buttonAddBus.Size = new System.Drawing.Size(188, 36); this.buttonAddBus.TabIndex = 1; this.buttonAddBus.Text = "Добавить автобус"; this.buttonAddBus.UseVisualStyleBackColor = true; @@ -253,10 +227,9 @@ // pictureBox // this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox.Location = new System.Drawing.Point(0, 28); - this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.pictureBox.Location = new System.Drawing.Point(0, 24); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(737, 829); + this.pictureBox.Size = new System.Drawing.Size(645, 710); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -267,7 +240,8 @@ this.FileToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(966, 28); + this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); + this.menuStrip1.Size = new System.Drawing.Size(845, 24); this.menuStrip1.TabIndex = 2; this.menuStrip1.Text = "menuStrip1"; // @@ -277,20 +251,20 @@ this.SaveToolStripMenuItem, this.LoadToolStripMenuItem}); this.FileToolStripMenuItem.Name = "FileToolStripMenuItem"; - this.FileToolStripMenuItem.Size = new System.Drawing.Size(59, 24); + this.FileToolStripMenuItem.Size = new System.Drawing.Size(48, 20); this.FileToolStripMenuItem.Text = "Файл"; // // SaveToolStripMenuItem // this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; - this.SaveToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.SaveToolStripMenuItem.Size = new System.Drawing.Size(141, 22); this.SaveToolStripMenuItem.Text = "Сохранение"; this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); // // LoadToolStripMenuItem // this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; - this.LoadToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.LoadToolStripMenuItem.Size = new System.Drawing.Size(141, 22); this.LoadToolStripMenuItem.Text = "Загрузка"; this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); // @@ -303,16 +277,55 @@ // this.saveFileDialog.Filter = "txt file | *.txt"; // + // button1 + // + this.button1.Location = new System.Drawing.Point(6, 605); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(182, 35); + this.button1.TabIndex = 5; + this.button1.Text = "Посмотреть карту"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(6, 564); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(182, 35); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // ButtonSortByColor + // + this.ButtonSortByColor.Location = new System.Drawing.Point(12, 402); + this.ButtonSortByColor.Name = "ButtonSortByColor"; + this.ButtonSortByColor.Size = new System.Drawing.Size(182, 35); + this.ButtonSortByColor.TabIndex = 13; + this.ButtonSortByColor.Text = "Сортировать по цвету"; + this.ButtonSortByColor.UseVisualStyleBackColor = true; + this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click); + // + // ButtonSortByType + // + this.ButtonSortByType.Location = new System.Drawing.Point(12, 361); + this.ButtonSortByType.Name = "ButtonSortByType"; + this.ButtonSortByType.Size = new System.Drawing.Size(182, 35); + this.ButtonSortByType.TabIndex = 12; + this.ButtonSortByType.Text = "Сортировать по типу"; + this.ButtonSortByType.UseVisualStyleBackColor = true; + this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click); + // // FormMapWithSetBuses // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(966, 857); + this.ClientSize = new System.Drawing.Size(845, 734); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxSettings); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormMapWithSetBuses"; this.Text = "Карты с набором объектов"; this.groupBoxSettings.ResumeLayout(false); @@ -334,8 +347,6 @@ private Button buttonAddBus; private Button buttonDeleteBus; private MaskedTextBox maskedTextBoxPosition; - private Button buttonShowStorage; - private Button button1; private Button buttonRight; private Button buttonDown; private Button buttonLeft; @@ -352,5 +363,9 @@ private ToolStripMenuItem LoadToolStripMenuItem; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; + private Button ButtonSortByColor; + private Button ButtonSortByType; + private Button button1; + private Button buttonShowStorage; } } \ No newline at end of file diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs index 35a549d..67c7551 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs @@ -248,6 +248,20 @@ namespace DoubleDeckerBus } } } + + private void ButtonSortByType_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].Sort(new BusCompareByType()); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + + private void ButtonSortByColor_Click(object sender, EventArgs e) + { + // TODO прописать логику + } } } diff --git a/DoubleDeckerBus/DoubleDeckerBus/IDrawingObject.cs b/DoubleDeckerBus/DoubleDeckerBus/IDrawingObject.cs index 2e091e9..6189a44 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/IDrawingObject.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/IDrawingObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace DoubleDeckerBus { - internal interface IDrawingObject + internal interface IDrawingObject : IEquatable { public DrawingBus getBus(); public float Step { get; } diff --git a/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs b/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs index 66aed8b..936d06d 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace DoubleDeckerBus { internal class MapWithSetBusesGeneric - where T : class, IDrawingObject + where T : class, IDrawingObject, IEquatable where U : AbstractMap { @@ -158,5 +158,9 @@ namespace DoubleDeckerBus _setBuses.Insert(DrawingObjectBus.Create(rec) as T); } } + + public void Sort(IComparer comparer) { + _setBuses.SortSet(comparer); + } } } diff --git a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs index a0a4123..3897636 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace DoubleDeckerBus { internal class SetBusesGeneric - where T : IDrawingObject + where T : class, IEquatable { private readonly List _places; @@ -29,6 +29,8 @@ namespace DoubleDeckerBus public int Insert(T bus, int position) { + // TODO Проверка на уникальность + if (position < 0 || position >= _maxCount) { throw new BusNotFoundException("Место указано неверно"); @@ -75,5 +77,12 @@ namespace DoubleDeckerBus } } } + + public void SortSet(IComparer comparer) { + if (comparer == null) { + return; + } + _places.Sort(comparer); + } } } -- 2.25.1 From 4fd89af30ed1c120327e5b2344c64d4a13892869 Mon Sep 17 00:00:00 2001 From: shadowik Date: Sun, 11 Dec 2022 23:17:18 +0400 Subject: [PATCH 2/5] All without change Insert --- .../DoubleDeckerBus/BusCompareByColor.cs | 45 ++++++++++++++++++- .../DoubleDeckerBus/DrawingObjectBus.cs | 21 ++++++++- .../DoubleDeckerBus/FormMapWithSetBuses.cs | 7 ++- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs index ed65f61..166b266 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs @@ -10,8 +10,49 @@ namespace DoubleDeckerBus { public int Compare(IDrawingObject? x, IDrawingObject? y) { - // TODO реализовать - throw new NotImplementedException(); + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xBus = x as DrawingObjectBus; + var yBus = y as DrawingObjectBus; + if (xBus == null && yBus == null) + { + return 0; + } + if (xBus == null && yBus != null) + { + return 1; + } + if (xBus != null && yBus == null) + { + return -1; + } + + var baseColorCompare = xBus.GetBus.Bus.BodyColor.ToString().CompareTo(yBus.GetBus.Bus.BodyColor.ToString()); + if (baseColorCompare != 0) + { + return baseColorCompare; + } + + if (xBus.GetBus.Bus is EntityDDB xDDB && yBus.GetBus.Bus is EntityDDB yDDB) { + var extraColorCompare = xDDB.BodyColor.ToString().CompareTo(yDDB.BodyColor.ToString()); + if (extraColorCompare != 0) + { + return extraColorCompare; + } + } + + return 0; } } + } } diff --git a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs index b1deb0d..b845317 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs @@ -87,7 +87,26 @@ namespace DoubleDeckerBus { return false; } - // TODO доделать проверки в случае продвинутого объекта + + if (bus is EntityDDB DDB) { + if (other is not EntityDDB otherDDB) { + return false; + } + + if (DDB.Ledder != otherDDB.Ledder) { + return false; + } + + if (DDB.SecondStage != otherDDB.SecondStage) { + return false; + } + + if (DDB.ExtraColor != otherDDB.ExtraColor) + { + return false; + } + } + return true; } diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs index 67c7551..a5458cb 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs @@ -260,7 +260,12 @@ namespace DoubleDeckerBus private void ButtonSortByColor_Click(object sender, EventArgs e) { - // TODO прописать логику + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].Sort(new BusCompareByColor()); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } } } -- 2.25.1 From 8be22de9a824285d3fba8b88bf6f9ced921d3a6e Mon Sep 17 00:00:00 2001 From: shadowik Date: Sun, 11 Dec 2022 23:17:41 +0400 Subject: [PATCH 3/5] fix --- DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs index 166b266..66b2b20 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs @@ -54,5 +54,5 @@ namespace DoubleDeckerBus return 0; } } - } + } -- 2.25.1 From 85f5d7f093aec85a69bb691d8bc44af72c7e3528 Mon Sep 17 00:00:00 2001 From: shadowik Date: Mon, 12 Dec 2022 20:33:30 +0400 Subject: [PATCH 4/5] Final --- DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs index 3897636..656e894 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs @@ -29,7 +29,10 @@ namespace DoubleDeckerBus public int Insert(T bus, int position) { - // TODO Проверка на уникальность + if (_places.Contains(bus)) + { + throw new ArgumentException("The same bus exist"); + } if (position < 0 || position >= _maxCount) { -- 2.25.1 From 60be921810277b9cb4ecdececb06a29a4fa2acac Mon Sep 17 00:00:00 2001 From: shadowik Date: Thu, 15 Dec 2022 06:23:03 +0400 Subject: [PATCH 5/5] Final --- .../DoubleDeckerBus/DrawingObjectBus.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs index b845317..77e7525 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs @@ -74,24 +74,26 @@ namespace DoubleDeckerBus return false; } var bus = _bus.Bus; - var otherCarCar = otherBus._bus.Bus; - if (bus.Speed != otherCarCar.Speed) + var otherBusBus = otherBus._bus.Bus; + if (bus.GetType().Name != otherBusBus.GetType().Name) { return false; } - if (bus.Weight != otherCarCar.Weight) + if (bus.Speed != otherBusBus.Speed) { return false; } - if (bus.BodyColor != otherCarCar.BodyColor) + if (bus.Weight != otherBusBus.Weight) + { + return false; + } + if (bus.BodyColor != otherBusBus.BodyColor) { return false; } - if (bus is EntityDDB DDB) { - if (other is not EntityDDB otherDDB) { - return false; - } + if (bus is EntityDDB DDB && otherBusBus is EntityDDB otherDDB) + { if (DDB.Ledder != otherDDB.Ledder) { return false; @@ -105,6 +107,7 @@ namespace DoubleDeckerBus { return false; } + } return true; -- 2.25.1