Eliseev E.E. LabWork08 #9
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||
{
|
||||
private IDrawningObject _drawningObject = null;
|
||||
protected int[,] _map = null;
|
||||
@ -166,6 +166,30 @@ namespace Airbus
|
||||
return bmp;
|
||||
}
|
||||
|
||||
//сравнение
|
||||
public bool Equals(AbstractMap? other)
|
||||
{
|
||||
if (other == null || _map != other._map || _height != other._height || _width != other._width
|
||||
|| _size_x != other._size_x || _size_y != other._size_y || GetType() != other.GetType()
|
||||
|| _map.GetLength(0) != other._map.GetLength(0) || _map.GetLength(1) != other._map.GetLength(1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i = 0; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for(int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] != other._map[i, j])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
|
@ -17,6 +17,8 @@ namespace Airbus
|
||||
_airbus = airbus;
|
||||
}
|
||||
|
||||
public DrawningAirbus GetPlane => _airbus;
|
||||
|
||||
void IDrawningObject.DrawningObject(Graphics g)
|
||||
{
|
||||
_airbus.DrawTransport(g);
|
||||
@ -46,5 +48,62 @@ namespace Airbus
|
||||
|
||||
public static IDrawningObject Create(string data) => new DrawningObjectPlane(data.CreateDrawningPlane());
|
||||
|
||||
public bool Equals(IDrawningObject? other)
|
||||
{
|
||||
if(other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var otherPlane = other as DrawningObjectPlane;
|
||||
|
||||
if(otherPlane == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var plane = _airbus.Airbus;
|
||||
var otherPlanePlane = otherPlane._airbus.Airbus;
|
||||
|
||||
if(plane.Speed != otherPlanePlane.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(plane.Weight != otherPlanePlane.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plane.CorpusColor != otherPlanePlane.CorpusColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(plane.GetType().Name != otherPlanePlane.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plane is EntitySuperAirbus entitySuperAirbus && otherPlanePlane is EntitySuperAirbus otherEntitySuperAirbus)
|
||||
{
|
||||
if(entitySuperAirbus.AddEngine != otherEntitySuperAirbus.AddEngine)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(entitySuperAirbus.AddСompartment != otherEntitySuperAirbus.AddСompartment)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(entitySuperAirbus.AddColor.Name != otherEntitySuperAirbus.AddColor.Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
50
Airbus/Airbus/FormMapWithSetPlanes.Designer.cs
generated
50
Airbus/Airbus/FormMapWithSetPlanes.Designer.cs
generated
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBoxTools = 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 @@
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.buttonSortByColor);
|
||||
this.groupBoxTools.Controls.Add(this.buttonSortByType);
|
||||
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||
@ -72,11 +76,31 @@
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(843, 28);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(250, 769);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(250, 805);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
this.buttonSortByColor.Location = new System.Drawing.Point(20, 416);
|
||||
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||
this.buttonSortByColor.Size = new System.Drawing.Size(218, 29);
|
||||
this.buttonSortByColor.TabIndex = 12;
|
||||
this.buttonSortByColor.Text = "Сортировка по цвету";
|
||||
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
this.buttonSortByType.Location = new System.Drawing.Point(20, 381);
|
||||
this.buttonSortByType.Name = "buttonSortByType";
|
||||
this.buttonSortByType.Size = new System.Drawing.Size(218, 29);
|
||||
this.buttonSortByType.TabIndex = 11;
|
||||
this.buttonSortByType.Text = "Сортировка по типу";
|
||||
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// groupBoxMaps
|
||||
//
|
||||
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
|
||||
@ -145,7 +169,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.Right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(158, 704);
|
||||
this.buttonRight.Location = new System.Drawing.Point(158, 740);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(45, 45);
|
||||
this.buttonRight.TabIndex = 9;
|
||||
@ -157,7 +181,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.Down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(107, 704);
|
||||
this.buttonDown.Location = new System.Drawing.Point(107, 740);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(45, 45);
|
||||
this.buttonDown.TabIndex = 8;
|
||||
@ -169,7 +193,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.Left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(56, 704);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(56, 740);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(45, 45);
|
||||
this.buttonLeft.TabIndex = 7;
|
||||
@ -181,7 +205,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.Up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(107, 653);
|
||||
this.buttonUp.Location = new System.Drawing.Point(107, 689);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(45, 45);
|
||||
this.buttonUp.TabIndex = 6;
|
||||
@ -190,7 +214,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(20, 553);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(20, 642);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(218, 29);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
@ -200,7 +224,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(20, 500);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(20, 589);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(218, 29);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
@ -210,7 +234,7 @@
|
||||
//
|
||||
// buttonRemovePlane
|
||||
//
|
||||
this.buttonRemovePlane.Location = new System.Drawing.Point(20, 446);
|
||||
this.buttonRemovePlane.Location = new System.Drawing.Point(20, 535);
|
||||
this.buttonRemovePlane.Name = "buttonRemovePlane";
|
||||
this.buttonRemovePlane.Size = new System.Drawing.Size(218, 29);
|
||||
this.buttonRemovePlane.TabIndex = 3;
|
||||
@ -220,7 +244,7 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 413);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 502);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(218, 27);
|
||||
@ -228,7 +252,7 @@
|
||||
//
|
||||
// buttonAddPlane
|
||||
//
|
||||
this.buttonAddPlane.Location = new System.Drawing.Point(20, 378);
|
||||
this.buttonAddPlane.Location = new System.Drawing.Point(20, 467);
|
||||
this.buttonAddPlane.Name = "buttonAddPlane";
|
||||
this.buttonAddPlane.Size = new System.Drawing.Size(218, 29);
|
||||
this.buttonAddPlane.TabIndex = 1;
|
||||
@ -241,7 +265,7 @@
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(843, 769);
|
||||
this.pictureBox.Size = new System.Drawing.Size(843, 805);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
@ -291,7 +315,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1093, 797);
|
||||
this.ClientSize = new System.Drawing.Size(1093, 833);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
@ -335,5 +359,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private OpenFileDialog saveFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -292,5 +292,29 @@ namespace Airbus
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//сортировка по типу
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
//шаг перемещения объекта
|
||||
public float Step { get; }
|
||||
|
@ -10,7 +10,7 @@ namespace Airbus
|
||||
{
|
||||
//карта с набором объектов под неё
|
||||
internal class MapWithSetPlanesGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where T : class, IDrawningObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
//ширина окна отрисовки
|
||||
@ -108,6 +108,12 @@ namespace Airbus
|
||||
}
|
||||
}
|
||||
|
||||
//сортировка
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setPlanes.SortSet(comparer);
|
||||
}
|
||||
|
||||
//"взламываем" набор, чтобы все элементы оказались в начале
|
||||
private void Shaking()
|
||||
{
|
||||
|
75
Airbus/Airbus/PlaneCompareByColor.cs
Normal file
75
Airbus/Airbus/PlaneCompareByColor.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal class PlaneCompareByColor : 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 xPlane = x as DrawningObjectPlane;
|
||||
var yPlane = y as DrawningObjectPlane;
|
||||
|
||||
if (xPlane == null && yPlane == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (xPlane == null && yPlane != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (xPlane != null && yPlane == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var xEntityPlane = xPlane.GetPlane.Airbus;
|
||||
var yEntityPlane = yPlane.GetPlane.Airbus;
|
||||
var colorCompare = xEntityPlane.CorpusColor.ToArgb().CompareTo(yEntityPlane.CorpusColor.ToArgb());
|
||||
|
||||
if (colorCompare != 0)
|
||||
{
|
||||
return colorCompare;
|
||||
}
|
||||
|
||||
if (xEntityPlane is EntitySuperAirbus xAirbus && yEntityPlane is EntitySuperAirbus yAirbus)
|
||||
{
|
||||
var dopColorCompare = xAirbus.AddColor.ToArgb().CompareTo(yAirbus.AddColor.ToArgb());
|
||||
|
||||
if (dopColorCompare != 0)
|
||||
{
|
||||
return dopColorCompare;
|
||||
}
|
||||
}
|
||||
|
||||
var speedCompare = xPlane.GetPlane.Airbus.Speed.CompareTo(yPlane.GetPlane.Airbus.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return xPlane.GetPlane.Airbus.Weight.CompareTo(yPlane.GetPlane.Airbus.Weight);
|
||||
}
|
||||
}
|
||||
}
|
67
Airbus/Airbus/PlaneCompareByType.cs
Normal file
67
Airbus/Airbus/PlaneCompareByType.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal class PlaneCompareByType : 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 xPlane = x as DrawningObjectPlane;
|
||||
var yPlane = y as DrawningObjectPlane;
|
||||
|
||||
if(xPlane == null && yPlane == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(xPlane == null && yPlane != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(xPlane != null && yPlane == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(xPlane.GetPlane.GetType().Name != yPlane.GetPlane.GetType().Name)
|
||||
{
|
||||
if(xPlane.GetPlane.GetType().Name == "DrawningAirbus")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
var speedCompare = xPlane.GetPlane.Airbus.Speed.CompareTo(yPlane.GetPlane.Airbus.Speed);
|
||||
|
||||
if(speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return xPlane.GetPlane.Airbus.Weight.CompareTo(yPlane.GetPlane.Airbus.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
MapsCollection
|
||||
123|StarWarsMap|1000:750:Red;1000:750:DeepPink:Control:False:False;
|
||||
345|DesertStormMap|1000:750:White:Gray:True:True;1000:750:DeepPink:Yellow:False:True;1001:751:Red;1000:750:Red;1005:755:Lime;1010:760:Yellow;1000:750:Black:Yellow:True:False;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,7 +9,7 @@ using System.Threading.Tasks;
|
||||
namespace Airbus
|
||||
{
|
||||
internal class SetPlanesGeneric<T>
|
||||
where T: class
|
||||
where T: class, IEquatable<T>
|
||||
{
|
||||
//список объектов, которые храним
|
||||
private readonly List<T> _places;
|
||||
@ -42,16 +43,16 @@ namespace Airbus
|
||||
//добавление объекта в набор на конкретную позицию
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
if (position > _maxCount && position < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_places.Contains(plane))
|
||||
{
|
||||
throw new ArgumentException($"Объект {plane} уже есть в наборе");
|
||||
}
|
||||
|
||||
if (position > _maxCount && position < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
_places.Insert(position, plane);
|
||||
|
||||
return position;
|
||||
@ -112,5 +113,16 @@ namespace Airbus
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//сортировка набора объектов
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if(comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user