Сортировка

This commit is contained in:
Володя 2022-12-02 20:50:53 +03:00
parent a145a52010
commit 71fb1ccbde
7 changed files with 136 additions and 16 deletions

View File

@ -34,7 +34,7 @@ namespace AirPlaneWithRadar
{ {
_plain?.MoveTransport(direction); _plain?.MoveTransport(direction);
} }
public DrawingPlain GetPlane => _plain;
public void SetObject(int x, int y, int width, int height) public void SetObject(int x, int y, int width, int height)
{ {
_plain.setPosition(x, y, width, height); _plain.setPosition(x, y, width, height);

View File

@ -28,6 +28,8 @@
/// </summary> /// </summary>
private void InitializeComponent() 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.groupBoxTools = new System.Windows.Forms.GroupBox();
this.groupBoxMaps = new System.Windows.Forms.GroupBox(); this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.buttonAddMap = new System.Windows.Forms.Button(); this.buttonAddMap = new System.Windows.Forms.Button();
@ -57,8 +59,30 @@
this.menuStrip.SuspendLayout(); this.menuStrip.SuspendLayout();
this.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 // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.buttonSortByType);
this.groupBoxTools.Controls.Add(this.buttonSortByColor);
this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRemovePlain); this.groupBoxTools.Controls.Add(this.buttonRemovePlain);
@ -74,7 +98,7 @@
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); 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.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; this.groupBoxTools.Text = "Инструменты";
@ -150,7 +174,7 @@
// //
// maskedTextBoxPosition // 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
@ -160,7 +184,7 @@
// //
// buttonRemovePlain // 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemovePlain.Name = "buttonRemovePlain"; this.buttonRemovePlain.Name = "buttonRemovePlain";
this.buttonRemovePlain.Size = new System.Drawing.Size(200, 47); this.buttonRemovePlain.Size = new System.Drawing.Size(200, 47);
@ -171,7 +195,7 @@
// //
// buttonShowStorage // 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(200, 47); 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.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.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(34, 40); 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.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.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(34, 40); 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.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.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(34, 40); 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.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.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(34, 40); this.buttonUp.Size = new System.Drawing.Size(34, 40);
@ -234,7 +258,7 @@
// //
// buttonShowOnMap // 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47); this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
@ -245,7 +269,7 @@
// //
// buttonAddPlain // 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddPlain.Name = "buttonAddPlain"; this.buttonAddPlain.Name = "buttonAddPlain";
this.buttonAddPlain.Size = new System.Drawing.Size(200, 47); this.buttonAddPlain.Size = new System.Drawing.Size(200, 47);
@ -260,7 +284,7 @@
this.pictureBox.Location = new System.Drawing.Point(0, 28); this.pictureBox.Location = new System.Drawing.Point(0, 28);
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBox.Name = "pictureBox"; 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.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -287,14 +311,14 @@
// SaveToolStrip // SaveToolStrip
// //
this.SaveToolStrip.Name = "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.Text = "Сохранение";
this.SaveToolStrip.Click += new System.EventHandler(this.SaveToolStrip_Click); this.SaveToolStrip.Click += new System.EventHandler(this.SaveToolStrip_Click);
// //
// loadToolStrip // loadToolStrip
// //
this.loadToolStrip.Name = "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.Text = "Загрузка";
this.loadToolStrip.Click += new System.EventHandler(this.loadToolStrip_Click); this.loadToolStrip.Click += new System.EventHandler(this.loadToolStrip_Click);
// //
@ -310,7 +334,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.menuStrip); this.Controls.Add(this.menuStrip);
@ -354,6 +378,8 @@
private ToolStripMenuItem loadToolStrip; private ToolStripMenuItem loadToolStrip;
private OpenFileDialog openFileDialog; private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog; private SaveFileDialog saveFileDialog;
private Button buttonSortByType;
private Button buttonSortByColor;
} }
} }

View File

@ -275,6 +275,20 @@ 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)
{
}
} }
} }

View File

@ -121,7 +121,10 @@ namespace AirPlaneWithRadar
} }
return data; return data;
} }
public void Sort(IComparer<T> comparer)
{
_setPlains.SortSet(comparer);
}
public void LoadData(string[] records) public void LoadData(string[] records)
{ {
foreach (var rec in records) foreach (var rec in records)

View File

@ -0,0 +1,16 @@
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)
{
throw new NotImplementedException();
}
}
}

View 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);
}
}
}

View File

@ -83,6 +83,12 @@ namespace AirPlaneWithRadar
yield break; yield break;
} }
} }
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
return;
_places.Sort(comparer);
}
} }
} }