Prytkina A.V. LabWork08 #9
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class AirplaneCompareByColor : 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 xAirplane = x as DrawingObjectAirplane;
|
||||
var yAirplane = y as DrawingObjectAirplane;
|
||||
if (xAirplane == null && yAirplane == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xAirplane == null && yAirplane != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xAirplane != null && yAirplane == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
string xAirplaneColor = xAirplane.GetAirplane.Airplane.BodyColor.Name;
|
||||
string yAirplaneColor = yAirplane.GetAirplane.Airplane.BodyColor.Name;
|
||||
if (xAirplaneColor != yAirplaneColor)
|
||||
{
|
||||
return xAirplaneColor.CompareTo(yAirplane);
|
||||
}
|
||||
if (xAirplane.GetAirplane.Airplane is EntityAirplaneWithRadar xAirpl && yAirplane.GetAirplane.Airplane is EntityAirplaneWithRadar yAirpl)
|
||||
{
|
||||
string xAirplaneDopColor = xAirpl.DopColor.Name;
|
||||
string yAirplaneDopColor = yAirpl.DopColor.Name;
|
||||
if (xAirplaneDopColor != yAirplaneDopColor)
|
||||
{
|
||||
return xAirplaneDopColor.CompareTo(yAirplaneDopColor);
|
||||
}
|
||||
}
|
||||
var speedCompare = xAirplane.GetAirplane.Airplane.Speed.CompareTo(yAirplane.GetAirplane.Airplane.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xAirplane.GetAirplane.Airplane.Weight.CompareTo(yAirplane.GetAirplane.Airplane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
55
AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs
Normal file
55
AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.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 AirplaneCompareByType : 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 xAirplane = x as DrawingObjectAirplane;
|
||||
var yAirplane = y as DrawingObjectAirplane;
|
||||
if (xAirplane == null && yAirplane == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xAirplane == null && yAirplane != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xAirplane != null && yAirplane == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (xAirplane.GetAirplane.GetType().Name != yAirplane.GetAirplane.GetType().Name)
|
||||
{
|
||||
if (xAirplane.GetAirplane.GetType().Name == "DrawingAirplane")
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
var speedCompare = xAirplane.GetAirplane.Airplane.Speed.CompareTo(yAirplane.GetAirplane.Airplane.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xAirplane.GetAirplane.Airplane.Weight.CompareTo(yAirplane.GetAirplane.Airplane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,8 @@ namespace AirplaneWithRadar
|
||||
_airplane = airplane;
|
||||
}
|
||||
public float Step => _airplane?.Airplane?.Step ?? 0;
|
||||
public DrawingAirplane GetAirplane => _airplane;
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _airplane?.GetCurrentPosition() ?? default;
|
||||
|
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox = new System.Windows.Forms.GroupBox();
|
||||
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||
this.buttonSortByType = new System.Windows.Forms.Button();
|
||||
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
@ -59,6 +61,8 @@
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
this.groupBox.Controls.Add(this.buttonSortByColor);
|
||||
this.groupBox.Controls.Add(this.buttonSortByType);
|
||||
this.groupBox.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBox.Controls.Add(this.buttonRight);
|
||||
this.groupBox.Controls.Add(this.buttonDown);
|
||||
@ -72,11 +76,31 @@
|
||||
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox.Location = new System.Drawing.Point(901, 33);
|
||||
this.groupBox.Name = "groupBox";
|
||||
this.groupBox.Size = new System.Drawing.Size(257, 750);
|
||||
this.groupBox.Size = new System.Drawing.Size(257, 859);
|
||||
this.groupBox.TabIndex = 0;
|
||||
this.groupBox.TabStop = false;
|
||||
this.groupBox.Text = "Инструменты";
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
this.buttonSortByColor.Location = new System.Drawing.Point(23, 424);
|
||||
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||
this.buttonSortByColor.Size = new System.Drawing.Size(222, 34);
|
||||
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(23, 384);
|
||||
this.buttonSortByType.Name = "buttonSortByType";
|
||||
this.buttonSortByType.Size = new System.Drawing.Size(222, 34);
|
||||
this.buttonSortByType.TabIndex = 12;
|
||||
this.buttonSortByType.Text = " Сортировка по типу ";
|
||||
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// groupBoxMaps
|
||||
//
|
||||
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
|
||||
@ -144,7 +168,7 @@
|
||||
//
|
||||
this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(153, 701);
|
||||
this.buttonRight.Location = new System.Drawing.Point(149, 792);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 10;
|
||||
@ -155,7 +179,7 @@
|
||||
//
|
||||
this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(117, 701);
|
||||
this.buttonDown.Location = new System.Drawing.Point(113, 792);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 9;
|
||||
@ -166,7 +190,7 @@
|
||||
//
|
||||
this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(81, 701);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(77, 792);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 8;
|
||||
@ -177,7 +201,7 @@
|
||||
//
|
||||
this.buttonUp.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(117, 665);
|
||||
this.buttonUp.Location = new System.Drawing.Point(113, 756);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 7;
|
||||
@ -186,7 +210,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(23, 603);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(23, 690);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(222, 34);
|
||||
this.buttonShowOnMap.TabIndex = 6;
|
||||
@ -196,7 +220,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(23, 549);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(23, 638);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(222, 37);
|
||||
this.buttonShowStorage.TabIndex = 5;
|
||||
@ -206,7 +230,7 @@
|
||||
//
|
||||
// buttonRemoveAirplane
|
||||
//
|
||||
this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 497);
|
||||
this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 588);
|
||||
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
|
||||
this.buttonRemoveAirplane.Size = new System.Drawing.Size(222, 34);
|
||||
this.buttonRemoveAirplane.TabIndex = 4;
|
||||
@ -216,7 +240,7 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 460);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 551);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(222, 31);
|
||||
@ -224,7 +248,7 @@
|
||||
//
|
||||
// buttonAddAirplane
|
||||
//
|
||||
this.buttonAddAirplane.Location = new System.Drawing.Point(23, 406);
|
||||
this.buttonAddAirplane.Location = new System.Drawing.Point(23, 496);
|
||||
this.buttonAddAirplane.Name = "buttonAddAirplane";
|
||||
this.buttonAddAirplane.Size = new System.Drawing.Size(222, 34);
|
||||
this.buttonAddAirplane.TabIndex = 2;
|
||||
@ -237,7 +261,7 @@
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 33);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(901, 750);
|
||||
this.pictureBox.Size = new System.Drawing.Size(901, 859);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
@ -286,7 +310,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1158, 783);
|
||||
this.ClientSize = new System.Drawing.Size(1158, 892);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
@ -330,5 +354,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -306,6 +306,35 @@ namespace AirplaneWithRadar
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AirplaneCompareByType());
|
||||
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)
|
||||
{
|
||||
// TODO прописать логику
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AirplaneCompareByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,6 +138,15 @@ namespace AirplaneWithRadar
|
||||
_setAirplanes.Insert(DrawingObjectAirplane.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setAirplanes.SortSet(comparer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
/// </summary>
|
||||
|
@ -141,5 +141,17 @@ namespace AirplaneWithRadar
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка набора объектов
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user