LabWork08 Zacharchenko PIbd-21 #9

Closed
shadowik wants to merge 5 commits from LabWork08 into LabWork07
8 changed files with 298 additions and 81 deletions

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDeckerBus
{
internal class BusCompareByColor : IComparer<IDrawingObject>
{
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;
}
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;
}
}
}

View File

@ -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<IDrawingObject>
{
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);
}
}
}

View File

@ -59,7 +59,60 @@ 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 otherBusBus = otherBus._bus.Bus;
if (bus.GetType().Name != otherBusBus.GetType().Name)
{
return false;
}
if (bus.Speed != otherBusBus.Speed)
{
return false;
}
if (bus.Weight != otherBusBus.Weight)
{
return false;
}
if (bus.BodyColor != otherBusBus.BodyColor)
{
return false;
}
if (bus is EntityDDB DDB && otherBusBus is EntityDDB otherDDB)
{
if (DDB.Ledder != otherDDB.Ledder) {
return false;
}
if (DDB.SecondStage != otherDDB.SecondStage) {
return false;
}
if (DDB.ExtraColor != otherDDB.ExtraColor)
{
return false;
}
}
return true;
}
public DrawingBus GetBus => _bus;
}
}

View File

@ -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;
}
}

View File

@ -248,6 +248,25 @@ 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)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].Sort(new BusCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace DoubleDeckerBus
{
internal interface IDrawingObject
internal interface IDrawingObject : IEquatable<IDrawingObject>
{
public DrawingBus getBus();
public float Step { get; }

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace DoubleDeckerBus
{
internal class MapWithSetBusesGeneric<T, U>
where T : class, IDrawingObject
where T : class, IDrawingObject, IEquatable<T>
where U : AbstractMap
{
@ -158,5 +158,9 @@ namespace DoubleDeckerBus
_setBuses.Insert(DrawingObjectBus.Create(rec) as T);
}
}
public void Sort(IComparer<T> comparer) {
_setBuses.SortSet(comparer);
}
}
}

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace DoubleDeckerBus
{
internal class SetBusesGeneric<T>
where T : IDrawingObject
where T : class, IEquatable<T>
{
private readonly List<T> _places;
@ -29,6 +29,11 @@ namespace DoubleDeckerBus
public int Insert(T bus, int position)
{
if (_places.Contains(bus))
{
throw new ArgumentException("The same bus exist");
}
if (position < 0 || position >= _maxCount)
{
throw new BusNotFoundException("Место указано неверно");
@ -75,5 +80,12 @@ namespace DoubleDeckerBus
}
}
}
public void SortSet(IComparer<T> comparer) {
if (comparer == null) {
return;
}
_places.Sort(comparer);
}
}
}