Лабораторная работа 8
This commit is contained in:
parent
d7880d438d
commit
a0f252b9e9
@ -10,6 +10,8 @@ namespace Monorail
|
|||||||
{
|
{
|
||||||
private DrawingLocomotive _locomotive = null;
|
private DrawingLocomotive _locomotive = null;
|
||||||
|
|
||||||
|
public DrawingLocomotive GetLocomotive => _locomotive;
|
||||||
|
|
||||||
public DrawingObjectLocomotive(DrawingLocomotive locomotive)
|
public DrawingObjectLocomotive(DrawingLocomotive locomotive)
|
||||||
{
|
{
|
||||||
_locomotive = locomotive;
|
_locomotive = locomotive;
|
||||||
@ -36,6 +38,34 @@ namespace Monorail
|
|||||||
{
|
{
|
||||||
_locomotive.DrawTransport(g);
|
_locomotive.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool Equals(IDrawingObject? other)
|
||||||
|
{
|
||||||
|
if (other is not DrawingObjectLocomotive otherLocomotive)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var entity = _locomotive.Locomotive;
|
||||||
|
var otherEntity = otherLocomotive._locomotive.Locomotive;
|
||||||
|
if (entity.GetType() != otherEntity.GetType() ||
|
||||||
|
entity.Speed != otherEntity.Speed ||
|
||||||
|
entity.Weight != otherEntity.Weight ||
|
||||||
|
entity.BodyColor != otherEntity.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (entity is EntityMonorailLocomotive entityMonorailLocomotive &&
|
||||||
|
otherEntity is EntityMonorailLocomotive otherEntityMonorailLocomotive && (
|
||||||
|
entityMonorailLocomotive.Monorail != otherEntityMonorailLocomotive.Monorail ||
|
||||||
|
entityMonorailLocomotive.DopColor != otherEntityMonorailLocomotive.DopColor ||
|
||||||
|
entityMonorailLocomotive.DopCabin != otherEntityMonorailLocomotive.DopCabin))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public string GetInfo() => _locomotive?.GetDataForSave();
|
public string GetInfo() => _locomotive?.GetDataForSave();
|
||||||
public static IDrawingObject Create(string data) => new DrawingObjectLocomotive(data.CreateDrawingLocomotive());
|
public static IDrawingObject Create(string data) => new DrawingObjectLocomotive(data.CreateDrawingLocomotive());
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@
|
|||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
groupBoxTools = new GroupBox();
|
groupBoxTools = new GroupBox();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
|
buttonSortByType = new Button();
|
||||||
groupBoxMaps = new GroupBox();
|
groupBoxMaps = new GroupBox();
|
||||||
textBoxNewMapName = new TextBox();
|
textBoxNewMapName = new TextBox();
|
||||||
buttonDeleteMap = new Button();
|
buttonDeleteMap = new Button();
|
||||||
@ -62,7 +64,7 @@
|
|||||||
pictureBoxLocomotive.Dock = DockStyle.Left;
|
pictureBoxLocomotive.Dock = DockStyle.Left;
|
||||||
pictureBoxLocomotive.Location = new Point(0, 24);
|
pictureBoxLocomotive.Location = new Point(0, 24);
|
||||||
pictureBoxLocomotive.Name = "pictureBoxLocomotive";
|
pictureBoxLocomotive.Name = "pictureBoxLocomotive";
|
||||||
pictureBoxLocomotive.Size = new Size(579, 537);
|
pictureBoxLocomotive.Size = new Size(579, 623);
|
||||||
pictureBoxLocomotive.TabIndex = 0;
|
pictureBoxLocomotive.TabIndex = 0;
|
||||||
pictureBoxLocomotive.TabStop = false;
|
pictureBoxLocomotive.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -78,7 +80,7 @@
|
|||||||
//
|
//
|
||||||
// buttonAddCar
|
// buttonAddCar
|
||||||
//
|
//
|
||||||
buttonAddCar.Location = new Point(23, 288);
|
buttonAddCar.Location = new Point(23, 358);
|
||||||
buttonAddCar.Name = "buttonAddCar";
|
buttonAddCar.Name = "buttonAddCar";
|
||||||
buttonAddCar.Size = new Size(169, 30);
|
buttonAddCar.Size = new Size(169, 30);
|
||||||
buttonAddCar.TabIndex = 3;
|
buttonAddCar.TabIndex = 3;
|
||||||
@ -88,7 +90,7 @@
|
|||||||
//
|
//
|
||||||
// buttonRemoveCar
|
// buttonRemoveCar
|
||||||
//
|
//
|
||||||
buttonRemoveCar.Location = new Point(23, 353);
|
buttonRemoveCar.Location = new Point(23, 421);
|
||||||
buttonRemoveCar.Name = "buttonRemoveCar";
|
buttonRemoveCar.Name = "buttonRemoveCar";
|
||||||
buttonRemoveCar.Size = new Size(169, 30);
|
buttonRemoveCar.Size = new Size(169, 30);
|
||||||
buttonRemoveCar.TabIndex = 4;
|
buttonRemoveCar.TabIndex = 4;
|
||||||
@ -98,7 +100,7 @@
|
|||||||
//
|
//
|
||||||
// buttonShowStorage
|
// buttonShowStorage
|
||||||
//
|
//
|
||||||
buttonShowStorage.Location = new Point(25, 406);
|
buttonShowStorage.Location = new Point(25, 470);
|
||||||
buttonShowStorage.Name = "buttonShowStorage";
|
buttonShowStorage.Name = "buttonShowStorage";
|
||||||
buttonShowStorage.Size = new Size(169, 30);
|
buttonShowStorage.Size = new Size(169, 30);
|
||||||
buttonShowStorage.TabIndex = 5;
|
buttonShowStorage.TabIndex = 5;
|
||||||
@ -108,7 +110,7 @@
|
|||||||
//
|
//
|
||||||
// buttonShowOnMap
|
// buttonShowOnMap
|
||||||
//
|
//
|
||||||
buttonShowOnMap.Location = new Point(25, 443);
|
buttonShowOnMap.Location = new Point(25, 505);
|
||||||
buttonShowOnMap.Name = "buttonShowOnMap";
|
buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
buttonShowOnMap.Size = new Size(169, 30);
|
buttonShowOnMap.Size = new Size(169, 30);
|
||||||
buttonShowOnMap.TabIndex = 6;
|
buttonShowOnMap.TabIndex = 6;
|
||||||
@ -118,7 +120,7 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
maskedTextBoxPosition.Location = new Point(24, 324);
|
maskedTextBoxPosition.Location = new Point(24, 393);
|
||||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
maskedTextBoxPosition.Size = new Size(169, 23);
|
maskedTextBoxPosition.Size = new Size(169, 23);
|
||||||
maskedTextBoxPosition.TabIndex = 7;
|
maskedTextBoxPosition.TabIndex = 7;
|
||||||
@ -127,7 +129,7 @@
|
|||||||
//
|
//
|
||||||
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonUp.Location = new Point(96, 483);
|
buttonUp.Location = new Point(96, 547);
|
||||||
buttonUp.Name = "buttonUp";
|
buttonUp.Name = "buttonUp";
|
||||||
buttonUp.Size = new Size(30, 30);
|
buttonUp.Size = new Size(30, 30);
|
||||||
buttonUp.TabIndex = 8;
|
buttonUp.TabIndex = 8;
|
||||||
@ -138,7 +140,7 @@
|
|||||||
//
|
//
|
||||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonLeft.Location = new Point(60, 519);
|
buttonLeft.Location = new Point(60, 583);
|
||||||
buttonLeft.Name = "buttonLeft";
|
buttonLeft.Name = "buttonLeft";
|
||||||
buttonLeft.Size = new Size(30, 30);
|
buttonLeft.Size = new Size(30, 30);
|
||||||
buttonLeft.TabIndex = 9;
|
buttonLeft.TabIndex = 9;
|
||||||
@ -149,7 +151,7 @@
|
|||||||
//
|
//
|
||||||
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonDown.Location = new Point(96, 519);
|
buttonDown.Location = new Point(96, 583);
|
||||||
buttonDown.Name = "buttonDown";
|
buttonDown.Name = "buttonDown";
|
||||||
buttonDown.Size = new Size(30, 30);
|
buttonDown.Size = new Size(30, 30);
|
||||||
buttonDown.TabIndex = 10;
|
buttonDown.TabIndex = 10;
|
||||||
@ -160,7 +162,7 @@
|
|||||||
//
|
//
|
||||||
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonRight.Location = new Point(132, 519);
|
buttonRight.Location = new Point(132, 583);
|
||||||
buttonRight.Name = "buttonRight";
|
buttonRight.Name = "buttonRight";
|
||||||
buttonRight.Size = new Size(30, 30);
|
buttonRight.Size = new Size(30, 30);
|
||||||
buttonRight.TabIndex = 11;
|
buttonRight.TabIndex = 11;
|
||||||
@ -170,6 +172,8 @@
|
|||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
//
|
//
|
||||||
groupBoxTools.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
groupBoxTools.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
groupBoxTools.Controls.Add(buttonSortByColor);
|
||||||
|
groupBoxTools.Controls.Add(buttonSortByType);
|
||||||
groupBoxTools.Controls.Add(groupBoxMaps);
|
groupBoxTools.Controls.Add(groupBoxMaps);
|
||||||
groupBoxTools.Controls.Add(buttonRight);
|
groupBoxTools.Controls.Add(buttonRight);
|
||||||
groupBoxTools.Controls.Add(buttonDown);
|
groupBoxTools.Controls.Add(buttonDown);
|
||||||
@ -180,13 +184,33 @@
|
|||||||
groupBoxTools.Controls.Add(buttonShowStorage);
|
groupBoxTools.Controls.Add(buttonShowStorage);
|
||||||
groupBoxTools.Controls.Add(buttonRemoveCar);
|
groupBoxTools.Controls.Add(buttonRemoveCar);
|
||||||
groupBoxTools.Controls.Add(buttonAddCar);
|
groupBoxTools.Controls.Add(buttonAddCar);
|
||||||
groupBoxTools.Location = new Point(585, 0);
|
groupBoxTools.Location = new Point(585, 24);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(212, 560);
|
groupBoxTools.Size = new Size(212, 623);
|
||||||
groupBoxTools.TabIndex = 12;
|
groupBoxTools.TabIndex = 12;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
groupBoxTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Location = new Point(25, 311);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(169, 30);
|
||||||
|
buttonSortByColor.TabIndex = 18;
|
||||||
|
buttonSortByColor.Text = "Сортировать по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += ButtonSortByColor_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Location = new Point(24, 277);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(169, 30);
|
||||||
|
buttonSortByType.TabIndex = 17;
|
||||||
|
buttonSortByType.Text = "Сортировать по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += ButtonSortByType_Click;
|
||||||
|
//
|
||||||
// groupBoxMaps
|
// groupBoxMaps
|
||||||
//
|
//
|
||||||
groupBoxMaps.Controls.Add(textBoxNewMapName);
|
groupBoxMaps.Controls.Add(textBoxNewMapName);
|
||||||
@ -194,7 +218,7 @@
|
|||||||
groupBoxMaps.Controls.Add(buttonAddMap);
|
groupBoxMaps.Controls.Add(buttonAddMap);
|
||||||
groupBoxMaps.Controls.Add(listBoxMaps);
|
groupBoxMaps.Controls.Add(listBoxMaps);
|
||||||
groupBoxMaps.Controls.Add(comboBoxSelectorMap);
|
groupBoxMaps.Controls.Add(comboBoxSelectorMap);
|
||||||
groupBoxMaps.Location = new Point(8, 21);
|
groupBoxMaps.Location = new Point(9, 22);
|
||||||
groupBoxMaps.Name = "groupBoxMaps";
|
groupBoxMaps.Name = "groupBoxMaps";
|
||||||
groupBoxMaps.Size = new Size(197, 249);
|
groupBoxMaps.Size = new Size(197, 249);
|
||||||
groupBoxMaps.TabIndex = 16;
|
groupBoxMaps.TabIndex = 16;
|
||||||
@ -257,14 +281,14 @@
|
|||||||
// SaveToolStripMenuItem
|
// SaveToolStripMenuItem
|
||||||
//
|
//
|
||||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
SaveToolStripMenuItem.Size = new Size(180, 22);
|
SaveToolStripMenuItem.Size = new Size(141, 22);
|
||||||
SaveToolStripMenuItem.Text = "Сохранение";
|
SaveToolStripMenuItem.Text = "Сохранение";
|
||||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// LoadToolStripMenuItem
|
// LoadToolStripMenuItem
|
||||||
//
|
//
|
||||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
LoadToolStripMenuItem.Size = new Size(180, 22);
|
LoadToolStripMenuItem.Size = new Size(141, 22);
|
||||||
LoadToolStripMenuItem.Text = "Загрузка";
|
LoadToolStripMenuItem.Text = "Загрузка";
|
||||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
@ -280,7 +304,7 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 561);
|
ClientSize = new Size(800, 647);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Controls.Add(pictureBoxLocomotive);
|
Controls.Add(pictureBoxLocomotive);
|
||||||
Controls.Add(menuStrip);
|
Controls.Add(menuStrip);
|
||||||
@ -323,5 +347,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ namespace Monorail
|
|||||||
{
|
{
|
||||||
public partial class FormMapWithSetLocomotive : Form
|
public partial class FormMapWithSetLocomotive : Form
|
||||||
{
|
{
|
||||||
private MapWithSetLocomotiveGeneric<DrawingObjectLocomotive, AbstractMap> _mapLocomotiveCollectionGeneric;
|
|
||||||
private readonly Dictionary<string, AbstractMap> _mapDict = new()
|
private readonly Dictionary<string, AbstractMap> _mapDict = new()
|
||||||
{
|
{
|
||||||
{"Простая карта", new SimpleMap() },
|
{"Простая карта", new SimpleMap() },
|
||||||
@ -53,32 +53,6 @@ namespace Monorail
|
|||||||
listBoxMaps.SelectedIndex = index;
|
listBoxMaps.SelectedIndex = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender,
|
|
||||||
EventArgs e)
|
|
||||||
{
|
|
||||||
AbstractMap map = null;
|
|
||||||
switch (comboBoxSelectorMap.Text)
|
|
||||||
{
|
|
||||||
case "Простая карта":
|
|
||||||
map = new SimpleMap();
|
|
||||||
break;
|
|
||||||
case "Карта с грязью":
|
|
||||||
map = new FieldMap();
|
|
||||||
break;
|
|
||||||
case "Карта с кустами":
|
|
||||||
map = new BushesMap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (map != null)
|
|
||||||
{
|
|
||||||
_mapLocomotiveCollectionGeneric = new MapWithSetLocomotiveGeneric<DrawingObjectLocomotive, AbstractMap>(
|
|
||||||
pictureBoxLocomotive.Width, pictureBoxLocomotive.Height, map);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_mapLocomotiveCollectionGeneric = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var FormLocmotiveConfig = new FormLocomotiveConfig();
|
var FormLocmotiveConfig = new FormLocomotiveConfig();
|
||||||
@ -272,5 +246,28 @@ namespace Monorail
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ??
|
||||||
|
string.Empty].Sort(new LocomotiveCompareByType());
|
||||||
|
pictureBoxLocomotive.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 LocomotiveCompareByColor());
|
||||||
|
pictureBoxLocomotive.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Monorail
|
namespace Monorail
|
||||||
{
|
{
|
||||||
internal interface IDrawingObject
|
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг перемещения объекта
|
/// Шаг перемещения объекта
|
||||||
|
62
Monorail/Monorail/LocomotiveCompareByColor.cs
Normal file
62
Monorail/Monorail/LocomotiveCompareByColor.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail
|
||||||
|
{
|
||||||
|
internal class LocomotiveCompareByColor : 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 xLocomotive = x as DrawingObjectLocomotive;
|
||||||
|
var yLocomotive = y as DrawingObjectLocomotive;
|
||||||
|
if (xLocomotive == null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (xLocomotive == null && yLocomotive != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (xLocomotive != null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var xEntityLocomotive = xLocomotive.GetLocomotive.Locomotive;
|
||||||
|
var yEntityLocomotive = yLocomotive.GetLocomotive.Locomotive;
|
||||||
|
var baseColorCompare = xEntityLocomotive.BodyColor.ToArgb().CompareTo(yEntityLocomotive.BodyColor.ToArgb());
|
||||||
|
if (baseColorCompare != 0)
|
||||||
|
{
|
||||||
|
return baseColorCompare;
|
||||||
|
}
|
||||||
|
if (xEntityLocomotive is EntityMonorailLocomotive xMonorailLocomotive && yEntityLocomotive is EntityMonorailLocomotive yMonorailLocomotive)
|
||||||
|
{
|
||||||
|
var dopColorCompare = xMonorailLocomotive.DopColor.ToArgb().CompareTo(yMonorailLocomotive.DopColor.ToArgb());
|
||||||
|
if (dopColorCompare != 0)
|
||||||
|
{
|
||||||
|
return dopColorCompare;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var speedCompare = xLocomotive.GetLocomotive.Locomotive.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotive.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return xLocomotive.GetLocomotive.Locomotive.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotive.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
Monorail/Monorail/LocomotiveCompareByType.cs
Normal file
56
Monorail/Monorail/LocomotiveCompareByType.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail
|
||||||
|
{
|
||||||
|
internal class LocomotiveCompareByType : 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 xLocomotive = x as DrawingObjectLocomotive;
|
||||||
|
var yLocomotive = y as DrawingObjectLocomotive;
|
||||||
|
if (xLocomotive == null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (xLocomotive == null && yLocomotive != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (xLocomotive != null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (xLocomotive.GetLocomotive.GetType().Name != yLocomotive.GetLocomotive.GetType().Name)
|
||||||
|
{
|
||||||
|
if (xLocomotive.GetLocomotive.GetType().Name == "DrawingLocomotive")
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
var speedCompare =
|
||||||
|
xLocomotive.GetLocomotive.Locomotive.Speed.CompareTo(yLocomotive.GetLocomotive.Locomotive.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return xLocomotive.GetLocomotive.Locomotive.Weight.CompareTo(yLocomotive.GetLocomotive.Locomotive.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
namespace Monorail
|
namespace Monorail
|
||||||
{
|
{
|
||||||
internal class MapWithSetLocomotiveGeneric<T, U>
|
internal class MapWithSetLocomotiveGeneric<T, U>
|
||||||
where T : class, IDrawingObject
|
where T : class, IDrawingObject, IEquatable<T>
|
||||||
where U : AbstractMap
|
where U : AbstractMap
|
||||||
{
|
{
|
||||||
// Ширина окна отрисовки
|
// Ширина окна отрисовки
|
||||||
@ -55,7 +55,7 @@ namespace Monorail
|
|||||||
public Bitmap ShowOnMap()
|
public Bitmap ShowOnMap()
|
||||||
{
|
{
|
||||||
Shaking();
|
Shaking();
|
||||||
foreach (var locomotive in _setLocomotive.GetLocomotives())
|
foreach (var locomotive in _setLocomotive.GetLocomotive())
|
||||||
{
|
{
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive);
|
return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive);
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ namespace Monorail
|
|||||||
int xPosition = _pictureWidth - _placeSizeWidth;
|
int xPosition = _pictureWidth - _placeSizeWidth;
|
||||||
int yPosition = 12;
|
int yPosition = 12;
|
||||||
|
|
||||||
foreach (var locomotive in _setLocomotive.GetLocomotives())
|
foreach (var locomotive in _setLocomotive.GetLocomotive())
|
||||||
{
|
{
|
||||||
locomotive.SetObject(xPosition, yPosition, _pictureWidth, _pictureHeight);
|
locomotive.SetObject(xPosition, yPosition, _pictureWidth, _pictureHeight);
|
||||||
locomotive.DrawingObject(g);
|
locomotive.DrawingObject(g);
|
||||||
@ -135,7 +135,7 @@ namespace Monorail
|
|||||||
public string GetData(char separatorType, char separatorData)
|
public string GetData(char separatorType, char separatorData)
|
||||||
{
|
{
|
||||||
string data = $"{_map.GetType().Name}{separatorType}";
|
string data = $"{_map.GetType().Name}{separatorType}";
|
||||||
foreach (var boat in _setLocomotive.GetLocomotives())
|
foreach (var boat in _setLocomotive.GetLocomotive())
|
||||||
{
|
{
|
||||||
data += $"{boat.GetInfo()}{separatorData}";
|
data += $"{boat.GetInfo()}{separatorData}";
|
||||||
}
|
}
|
||||||
@ -148,5 +148,10 @@ namespace Monorail
|
|||||||
_setLocomotive.Insert(DrawingObjectLocomotive.Create(rec) as T);
|
_setLocomotive.Insert(DrawingObjectLocomotive.Create(rec) as T);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Sort(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
_setLocomotive.SortSet(comparer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,29 +7,30 @@ using System.Threading.Tasks;
|
|||||||
namespace Monorail
|
namespace Monorail
|
||||||
{
|
{
|
||||||
internal class SetLocomotiveGeneric<T>
|
internal class SetLocomotiveGeneric<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;
|
||||||
private readonly int _maxCount;
|
private readonly int _maxCount;
|
||||||
|
|
||||||
public SetLocomotiveGeneric(int count)
|
public SetLocomotiveGeneric(int count)
|
||||||
{
|
{
|
||||||
_maxCount = count;
|
_maxCount = count;
|
||||||
_places = new List<T>();
|
_places = new List<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T locomotive)
|
public int Insert(T locomotive)
|
||||||
{
|
{
|
||||||
return Insert(locomotive, 0);
|
return Insert(locomotive, 0);
|
||||||
}
|
}
|
||||||
public int Insert(T locomotive, int position)
|
public int Insert(T locomotive, int position)
|
||||||
{
|
{
|
||||||
if (Count == _maxCount)
|
if (_places.Contains(locomotive))
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Объект {locomotive} уже присутствует в наборе");
|
||||||
|
}
|
||||||
|
if (position < 0 || position > Count || _maxCount == Count)
|
||||||
{
|
{
|
||||||
throw new StorageOverflowException(_maxCount);
|
throw new StorageOverflowException(_maxCount);
|
||||||
}
|
}
|
||||||
if (position < 0 || position > _maxCount) return -1;
|
|
||||||
_places.Insert(position, locomotive);
|
_places.Insert(position, locomotive);
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
@ -43,23 +44,27 @@ namespace Monorail
|
|||||||
_places.RemoveAt(position);
|
_places.RemoveAt(position);
|
||||||
return ship;
|
return ship;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public T this[int position]
|
public T this[int position]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (position < _places.Count && position >= 0)
|
if (position >= Count || position < 0)
|
||||||
return _places[position];
|
{
|
||||||
else
|
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
return _places[position];
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
if (position >= Count || position < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
Insert(value, position);
|
Insert(value, position);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public IEnumerable<T> GetLocomotives()
|
public IEnumerable<T> GetLocomotive()
|
||||||
{
|
{
|
||||||
foreach (var locomotive in _places)
|
foreach (var locomotive in _places)
|
||||||
{
|
{
|
||||||
@ -73,5 +78,14 @@ namespace Monorail
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void SortSet(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
if (comparer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_places.Sort(comparer);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user