lab 8 out todo

This commit is contained in:
NikGapon 2022-12-05 18:47:34 +04:00
parent f2fc4ab53b
commit b23f4d39e4
8 changed files with 163 additions and 6 deletions

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Airbus
{
internal class AirplaneCompareByColor : IComparer<IDrawningObject>
{
public int Compare(IDrawningObject? x, IDrawningObject? y)
{
// TODO реализовать логику сравнения
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Airbus
{
internal class AirplaneCompareByType : 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 xAirplane = x as DrawningObjectAirplane;
var yAirplane = y as DrawningObjectAirplane;
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);
}
}
}

View File

@ -14,6 +14,7 @@ namespace Airbus
{ {
_airplane = airplane; _airplane = airplane;
} }
public DrawningAirplane GetAirplane => _airplane;
public float Step => _airplane?.airplane?.Step ?? 0; public float Step => _airplane?.airplane?.Step ?? 0;
public void DrawningObject(Graphics g) public void DrawningObject(Graphics g)
{ {
@ -27,7 +28,7 @@ namespace Airbus
{ {
_airplane?.MoveTransport(direction); _airplane?.MoveTransport(direction);
} }
public void SetObject(int x, int y, int width, int height) public void SetObject(int x, int y, int width, int height)
{ {
_airplane?.SetPosition(x, y, width, height); _airplane?.SetPosition(x, y, width, height);
} }
@ -35,5 +36,33 @@ namespace Airbus
public string GetInfo() => _airplane?.GetDataForSave(); public string GetInfo() => _airplane?.GetDataForSave();
public static IDrawningObject Create(string data) => new DrawningObjectAirplane(data.CreateDrawningAirplane()); public static IDrawningObject Create(string data) => new DrawningObjectAirplane(data.CreateDrawningAirplane());
public bool Equals(IDrawningObject? other)
{
if (other == null)
{
return false;
}
var otherAirplane = other as DrawningObjectAirplane;
if (otherAirplane == null)
{
return false;
}
var airplane = _airplane.airplane;
var otherAirplaneAirplane = otherAirplane._airplane.airplane;
if (airplane.Speed != otherAirplaneAirplane.Speed)
{
return false;
}
if (airplane.Weight != otherAirplaneAirplane.Weight)
{
return false;
}
if (airplane.BodyColor != otherAirplaneAirplane.BodyColor)
{
return false;
}
// TODO доделать проверки в случае продвинутого объекта
return true;
}
} }
} }

View File

@ -51,6 +51,8 @@
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.buttonSortByType = new System.Windows.Forms.Button();
this.buttonSortByColor = new System.Windows.Forms.Button();
this.groupBoxTools.SuspendLayout(); this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout(); this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
@ -59,6 +61,8 @@
// //
// groupBoxTools // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.buttonSortByColor);
this.groupBoxTools.Controls.Add(this.buttonSortByType);
this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Controls.Add(this.buttonRight); this.groupBoxTools.Controls.Add(this.buttonRight);
@ -267,14 +271,14 @@
// SaveToolStripMenuItem // SaveToolStripMenuItem
// //
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.SaveToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
this.SaveToolStripMenuItem.Text = "Сохранение"; this.SaveToolStripMenuItem.Text = "Сохранение";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
// //
// LoadToolStripMenuItem // LoadToolStripMenuItem
// //
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.LoadToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
this.LoadToolStripMenuItem.Text = "Загрузка"; this.LoadToolStripMenuItem.Text = "Загрузка";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
// //
@ -286,6 +290,26 @@
// //
this.saveFileDialog.Filter = "txt file | *.txt"; this.saveFileDialog.Filter = "txt file | *.txt";
// //
// buttonSortByType
//
this.buttonSortByType.Location = new System.Drawing.Point(12, 326);
this.buttonSortByType.Name = "buttonSortByType";
this.buttonSortByType.Size = new System.Drawing.Size(83, 38);
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(101, 326);
this.buttonSortByColor.Name = "buttonSortByColor";
this.buttonSortByColor.Size = new System.Drawing.Size(93, 38);
this.buttonSortByColor.TabIndex = 12;
this.buttonSortByColor.Text = "Сортировать по цвету";
this.buttonSortByColor.UseVisualStyleBackColor = true;
this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click);
//
// FormMapWithSetAirplane // FormMapWithSetAirplane
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -334,5 +358,7 @@
private ToolStripMenuItem LoadToolStripMenuItem; private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog; private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog; private SaveFileDialog saveFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
} }
} }

View File

@ -296,5 +296,22 @@ namespace Airbus
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
} }
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();
}
private void buttonSortByColor_Click(object sender, EventArgs e)
{
}
} }
} }

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Airbus namespace Airbus
{ {
internal interface IDrawningObject internal interface IDrawningObject : IEquatable<IDrawningObject>
{ {
public float Step { get; } public float Step { get; }
void SetObject(int x, int y, int width, int height); void SetObject(int x, int y, int width, int height);

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Airbus namespace Airbus
{ {
internal class MapWithSetAirplaneGeneric<T, U> internal class MapWithSetAirplaneGeneric<T, U>
where T : class, IDrawningObject where T : class, IDrawningObject, IEquatable<T>
where U : AbstractMap where U : AbstractMap
{ {
/// <summary> /// <summary>
@ -201,5 +201,9 @@ namespace Airbus
_setAirplane.Insert(DrawningObjectAirplane.Create(rec) as T); _setAirplane.Insert(DrawningObjectAirplane.Create(rec) as T);
} }
} }
public void Sort(IComparer<T> comparer)
{
_setAirplane.SortSet(comparer);
}
} }
} }

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Airbus namespace Airbus
{ {
internal class SetAirplaneGeneric<T> internal class SetAirplaneGeneric<T>
where T : class where T : class, IEquatable<T>
{ {
private readonly List<T> _places; private readonly List<T> _places;
public int Count => _places.Count; public int Count => _places.Count;
@ -80,6 +80,14 @@ namespace Airbus
} }
} }
} }
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
} }
} }