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 DrawingShip GetShip => _ship;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _ship?.GetCurrentPosition() ?? default;
@ -47,26 +49,49 @@ namespace Ship
{
return false;
}
var otherCar = other as DrawingObject;
if (otherCar == null)
var otherShip = other as DrawingObject;
if (otherShip == null)
{
return false;
}
var car = _ship.Ship;
var otherCarCar = otherCar._ship.Ship;
if (car.Speed != otherCarCar.Speed)
var ship = _ship.Ship;
var otherShipShip = otherShip._ship.Ship;
if (ship.GetType() != otherShipShip.GetType())
{
return false;
}
if (car.Weight != otherCarCar.Weight)
if (ship.Speed != otherShipShip.Speed)
{
return false;
}
if (car.BodyColor != otherCarCar.BodyColor)
if (ship.Weight != otherShipShip.Weight)
{
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;
}
}

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();
@ -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(767, 24);
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.TabStop = false;
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
//
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::Ship.Properties.Resources.arrowRight;
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.Size = new System.Drawing.Size(30, 30);
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.BackgroundImage = global::Ship.Properties.Resources.arrowDown;
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.Size = new System.Drawing.Size(30, 30);
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.BackgroundImage = global::Ship.Properties.Resources.arrowLeft;
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.Size = new System.Drawing.Size(30, 30);
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.BackgroundImage = global::Ship.Properties.Resources.arrowUp;
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.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 7;
@ -190,7 +214,7 @@
//
// 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.Size = new System.Drawing.Size(169, 37);
this.buttonShowOnMap.TabIndex = 5;
@ -200,7 +224,7 @@
//
// 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.Size = new System.Drawing.Size(169, 37);
this.buttonShowStorage.TabIndex = 4;
@ -210,7 +234,7 @@
//
// 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.Size = new System.Drawing.Size(169, 37);
this.buttonRemoveShip.TabIndex = 3;
@ -220,7 +244,7 @@
//
// 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.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(169, 23);
@ -228,7 +252,7 @@
//
// 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.Size = new System.Drawing.Size(169, 37);
this.buttonAddShip.TabIndex = 1;
@ -241,7 +265,7 @@
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 24);
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.TabStop = false;
//
@ -266,14 +290,14 @@
// 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.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// 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.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
@ -290,7 +314,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
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.groupBoxTools);
this.Controls.Add(this.menuStrip);
@ -335,5 +359,7 @@
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
}
}

View File

@ -32,10 +32,6 @@ namespace Ship
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetShipsGeneric<DrawingObject, AbstractMap> _mapShipsCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
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++;
}
}
/// <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);
}
}
}