Morozov V.S LabWork08 #9
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirPlaneWithRadar
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||
{
|
||||
private IDrawingObject _drawningObject = null;
|
||||
protected int[,] _map = null;
|
||||
@ -145,5 +145,37 @@ namespace AirPlaneWithRadar
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
|
||||
public string ArrToStr(int[,] arr)
|
||||
{
|
||||
string res = "";
|
||||
foreach (int i in arr)
|
||||
{
|
||||
res += i;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public bool Equals(AbstractMap? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var curMap = this;
|
||||
var otherMap = other;
|
||||
if (curMap._height != otherMap._height)
|
||||
return false;
|
||||
if (curMap._width != otherMap._width)
|
||||
return false;
|
||||
if (curMap._size_x != otherMap._size_x)
|
||||
return false;
|
||||
if (curMap._size_y != otherMap._size_y)
|
||||
return false;
|
||||
string arr1 = ArrToStr(curMap._map);
|
||||
string arr2 = ArrToStr(curMap._map);
|
||||
if (!arr1.Equals(arr2))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,10 +34,52 @@ namespace AirPlaneWithRadar
|
||||
{
|
||||
_plain?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public DrawingPlain GetPlane => _plain;
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_plain.setPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
public bool Equals(IDrawingObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherPlain = other as DrawingObjectPlane;
|
||||
if (otherPlain == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var plain = _plain.Plain;
|
||||
var otherPlainPlain = otherPlain._plain.Plain;
|
||||
|
||||
if (plain.Speed != otherPlainPlain.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (plain.Weight != otherPlainPlain.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (plain.BodyColor != otherPlainPlain.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var RadPlain = plain as RadioPlane;
|
||||
var otherRadPlain = otherPlainPlain as RadioPlane;
|
||||
if (RadPlain == null && otherRadPlain == null)
|
||||
return true;
|
||||
if (RadPlain == null || otherRadPlain == null)
|
||||
return false;
|
||||
if (!(RadPlain.DopColor.Equals(otherRadPlain.DopColor)))
|
||||
return false;
|
||||
if (!(RadPlain.Radar.Equals(otherRadPlain.Radar)))
|
||||
return false;
|
||||
if (!(RadPlain.OilBox.Equals(otherRadPlain.OilBox)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,8 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonSortByType = new System.Windows.Forms.Button();
|
||||
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||
@ -57,8 +59,30 @@
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
this.buttonSortByType.Location = new System.Drawing.Point(20, 368);
|
||||
this.buttonSortByType.Name = "buttonSortByType";
|
||||
this.buttonSortByType.Size = new System.Drawing.Size(196, 47);
|
||||
this.buttonSortByType.TabIndex = 12;
|
||||
this.buttonSortByType.Text = "Сортировать по типу";
|
||||
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
this.buttonSortByColor.Location = new System.Drawing.Point(23, 432);
|
||||
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||
this.buttonSortByColor.Size = new System.Drawing.Size(196, 47);
|
||||
this.buttonSortByColor.TabIndex = 11;
|
||||
this.buttonSortByColor.Text = "Сортировать по цвету";
|
||||
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.buttonSortByType);
|
||||
this.groupBoxTools.Controls.Add(this.buttonSortByColor);
|
||||
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemovePlain);
|
||||
@ -74,7 +98,7 @@
|
||||
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(233, 815);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(233, 909);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
@ -150,7 +174,7 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 473);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 540);
|
||||
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
@ -160,7 +184,7 @@
|
||||
//
|
||||
// buttonRemovePlain
|
||||
//
|
||||
this.buttonRemovePlain.Location = new System.Drawing.Point(19, 512);
|
||||
this.buttonRemovePlain.Location = new System.Drawing.Point(17, 579);
|
||||
this.buttonRemovePlain.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRemovePlain.Name = "buttonRemovePlain";
|
||||
this.buttonRemovePlain.Size = new System.Drawing.Size(200, 47);
|
||||
@ -171,7 +195,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(19, 583);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 650);
|
||||
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
|
||||
@ -185,7 +209,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(104, 748);
|
||||
this.buttonDown.Location = new System.Drawing.Point(104, 842);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(34, 40);
|
||||
@ -198,7 +222,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(145, 748);
|
||||
this.buttonRight.Location = new System.Drawing.Point(145, 842);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(34, 40);
|
||||
@ -211,7 +235,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(63, 748);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(63, 842);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
|
||||
@ -224,7 +248,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(104, 700);
|
||||
this.buttonUp.Location = new System.Drawing.Point(104, 794);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(34, 40);
|
||||
@ -234,7 +258,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 649);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 716);
|
||||
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
|
||||
@ -245,7 +269,7 @@
|
||||
//
|
||||
// buttonAddPlain
|
||||
//
|
||||
this.buttonAddPlain.Location = new System.Drawing.Point(19, 419);
|
||||
this.buttonAddPlain.Location = new System.Drawing.Point(17, 486);
|
||||
this.buttonAddPlain.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonAddPlain.Name = "buttonAddPlain";
|
||||
this.buttonAddPlain.Size = new System.Drawing.Size(200, 47);
|
||||
@ -260,7 +284,7 @@
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(927, 815);
|
||||
this.pictureBox.Size = new System.Drawing.Size(927, 909);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
@ -287,14 +311,14 @@
|
||||
// SaveToolStrip
|
||||
//
|
||||
this.SaveToolStrip.Name = "SaveToolStrip";
|
||||
this.SaveToolStrip.Size = new System.Drawing.Size(224, 26);
|
||||
this.SaveToolStrip.Size = new System.Drawing.Size(177, 26);
|
||||
this.SaveToolStrip.Text = "Сохранение";
|
||||
this.SaveToolStrip.Click += new System.EventHandler(this.SaveToolStrip_Click);
|
||||
//
|
||||
// loadToolStrip
|
||||
//
|
||||
this.loadToolStrip.Name = "loadToolStrip";
|
||||
this.loadToolStrip.Size = new System.Drawing.Size(224, 26);
|
||||
this.loadToolStrip.Size = new System.Drawing.Size(177, 26);
|
||||
this.loadToolStrip.Text = "Загрузка";
|
||||
this.loadToolStrip.Click += new System.EventHandler(this.loadToolStrip_Click);
|
||||
//
|
||||
@ -310,7 +334,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1160, 843);
|
||||
this.ClientSize = new System.Drawing.Size(1160, 937);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
@ -354,6 +378,8 @@
|
||||
private ToolStripMenuItem loadToolStrip;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByType;
|
||||
private Button buttonSortByColor;
|
||||
|
||||
}
|
||||
}
|
@ -275,6 +275,25 @@ namespace AirPlaneWithRadar
|
||||
|
||||
}
|
||||
}
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new PlaneCompareByType());
|
||||
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 PlaneCompareByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirPlaneWithRadar
|
||||
{
|
||||
internal interface IDrawingObject
|
||||
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||
{
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
|
@ -37,3 +37,61 @@
|
||||
2022-12-02 19:35:15.398 +03:00 [WRN] Неизвестная ошибка при удалении самолета на карту 1234 : Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
|
||||
2022-12-02 19:35:20.416 +03:00 [INF] С карты 1234 был удален самолет
|
||||
2022-12-02 19:35:24.176 +03:00 [WRN] Неизвестная ошибка при удалении самолета на карту 1234 : Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
|
||||
2022-12-02 20:58:51.450 +03:00 [INF] Переключение на карту 0
|
||||
2022-12-02 20:58:51.469 +03:00 [INF] Была проведена загрузка из файла C:\Users\Вова\Documents\test2.txt
|
||||
2022-12-02 20:58:52.939 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 20:58:53.435 +03:00 [INF] Переключение на карту 123
|
||||
2022-12-02 20:58:53.906 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 20:59:11.008 +03:00 [INF] На карту 2 добавлен новый самолет
|
||||
2022-12-02 20:59:17.699 +03:00 [INF] На карту 2 добавлен новый самолет
|
||||
2022-12-02 21:02:18.006 +03:00 [INF] Переключение на карту 1
|
||||
2022-12-02 21:02:18.017 +03:00 [INF] Добавлена карта: 1
|
||||
2022-12-02 21:02:23.228 +03:00 [INF] На карту 1 добавлен новый самолет
|
||||
2022-12-02 21:02:29.188 +03:00 [INF] На карту 1 добавлен новый самолет
|
||||
2022-12-02 21:02:41.779 +03:00 [INF] На карту 1 добавлен новый самолет
|
||||
2022-12-02 21:04:40.932 +03:00 [INF] Переключение на карту 12
|
||||
2022-12-02 21:04:40.942 +03:00 [INF] Добавлена карта: 12
|
||||
2022-12-02 21:04:47.181 +03:00 [INF] На карту 12 добавлен новый самолет
|
||||
2022-12-02 21:04:51.926 +03:00 [INF] На карту 12 добавлен новый самолет
|
||||
2022-12-02 21:06:03.473 +03:00 [INF] Переключение на карту 12
|
||||
2022-12-02 21:06:03.483 +03:00 [INF] Добавлена карта: 12
|
||||
2022-12-02 21:06:11.530 +03:00 [INF] На карту 12 добавлен новый самолет
|
||||
2022-12-02 21:08:09.171 +03:00 [INF] Переключение на карту 12
|
||||
2022-12-02 21:08:09.180 +03:00 [INF] Добавлена карта: 12
|
||||
2022-12-02 21:09:01.146 +03:00 [INF] На карту 12 добавлен новый самолет
|
||||
2022-12-02 21:10:09.720 +03:00 [INF] Переключение на карту 12
|
||||
2022-12-02 21:10:09.734 +03:00 [INF] Добавлена карта: 12
|
||||
2022-12-02 21:10:19.563 +03:00 [INF] На карту 12 добавлен новый самолет
|
||||
2022-12-02 21:10:27.721 +03:00 [INF] Добавление самолета на карту 12 прошло неудачно
|
||||
2022-12-02 21:10:36.916 +03:00 [INF] Переключение на карту 0
|
||||
2022-12-02 21:10:36.917 +03:00 [INF] Была проведена загрузка из файла C:\Users\Вова\Documents\test.txt
|
||||
2022-12-02 21:10:37.991 +03:00 [INF] Переключение на карту 123
|
||||
2022-12-02 21:10:38.462 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 21:10:54.307 +03:00 [INF] На карту 2 добавлен новый самолет
|
||||
2022-12-02 21:11:04.627 +03:00 [INF] На карту 2 добавлен новый самолет
|
||||
2022-12-02 21:11:11.001 +03:00 [INF] Добавление самолета на карту 2 прошло неудачно
|
||||
2022-12-02 21:11:30.530 +03:00 [INF] На карту 2 добавлен новый самолет
|
||||
2022-12-02 21:11:42.503 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 21:11:42.503 +03:00 [INF] Добавлена карта: 2
|
||||
2022-12-02 21:11:43.232 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 21:11:43.232 +03:00 [INF] Добавлена карта: 2
|
||||
2022-12-02 21:11:43.412 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 21:11:43.412 +03:00 [INF] Добавлена карта: 2
|
||||
2022-12-02 21:11:45.214 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 21:11:45.214 +03:00 [INF] Добавлена карта: 2
|
||||
2022-12-02 21:11:47.256 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 21:11:47.256 +03:00 [INF] Добавлена карта: 2
|
||||
2022-12-02 21:11:47.612 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 21:11:47.612 +03:00 [INF] Добавлена карта: 2
|
||||
2022-12-02 21:11:47.780 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 21:11:47.780 +03:00 [INF] Добавлена карта: 2
|
||||
2022-12-02 21:11:47.996 +03:00 [INF] Переключение на карту 2
|
||||
2022-12-02 21:11:47.996 +03:00 [INF] Добавлена карта: 2
|
||||
2022-12-02 21:22:56.692 +03:00 [INF] Переключение на карту 123
|
||||
2022-12-02 21:22:56.708 +03:00 [INF] Добавлена карта: 123
|
||||
2022-12-02 21:23:01.316 +03:00 [INF] На карту 123 добавлен новый самолет
|
||||
2022-12-02 21:23:05.600 +03:00 [INF] Добавление самолета на карту 123 прошло неудачно
|
||||
2022-12-02 21:23:09.917 +03:00 [INF] На карту 123 добавлен новый самолет
|
||||
2022-12-02 21:23:19.050 +03:00 [INF] На карту 123 добавлен новый самолет
|
||||
2022-12-02 21:23:30.002 +03:00 [INF] На карту 123 добавлен новый самолет
|
||||
2022-12-02 21:23:34.691 +03:00 [INF] На карту 123 добавлен новый самолет
|
||||
|
@ -8,7 +8,7 @@ namespace AirPlaneWithRadar
|
||||
{
|
||||
internal class MapWithSetPlainGeneric
|
||||
<T, U>
|
||||
where T : class, IDrawingObject
|
||||
where T : class, IDrawingObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
@ -121,7 +121,10 @@ namespace AirPlaneWithRadar
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setPlains.SortSet(comparer);
|
||||
}
|
||||
public void LoadData(string[] records)
|
||||
{
|
||||
foreach (var rec in records)
|
||||
|
52
AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs
Normal file
52
AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByColor.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirPlaneWithRadar
|
||||
{
|
||||
internal class PlaneCompareByColor : 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 xPlain = x as DrawingObjectPlane;
|
||||
var yPlain = y as DrawingObjectPlane;
|
||||
if (xPlain == null && yPlain == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xPlain == null && yPlain != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xPlain != null && yPlain == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int res = string.Compare(xPlain.GetPlane.Plain.BodyColor.Name, yPlain.GetPlane.Plain.BodyColor.Name);
|
||||
if (res != 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
var speedCompare = xPlain.GetPlane.Plain.Speed.CompareTo(yPlain.GetPlane.Plain.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xPlain.GetPlane.Plain.Weight.CompareTo(yPlain.GetPlane.Plain.Weight);
|
||||
}
|
||||
}
|
||||
}
|
55
AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByType.cs
Normal file
55
AirPlaneWithRadar/AirPlaneWithRadar/PlaneCompareByType.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirPlaneWithRadar
|
||||
{
|
||||
internal class PlaneCompareByType : 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 xPlain = x as DrawingObjectPlane;
|
||||
var yPlain = y as DrawingObjectPlane;
|
||||
if (xPlain == null && yPlain == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xPlain == null && yPlain != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xPlain != null && yPlain == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (!(xPlain.GetPlane.GetType().Name.Equals(yPlain.GetPlane.GetType().Name)))
|
||||
{
|
||||
if (xPlain.GetPlane.GetType().Name.Equals("DrawingPlain"))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var speedCompare = xPlain.GetPlane.Plain.Speed.CompareTo(yPlain.GetPlane.Plain.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xPlain.GetPlane.Plain.Weight.CompareTo(yPlain.GetPlane.Plain.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace AirPlaneWithRadar
|
||||
{
|
||||
internal class SetPlaneGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
|
||||
{
|
||||
private readonly List<T> _places;
|
||||
@ -20,12 +20,13 @@ namespace AirPlaneWithRadar
|
||||
}
|
||||
public int Insert(T plain)
|
||||
{
|
||||
|
||||
if (_places.Contains(plain)) { return -1; }
|
||||
Insert(plain, 0);
|
||||
return _places.Count;
|
||||
}
|
||||
public int Insert(T plain, int position)
|
||||
{
|
||||
|
||||
if (_places.Count == _maxCount)
|
||||
{
|
||||
throw new StorageOverFullException(_maxCount);
|
||||
@ -82,6 +83,12 @@ namespace AirPlaneWithRadar
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
return;
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user