Сортировка

This commit is contained in:
Arklightning 2022-12-19 23:15:34 +04:00
parent 28682f5779
commit 9e07faa1b4
11 changed files with 275 additions and 32 deletions

View File

@ -7,7 +7,7 @@ using System.Drawing;
namespace Trolleybus namespace Trolleybus
{ {
internal abstract class AbstractMap internal abstract class AbstractMap : IEquatable<AbstractMap>
{ {
private IDrawningObject _drawningObject = null; private IDrawningObject _drawningObject = null;
protected int[,] _map = null; protected int[,] _map = null;
@ -136,5 +136,45 @@ namespace Trolleybus
protected abstract void GenerateMap(); protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j);
public bool Equals(AbstractMap? other)
{
if (other == null)
{
return false;
}
var otherMap = other as AbstractMap;
if (otherMap == null)
{
return false;
}
if (_width != otherMap._width)
{
return false;
}
if (_height != otherMap._height)
{
return false;
}
if (_size_x != otherMap._size_x)
{
return false;
}
if (_size_y != otherMap._size_y)
{
return false;
}
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] != otherMap._map[i, j])
{
return false;
}
}
}
return true;
}
} }
} }

View File

@ -8,9 +8,9 @@ using static System.Windows.Forms.AxHost;
namespace Trolleybus namespace Trolleybus
{ {
internal class DrawningObject : IDrawningObject internal class DrawningObject
{ {
private DrawingTrolleybus _trolleybus = null; public DrawingTrolleybus _trolleybus = null;
public DrawningObject(DrawingTrolleybus car) public DrawningObject(DrawingTrolleybus car)
{ {
@ -38,12 +38,5 @@ namespace Trolleybus
{ {
_trolleybus.SetPosition(x, y, width, height); _trolleybus.SetPosition(x, y, width, height);
} }
void IDrawningObject.DrawningObject(Graphics g)
{
_trolleybus.DrawTransport(g);
}
public string GetInfo() => _trolleybus?.GetDataForSave();
public static IDrawningObject Create(string data) => new DrawningObjectTrolleybus(data.CreateDrawingTrolleybus());
} }
} }

View File

@ -9,7 +9,7 @@ namespace Trolleybus
{ {
internal class DrawningObjectTrolleybus : IDrawningObject internal class DrawningObjectTrolleybus : IDrawningObject
{ {
private DrawingTrolleybus _trolleybus = null; public DrawingTrolleybus _trolleybus { get; private set; }
public DrawningObjectTrolleybus(DrawingTrolleybus trolleybus) public DrawningObjectTrolleybus(DrawingTrolleybus trolleybus)
{ {
@ -18,6 +18,8 @@ namespace Trolleybus
public float Step => _trolleybus?.Trolleybus?.Step ?? 0; public float Step => _trolleybus?.Trolleybus?.Step ?? 0;
public DrawingTrolleybus GetTrolleybus => _trolleybus;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{ {
return _trolleybus?.GetCurrentPosition() ?? default; return _trolleybus?.GetCurrentPosition() ?? default;
@ -43,11 +45,37 @@ namespace Trolleybus
_trolleybus.DrawTransport(g); _trolleybus.DrawTransport(g);
} }
public string GetInfo() => _trolleybus?.GetDataForSave(); public string GetInfo() => _trolleybus?.GetDataForSave() ?? string.Empty;
public static IDrawningObject Create(string data) public static IDrawningObject Create(string data)
{ {
return new DrawningObjectTrolleybus(data.CreateDrawingTrolleybus()); return new DrawningObjectTrolleybus(data.CreateDrawingTrolleybus());
} }
public bool Equals(IDrawningObject? other)
{
if (other is not DrawningObjectTrolleybus otherAirplane)
{
return false;
}
var entity = _trolleybus.Trolleybus;
var otherEntity = otherAirplane._trolleybus.Trolleybus;
if (entity.GetType() != otherEntity.GetType() ||
entity.Speed != otherEntity.Speed ||
entity.Weight != otherEntity.Weight ||
entity.BodyColor != otherEntity.BodyColor)
{
return false;
}
if (entity is EntitySmallTrolleybus entitySmallTrolleybus &&
otherEntity is EntitySmallTrolleybus otherEntityAirplaneWithRadar && (
entitySmallTrolleybus.BodyKit != otherEntityAirplaneWithRadar.BodyKit ||
entitySmallTrolleybus.DopColor != otherEntityAirplaneWithRadar.DopColor ||
entitySmallTrolleybus.Horns != otherEntityAirplaneWithRadar.Horns ||
entitySmallTrolleybus.Battary != otherEntityAirplaneWithRadar.Battary))
{
return false;
}
return true;
}
} }
} }

View File

@ -51,6 +51,8 @@
this.downloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.downloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.buttonSortByType = new System.Windows.Forms.Button();
this.buttonSortByColor = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
@ -59,6 +61,8 @@
// //
// groupBox1 // groupBox1
// //
this.groupBox1.Controls.Add(this.buttonSortByColor);
this.groupBox1.Controls.Add(this.buttonSortByType);
this.groupBox1.Controls.Add(this.groupBox2); this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.buttonLeft); this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Controls.Add(this.buttonRight); this.groupBox1.Controls.Add(this.buttonRight);
@ -70,11 +74,11 @@
this.groupBox1.Controls.Add(this.maskedTextBoxPosition); this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonAddTrolleybus); this.groupBox1.Controls.Add(this.buttonAddTrolleybus);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(900, 33); this.groupBox1.Location = new System.Drawing.Point(900, 36);
this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox1.Size = new System.Drawing.Size(300, 964); this.groupBox1.Size = new System.Drawing.Size(300, 1080);
this.groupBox1.TabIndex = 0; this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты"; this.groupBox1.Text = "Инструменты";
@ -153,7 +157,7 @@
// //
this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30; this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(120, 931); this.buttonLeft.Location = new System.Drawing.Point(124, 1021);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.buttonLeft.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(48, 48); this.buttonLeft.Size = new System.Drawing.Size(48, 48);
@ -165,7 +169,7 @@
// //
this.buttonRight.BackgroundImage = global::Trolleybus.Properties.Resources.right30; this.buttonRight.BackgroundImage = global::Trolleybus.Properties.Resources.right30;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(234, 931); this.buttonRight.Location = new System.Drawing.Point(238, 1021);
this.buttonRight.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.buttonRight.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(48, 48); this.buttonRight.Size = new System.Drawing.Size(48, 48);
@ -177,7 +181,7 @@
// //
this.buttonDown.BackgroundImage = global::Trolleybus.Properties.Resources.down30; this.buttonDown.BackgroundImage = global::Trolleybus.Properties.Resources.down30;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(177, 931); this.buttonDown.Location = new System.Drawing.Point(181, 1021);
this.buttonDown.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.buttonDown.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(48, 48); this.buttonDown.Size = new System.Drawing.Size(48, 48);
@ -189,7 +193,7 @@
// //
this.buttonUp.BackgroundImage = global::Trolleybus.Properties.Resources.up30; this.buttonUp.BackgroundImage = global::Trolleybus.Properties.Resources.up30;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(177, 874); this.buttonUp.Location = new System.Drawing.Point(181, 964);
this.buttonUp.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.buttonUp.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(48, 48); this.buttonUp.Size = new System.Drawing.Size(48, 48);
@ -199,7 +203,7 @@
// //
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(10, 786); this.buttonShowOnMap.Location = new System.Drawing.Point(14, 876);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(272, 35); this.buttonShowOnMap.Size = new System.Drawing.Size(272, 35);
@ -210,7 +214,7 @@
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(10, 725); this.buttonShowStorage.Location = new System.Drawing.Point(14, 815);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(272, 35); this.buttonShowStorage.Size = new System.Drawing.Size(272, 35);
@ -221,7 +225,7 @@
// //
// buttonRemoveTrolleybus // buttonRemoveTrolleybus
// //
this.buttonRemoveTrolleybus.Location = new System.Drawing.Point(9, 654); this.buttonRemoveTrolleybus.Location = new System.Drawing.Point(13, 744);
this.buttonRemoveTrolleybus.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.buttonRemoveTrolleybus.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonRemoveTrolleybus.Name = "buttonRemoveTrolleybus"; this.buttonRemoveTrolleybus.Name = "buttonRemoveTrolleybus";
this.buttonRemoveTrolleybus.Size = new System.Drawing.Size(273, 35); this.buttonRemoveTrolleybus.Size = new System.Drawing.Size(273, 35);
@ -232,7 +236,7 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 589); this.maskedTextBoxPosition.Location = new System.Drawing.Point(14, 679);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(270, 26); this.maskedTextBoxPosition.Size = new System.Drawing.Size(270, 26);
@ -240,7 +244,7 @@
// //
// buttonAddTrolleybus // buttonAddTrolleybus
// //
this.buttonAddTrolleybus.Location = new System.Drawing.Point(10, 523); this.buttonAddTrolleybus.Location = new System.Drawing.Point(14, 613);
this.buttonAddTrolleybus.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.buttonAddTrolleybus.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonAddTrolleybus.Name = "buttonAddTrolleybus"; this.buttonAddTrolleybus.Name = "buttonAddTrolleybus";
this.buttonAddTrolleybus.Size = new System.Drawing.Size(272, 35); this.buttonAddTrolleybus.Size = new System.Drawing.Size(272, 35);
@ -252,10 +256,10 @@
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 33); this.pictureBox.Location = new System.Drawing.Point(0, 36);
this.pictureBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.pictureBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(900, 964); this.pictureBox.Size = new System.Drawing.Size(900, 1080);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -267,7 +271,7 @@
this.FiletoolStripMenuItem}); this.FiletoolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1200, 33); this.menuStrip1.Size = new System.Drawing.Size(1200, 36);
this.menuStrip1.TabIndex = 2; this.menuStrip1.TabIndex = 2;
this.menuStrip1.Text = "menuStrip1"; this.menuStrip1.Text = "menuStrip1";
// //
@ -277,20 +281,20 @@
this.saveToolStripMenuItem, this.saveToolStripMenuItem,
this.downloadToolStripMenuItem}); this.downloadToolStripMenuItem});
this.FiletoolStripMenuItem.Name = "FiletoolStripMenuItem"; this.FiletoolStripMenuItem.Name = "FiletoolStripMenuItem";
this.FiletoolStripMenuItem.Size = new System.Drawing.Size(54, 29); this.FiletoolStripMenuItem.Size = new System.Drawing.Size(54, 32);
this.FiletoolStripMenuItem.Text = "File"; this.FiletoolStripMenuItem.Text = "File";
// //
// saveToolStripMenuItem // saveToolStripMenuItem
// //
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.saveToolStripMenuItem.Size = new System.Drawing.Size(196, 34);
this.saveToolStripMenuItem.Text = "Save"; this.saveToolStripMenuItem.Text = "Save";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
// //
// downloadToolStripMenuItem // downloadToolStripMenuItem
// //
this.downloadToolStripMenuItem.Name = "downloadToolStripMenuItem"; this.downloadToolStripMenuItem.Name = "downloadToolStripMenuItem";
this.downloadToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.downloadToolStripMenuItem.Size = new System.Drawing.Size(196, 34);
this.downloadToolStripMenuItem.Text = "Download"; this.downloadToolStripMenuItem.Text = "Download";
this.downloadToolStripMenuItem.Click += new System.EventHandler(this.downloadToolStripMenuItem_Click); this.downloadToolStripMenuItem.Click += new System.EventHandler(this.downloadToolStripMenuItem_Click);
// //
@ -302,11 +306,31 @@
// //
this.saveFileDialog.Filter = "txt file | *.txt"; this.saveFileDialog.Filter = "txt file | *.txt";
// //
// buttonSortByType
//
this.buttonSortByType.Location = new System.Drawing.Point(14, 506);
this.buttonSortByType.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonSortByType.Name = "buttonSortByType";
this.buttonSortByType.Size = new System.Drawing.Size(272, 35);
this.buttonSortByType.TabIndex = 10;
this.buttonSortByType.Text = "Сортировать по типу";
this.buttonSortByType.UseVisualStyleBackColor = true;
//
// buttonSortByColor
//
this.buttonSortByColor.Location = new System.Drawing.Point(14, 551);
this.buttonSortByColor.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.buttonSortByColor.Name = "buttonSortByColor";
this.buttonSortByColor.Size = new System.Drawing.Size(272, 35);
this.buttonSortByColor.TabIndex = 11;
this.buttonSortByColor.Text = "Сортировать по цвету";
this.buttonSortByColor.UseVisualStyleBackColor = true;
//
// FormMapWithSetTrolleybus // FormMapWithSetTrolleybus
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1200, 997); this.ClientSize = new System.Drawing.Size(1200, 1116);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.Controls.Add(this.menuStrip1); this.Controls.Add(this.menuStrip1);
@ -351,5 +375,7 @@
private System.Windows.Forms.ToolStripMenuItem downloadToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem downloadToolStripMenuItem;
private System.Windows.Forms.OpenFileDialog openFileDialog; private System.Windows.Forms.OpenFileDialog openFileDialog;
private System.Windows.Forms.SaveFileDialog saveFileDialog; private System.Windows.Forms.SaveFileDialog saveFileDialog;
private System.Windows.Forms.Button buttonSortByColor;
private System.Windows.Forms.Button buttonSortByType;
} }
} }

View File

@ -254,7 +254,29 @@ namespace Trolleybus
MessageBox.Show("Не получилось загрузить файл", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Не получилось загрузить файл", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
}
private void buttonSortByType_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new TrolleybusCompareByType());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Сортировка по цвету
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSortByColor_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new TrolleybusCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
} }
} }

View File

@ -7,7 +7,7 @@ using System.Drawing;
namespace Trolleybus namespace Trolleybus
{ {
internal interface IDrawningObject internal interface IDrawningObject : IEquatable<IDrawningObject>
{ {
/// <summary> /// <summary>
/// Шаг перемещения объекта /// Шаг перемещения объекта

View File

@ -130,6 +130,12 @@ namespace Trolleybus
_setTrolleybus.Insert(DrawningObjectTrolleybus.Create(rec) as T); _setTrolleybus.Insert(DrawningObjectTrolleybus.Create(rec) as T);
} }
} }
public void Sort(IComparer<T> comparer)
{
_setTrolleybus.SortSet(comparer);
}
/// <summary> /// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале /// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary> /// </summary>

View File

@ -86,5 +86,14 @@ namespace Trolleybus
} }
} }
} }
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
} }
} }

View File

@ -145,6 +145,8 @@
<Compile Include="SetTrolleybusGeneric.cs" /> <Compile Include="SetTrolleybusGeneric.cs" />
<Compile Include="SimpleMap.cs" /> <Compile Include="SimpleMap.cs" />
<Compile Include="StorageOverflowException.cs" /> <Compile Include="StorageOverflowException.cs" />
<Compile Include="TrolleybusCompareByColor.cs" />
<Compile Include="TrolleybusCompareByType.cs" />
<Compile Include="TrolleybusDelegate.cs" /> <Compile Include="TrolleybusDelegate.cs" />
<Compile Include="TrolleybusNotFoundException.cs" /> <Compile Include="TrolleybusNotFoundException.cs" />
<EmbeddedResource Include="Form1.resx"> <EmbeddedResource Include="Form1.resx">

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Trolleybus
{
internal class TrolleybusCompareByColor : IComparer<IDrawningObject>
{
public int Compare(IDrawningObject? x, IDrawningObject? y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xTrolleybus = x as DrawningObjectTrolleybus;
var yTrolleybus = y as DrawningObjectTrolleybus;
if (xTrolleybus == null && yTrolleybus == null)
{
return 0;
}
if (xTrolleybus == null && yTrolleybus != null)
{
return 1;
}
if (xTrolleybus != null && yTrolleybus == null)
{
return -1;
}
var xEntityTrolleybus = xTrolleybus._trolleybus.Trolleybus;
var yEntityTrolleybus = yTrolleybus._trolleybus.Trolleybus;
var baseColorCompare = xEntityTrolleybus.BodyColor.ToArgb().CompareTo(yEntityTrolleybus.BodyColor.ToArgb());
if (baseColorCompare != 0)
{
return baseColorCompare;
}
if (xEntityTrolleybus is EntitySmallTrolleybus xSmallTrolleybus && yEntityTrolleybus is EntitySmallTrolleybus ySmallTrolleybus)
{
var dopColorCompare = xSmallTrolleybus.DopColor.ToArgb().CompareTo(ySmallTrolleybus.DopColor.ToArgb());
if (dopColorCompare != 0)
{
return dopColorCompare;
}
}
var speedCompare = xTrolleybus._trolleybus.Trolleybus.Speed.CompareTo(yTrolleybus._trolleybus.Trolleybus.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xTrolleybus._trolleybus.Trolleybus.Weight.CompareTo(yTrolleybus._trolleybus.Trolleybus.Weight);
}
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Trolleybus
{
internal class TrolleybusCompareByType : IComparer<IDrawningObject>
{
public int Compare(IDrawningObject? x, IDrawningObject? y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xTrolleybus = x as DrawningObjectTrolleybus;
var yTrolleybus = y as DrawningObjectTrolleybus;
if (xTrolleybus == null && yTrolleybus == null)
{
return 0;
}
if (xTrolleybus == null && yTrolleybus != null)
{
return 1;
}
if (xTrolleybus != null && yTrolleybus == null)
{
return -1;
}
if (xTrolleybus.GetTrolleybus.GetType().Name != yTrolleybus.GetTrolleybus.GetType().Name)
{
if (xTrolleybus.GetTrolleybus.GetType().Name == "DrawningAirplane")
{
return -1;
}
return 1;
}
var speedCompare = xTrolleybus.GetTrolleybus.Trolleybus.Speed.CompareTo(yTrolleybus.GetTrolleybus.Trolleybus.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xTrolleybus.GetTrolleybus.Trolleybus.Weight.CompareTo(yTrolleybus.GetTrolleybus.Trolleybus.Weight);
}
}
}