Доработки 8-й лабораторной.

This commit is contained in:
Programmist73 2022-12-02 14:16:39 +04:00
parent 91c2c075f3
commit 535dbe7e44
6 changed files with 137 additions and 39 deletions

View File

@ -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,31 @@ 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);

View File

@ -80,7 +80,23 @@ namespace Airbus
return false;
}
//TODO доделать проверки на случай продвинутого объекта
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.ToArgb() != otherEntitySuperAirbus.AddColor.ToArgb())
{
return false;
}
}
return true;
}

View File

@ -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();
@ -51,8 +53,6 @@
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.OpenFileDialog();
this.buttonSortByType = new System.Windows.Forms.Button();
this.buttonSortByColor = new System.Windows.Forms.Button();
this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
@ -76,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, 863);
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);
@ -149,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, 798);
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;
@ -161,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, 798);
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;
@ -173,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, 798);
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;
@ -185,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, 747);
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;
@ -194,7 +214,7 @@
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(20, 687);
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;
@ -204,7 +224,7 @@
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(20, 634);
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;
@ -214,7 +234,7 @@
//
// buttonRemovePlane
//
this.buttonRemovePlane.Location = new System.Drawing.Point(20, 580);
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;
@ -224,7 +244,7 @@
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 547);
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);
@ -232,7 +252,7 @@
//
// buttonAddPlane
//
this.buttonAddPlane.Location = new System.Drawing.Point(20, 512);
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;
@ -245,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, 863);
this.pictureBox.Size = new System.Drawing.Size(843, 805);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
@ -291,31 +311,11 @@
//
this.saveFileDialog.Filter = "txt file | *.txt";
//
// buttonSortByType
//
this.buttonSortByType.Location = new System.Drawing.Point(20, 395);
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);
//
// buttonSortByColor
//
this.buttonSortByColor.Location = new System.Drawing.Point(20, 430);
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);
//
// FormMapWithSetPlanes
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1093, 891);
this.ClientSize = new System.Drawing.Size(1093, 833);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.menuStrip);

View File

@ -296,13 +296,25 @@ 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)
{
//TODO прописать логику
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new PlaneCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
}
}

View File

@ -10,7 +10,49 @@ namespace Airbus
{
public int Compare(IDrawningObject? x, IDrawningObject? y)
{
//TODO проверку
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 xEntity = xPlane.GetPlane.Airbus;
var yEntity = yPlane.GetPlane.Airbus;
var colorCompare = xEntity.CorpusColor.ToArgb().CompareTo(yEntity.CorpusColor.ToArgb());
if (colorCompare != 0 || xEntity is not EntitySuperAirbus xEntityAirbus || yEntity is not EntitySuperAirbus yEntityAirbus)
{
return colorCompare;
}
return xEntityAirbus.AddColor.ToArgb().CompareTo(yEntityAirbus.AddColor.ToArgb());
}
}
}

View File

@ -29,7 +29,10 @@ namespace Airbus
//добавление объекта в набор
public int Insert(T plane)
{
//TODO проверка на уникальность элемента в списке, делаем перед сообщением о переполнении
if (_places.Contains(plane))
{
throw new ArgumentException($"Объект {plane} уже есть в данном наборе");
}
if (Count == _maxCount)
{