This commit is contained in:
the 2022-12-06 00:13:52 +04:00
parent 7a4942a0a5
commit 9b5dfadc81
7 changed files with 251 additions and 26 deletions

View File

@ -17,6 +17,8 @@ namespace Ship
public float Step => _ship?.Ship?.Step ?? 0; public float Step => _ship?.Ship?.Step ?? 0;
public DrawingShip GetShip => _ship;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{ {
return _ship?.GetCurrentPosition() ?? default; return _ship?.GetCurrentPosition() ?? default;
@ -47,26 +49,49 @@ namespace Ship
{ {
return false; return false;
} }
var otherCar = other as DrawingObject; var otherShip = other as DrawingObject;
if (otherCar == null) if (otherShip == null)
{ {
return false; return false;
} }
var car = _ship.Ship; var ship = _ship.Ship;
var otherCarCar = otherCar._ship.Ship; var otherShipShip = otherShip._ship.Ship;
if (car.Speed != otherCarCar.Speed) if (ship.GetType() != otherShipShip.GetType())
{ {
return false; return false;
} }
if (car.Weight != otherCarCar.Weight)
if (ship.Speed != otherShipShip.Speed)
{ {
return false; return false;
} }
if (car.BodyColor != otherCarCar.BodyColor) if (ship.Weight != otherShipShip.Weight)
{ {
return false; return false;
} }
// TODO доделать проверки в случае продвинутого объекта if (ship.BodyColor != otherShipShip.BodyColor)
{
return false;
}
if (ship is EntityMotorShip motor && otherShipShip is EntityMotorShip otherMotor)
{
if (motor.DopColor != otherMotor.DopColor)
{
return false;
}
if (motor.Pipes != otherMotor.Pipes)
{
return false;
}
if (motor.Fueltank != otherMotor.Fueltank)
{
return false;
}
}
return true; return true;
} }
} }

View File

@ -29,6 +29,8 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxTools = new System.Windows.Forms.GroupBox(); 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.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.buttonDeleteMap = new System.Windows.Forms.Button(); this.buttonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox(); this.listBoxMaps = new System.Windows.Forms.ListBox();
@ -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.buttonRight); this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonDown);
@ -72,11 +76,31 @@
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(767, 24); this.groupBoxTools.Location = new System.Drawing.Point(767, 24);
this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(200, 595); this.groupBoxTools.Size = new System.Drawing.Size(200, 713);
this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; this.groupBoxTools.Text = "Инструменты";
// //
// buttonSortByColor
//
this.buttonSortByColor.Location = new System.Drawing.Point(19, 361);
this.buttonSortByColor.Name = "buttonSortByColor";
this.buttonSortByColor.Size = new System.Drawing.Size(162, 38);
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(19, 317);
this.buttonSortByType.Name = "buttonSortByType";
this.buttonSortByType.Size = new System.Drawing.Size(162, 38);
this.buttonSortByType.TabIndex = 12;
this.buttonSortByType.Text = "Сортировать по типу";
this.buttonSortByType.UseVisualStyleBackColor = true;
this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click);
//
// groupBoxMaps // groupBoxMaps
// //
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); 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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Ship.Properties.Resources.arrowRight; this.buttonRight.BackgroundImage = global::Ship.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(124, 553); this.buttonRight.Location = new System.Drawing.Point(124, 671);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 10; this.buttonRight.TabIndex = 10;
@ -157,7 +181,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::Ship.Properties.Resources.arrowDown; this.buttonDown.BackgroundImage = global::Ship.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(88, 553); this.buttonDown.Location = new System.Drawing.Point(88, 671);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 9; this.buttonDown.TabIndex = 9;
@ -169,7 +193,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::Ship.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImage = global::Ship.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(52, 553); this.buttonLeft.Location = new System.Drawing.Point(52, 671);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 8; this.buttonLeft.TabIndex = 8;
@ -181,7 +205,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::Ship.Properties.Resources.arrowUp; this.buttonUp.BackgroundImage = global::Ship.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(88, 517); this.buttonUp.Location = new System.Drawing.Point(88, 635);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 7; this.buttonUp.TabIndex = 7;
@ -190,7 +214,7 @@
// //
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 498); this.buttonShowOnMap.Location = new System.Drawing.Point(19, 592);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(169, 37); this.buttonShowOnMap.Size = new System.Drawing.Size(169, 37);
this.buttonShowOnMap.TabIndex = 5; this.buttonShowOnMap.TabIndex = 5;
@ -200,7 +224,7 @@
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(19, 455); this.buttonShowStorage.Location = new System.Drawing.Point(19, 549);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(169, 37); this.buttonShowStorage.Size = new System.Drawing.Size(169, 37);
this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.TabIndex = 4;
@ -210,7 +234,7 @@
// //
// buttonRemoveShip // buttonRemoveShip
// //
this.buttonRemoveShip.Location = new System.Drawing.Point(19, 412); this.buttonRemoveShip.Location = new System.Drawing.Point(19, 506);
this.buttonRemoveShip.Name = "buttonRemoveShip"; this.buttonRemoveShip.Name = "buttonRemoveShip";
this.buttonRemoveShip.Size = new System.Drawing.Size(169, 37); this.buttonRemoveShip.Size = new System.Drawing.Size(169, 37);
this.buttonRemoveShip.TabIndex = 3; this.buttonRemoveShip.TabIndex = 3;
@ -220,7 +244,7 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 383); this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 477);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(169, 23); this.maskedTextBoxPosition.Size = new System.Drawing.Size(169, 23);
@ -228,7 +252,7 @@
// //
// buttonAddShip // buttonAddShip
// //
this.buttonAddShip.Location = new System.Drawing.Point(19, 340); this.buttonAddShip.Location = new System.Drawing.Point(19, 434);
this.buttonAddShip.Name = "buttonAddShip"; this.buttonAddShip.Name = "buttonAddShip";
this.buttonAddShip.Size = new System.Drawing.Size(169, 37); this.buttonAddShip.Size = new System.Drawing.Size(169, 37);
this.buttonAddShip.TabIndex = 1; this.buttonAddShip.TabIndex = 1;
@ -241,7 +265,7 @@
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 24); this.pictureBox.Location = new System.Drawing.Point(0, 24);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(767, 595); this.pictureBox.Size = new System.Drawing.Size(767, 713);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -266,14 +290,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);
// //
@ -290,7 +314,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(967, 619); this.ClientSize = new System.Drawing.Size(967, 737);
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);
@ -335,5 +359,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

@ -32,10 +32,6 @@ namespace Ship
/// </summary> /// </summary>
private readonly ILogger _logger; private readonly ILogger _logger;
/// <summary> /// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetShipsGeneric<DrawingObject, AbstractMap> _mapShipsCollectionGeneric;
/// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public FormMapWithSetShips(ILogger<FormMapWithSetShips> logger) public FormMapWithSetShips(ILogger<FormMapWithSetShips> logger)
@ -317,5 +313,27 @@ namespace Ship
{ {
} }
private void buttonSortByType_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ??
string.Empty].Sort(new ShipCompareByType());
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 ShipCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
} }
} }

View File

@ -207,5 +207,14 @@ namespace Ship
i++; i++;
} }
} }
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer"></param>
public void Sort(IComparer<T> comparer)
{
_setShips.SortSet(comparer);
}
} }
} }

View File

@ -123,5 +123,18 @@ namespace Ship
} }
} }
} }
/// <summary>
/// Сортировка набора объектов
/// </summary>
/// <param name="comparer"></param>
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
} }
} }

View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ship
{
internal class ShipCompareByColor : 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 xShip = x as DrawingObject;
var yShip = y as DrawingObject;
if (xShip == null && yShip == null)
{
return 0;
}
if (xShip == null && yShip != null)
{
return 1;
}
if (xShip != null && yShip == null)
{
return -1;
}
if (xShip.GetShip.Ship.BodyColor.R.CompareTo(yShip.GetShip.Ship.BodyColor.R) != 0)
{
return xShip.GetShip.Ship.BodyColor.R.CompareTo(yShip.GetShip.Ship.BodyColor.R);
}
if (xShip.GetShip.Ship.BodyColor.G.CompareTo(yShip.GetShip.Ship.BodyColor.G) != 0)
{
return xShip.GetShip.Ship.BodyColor.G.CompareTo(yShip.GetShip.Ship.BodyColor.G);
}
if (xShip.GetShip.Ship.BodyColor.B.CompareTo(yShip.GetShip.Ship.BodyColor.B) != 0)
{
return xShip.GetShip.Ship.BodyColor.B.CompareTo(yShip.GetShip.Ship.BodyColor.B);
}
if (xShip.GetShip.Ship is EntityMotorShip xMotorEntity && yShip.GetShip.Ship is EntityMotorShip yMotorEntity)
{
if (xMotorEntity.DopColor.R.CompareTo(yMotorEntity.DopColor.R) != 0)
{
return xMotorEntity.DopColor.R.CompareTo(yMotorEntity.DopColor.R);
}
if (xMotorEntity.DopColor.G.CompareTo(yMotorEntity.DopColor.G) != 0)
{
return xMotorEntity.DopColor.G.CompareTo(yMotorEntity.DopColor.G);
}
if (xMotorEntity.DopColor.B.CompareTo(yMotorEntity.DopColor.B) != 0)
{
return xMotorEntity.DopColor.B.CompareTo(yMotorEntity.DopColor.B);
}
}
var speedCompare = xShip.GetShip.Ship.Speed.CompareTo(yShip.GetShip.Ship.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xShip.GetShip.Ship.Weight.CompareTo(yShip.GetShip.Ship.Weight);
}
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ship
{
internal class ShipCompareByType : 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 xShip = x as DrawingObject;
var yShip = y as DrawingObject;
if (xShip == null && yShip == null)
{
return 0;
}
if (xShip == null && yShip != null)
{
return 1;
}
if (xShip != null && yShip == null)
{
return -1;
}
if (xShip.GetShip.GetType().Name != yShip.GetShip.GetType().Name)
{
if (xShip.GetShip.GetType().Name == "DrawingShip")
{
return -1;
}
return 1;
}
var speedCompare = xShip.GetShip.Ship.Speed.CompareTo(yShip.GetShip.Ship.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xShip.GetShip.Ship.Weight.CompareTo(yShip.GetShip.Ship.Weight);
}
}
}