Compare commits
3 Commits
88b702d5b5
...
a7027333d8
Author | SHA1 | Date | |
---|---|---|---|
a7027333d8 | |||
5a1cdcd4b2 | |||
38def0fbc5 |
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Locomotive
|
namespace Locomotive
|
||||||
{
|
{
|
||||||
internal abstract class AbstractMap
|
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||||
{
|
{
|
||||||
private IDrawningObject _drawningObject = null;
|
private IDrawningObject _drawningObject = null;
|
||||||
protected int[,] _map = null;
|
protected int[,] _map = null;
|
||||||
@ -164,5 +164,30 @@ namespace Locomotive
|
|||||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||||
|
|
||||||
|
public bool Equals(AbstractMap? other)
|
||||||
|
{
|
||||||
|
if (other == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var otherMap = other as AbstractMap;
|
||||||
|
if (otherMap == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_width != otherMap._width) return false;
|
||||||
|
if (_height != otherMap._height) return false;
|
||||||
|
if (_size_x != otherMap._size_x) return false;
|
||||||
|
if (_size_y != otherMap._size_y) return false;
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i,j] != otherMap._map[i,j]) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ namespace Locomotive
|
|||||||
|
|
||||||
public float Step => _locomotive?.Locomotive?.Step ?? 0;
|
public float Step => _locomotive?.Locomotive?.Step ?? 0;
|
||||||
|
|
||||||
|
public DrawningLocomotive GetLocomotive => _locomotive;
|
||||||
|
|
||||||
public void DrawningObject(Graphics g)
|
public void DrawningObject(Graphics g)
|
||||||
{
|
{
|
||||||
_locomotive?.DrawTransport(g);
|
_locomotive?.DrawTransport(g);
|
||||||
@ -39,5 +41,44 @@ namespace Locomotive
|
|||||||
public string getInfo() => _locomotive?.getDataForSave();
|
public string getInfo() => _locomotive?.getDataForSave();
|
||||||
|
|
||||||
public static IDrawningObject Create(string data) => new DrawningObjectLocomotive(data.createDrawningLocomotive());
|
public static IDrawningObject Create(string data) => new DrawningObjectLocomotive(data.createDrawningLocomotive());
|
||||||
|
|
||||||
|
public bool Equals(IDrawningObject? other)
|
||||||
|
{
|
||||||
|
if (other == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var otherLocomotive = other as DrawningObjectLocomotive;
|
||||||
|
if (otherLocomotive == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var locomotive = _locomotive.Locomotive;
|
||||||
|
var otherLocomotiveLocomotive = otherLocomotive._locomotive.Locomotive;
|
||||||
|
|
||||||
|
if (locomotive.GetType().Name != otherLocomotiveLocomotive.GetType().Name) return false;
|
||||||
|
|
||||||
|
if (locomotive.Speed != otherLocomotiveLocomotive.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (locomotive.Weight != otherLocomotiveLocomotive.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (locomotive.BodyColor != otherLocomotiveLocomotive.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// проверка в случае продвинутого объекта
|
||||||
|
if (locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive && otherLocomotiveLocomotive is EntityWarmlyLocomotive otherEntityWarmlyLocomotive)
|
||||||
|
{
|
||||||
|
if (entityWarmlyLocomotive.ExtraColor != otherEntityWarmlyLocomotive.ExtraColor) return false;
|
||||||
|
if (entityWarmlyLocomotive.Pipe != otherEntityWarmlyLocomotive.Pipe) return false;
|
||||||
|
if (entityWarmlyLocomotive.FuelStorage != otherEntityWarmlyLocomotive.FuelStorage) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||||
|
this.ButtonSortByType = new System.Windows.Forms.Button();
|
||||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
this.groupBox1 = 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();
|
||||||
@ -51,6 +52,7 @@
|
|||||||
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.loadFileDialog = new System.Windows.Forms.OpenFileDialog();
|
this.loadFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||||
|
this.ButtonSortByColor = new System.Windows.Forms.Button();
|
||||||
this.groupBoxTools.SuspendLayout();
|
this.groupBoxTools.SuspendLayout();
|
||||||
this.groupBox1.SuspendLayout();
|
this.groupBox1.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.groupBox1);
|
this.groupBoxTools.Controls.Add(this.groupBox1);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||||
@ -72,11 +76,21 @@
|
|||||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
this.groupBoxTools.Location = new System.Drawing.Point(580, 28);
|
this.groupBoxTools.Location = new System.Drawing.Point(580, 28);
|
||||||
this.groupBoxTools.Name = "groupBoxTools";
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
this.groupBoxTools.Size = new System.Drawing.Size(220, 540);
|
this.groupBoxTools.Size = new System.Drawing.Size(220, 637);
|
||||||
this.groupBoxTools.TabIndex = 0;
|
this.groupBoxTools.TabIndex = 0;
|
||||||
this.groupBoxTools.TabStop = false;
|
this.groupBoxTools.TabStop = false;
|
||||||
this.groupBoxTools.Text = "Tools";
|
this.groupBoxTools.Text = "Tools";
|
||||||
//
|
//
|
||||||
|
// ButtonSortByType
|
||||||
|
//
|
||||||
|
this.ButtonSortByType.Location = new System.Drawing.Point(7, 456);
|
||||||
|
this.ButtonSortByType.Name = "ButtonSortByType";
|
||||||
|
this.ButtonSortByType.Size = new System.Drawing.Size(207, 29);
|
||||||
|
this.ButtonSortByType.TabIndex = 9;
|
||||||
|
this.ButtonSortByType.Text = "Sort By Type";
|
||||||
|
this.ButtonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||||
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
this.groupBox1.Controls.Add(this.buttonDeleteMap);
|
this.groupBox1.Controls.Add(this.buttonDeleteMap);
|
||||||
@ -144,7 +158,7 @@
|
|||||||
//
|
//
|
||||||
this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow;
|
this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow;
|
||||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonLeft.Location = new System.Drawing.Point(42, 502);
|
this.buttonLeft.Location = new System.Drawing.Point(48, 591);
|
||||||
this.buttonLeft.Name = "buttonLeft";
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
this.buttonLeft.Size = new System.Drawing.Size(40, 40);
|
this.buttonLeft.Size = new System.Drawing.Size(40, 40);
|
||||||
this.buttonLeft.TabIndex = 7;
|
this.buttonLeft.TabIndex = 7;
|
||||||
@ -155,7 +169,7 @@
|
|||||||
//
|
//
|
||||||
this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow;
|
this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow;
|
||||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonRight.Location = new System.Drawing.Point(134, 502);
|
this.buttonRight.Location = new System.Drawing.Point(140, 591);
|
||||||
this.buttonRight.Name = "buttonRight";
|
this.buttonRight.Name = "buttonRight";
|
||||||
this.buttonRight.Size = new System.Drawing.Size(40, 40);
|
this.buttonRight.Size = new System.Drawing.Size(40, 40);
|
||||||
this.buttonRight.TabIndex = 7;
|
this.buttonRight.TabIndex = 7;
|
||||||
@ -166,7 +180,7 @@
|
|||||||
//
|
//
|
||||||
this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow;
|
this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow;
|
||||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonDown.Location = new System.Drawing.Point(88, 502);
|
this.buttonDown.Location = new System.Drawing.Point(94, 591);
|
||||||
this.buttonDown.Name = "buttonDown";
|
this.buttonDown.Name = "buttonDown";
|
||||||
this.buttonDown.Size = new System.Drawing.Size(40, 40);
|
this.buttonDown.Size = new System.Drawing.Size(40, 40);
|
||||||
this.buttonDown.TabIndex = 7;
|
this.buttonDown.TabIndex = 7;
|
||||||
@ -177,7 +191,7 @@
|
|||||||
//
|
//
|
||||||
this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow;
|
this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow;
|
||||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||||
this.buttonUp.Location = new System.Drawing.Point(88, 456);
|
this.buttonUp.Location = new System.Drawing.Point(94, 545);
|
||||||
this.buttonUp.Name = "buttonUp";
|
this.buttonUp.Name = "buttonUp";
|
||||||
this.buttonUp.Size = new System.Drawing.Size(40, 40);
|
this.buttonUp.Size = new System.Drawing.Size(40, 40);
|
||||||
this.buttonUp.TabIndex = 6;
|
this.buttonUp.TabIndex = 6;
|
||||||
@ -237,7 +251,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, 28);
|
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||||
this.pictureBox.Name = "pictureBox";
|
this.pictureBox.Name = "pictureBox";
|
||||||
this.pictureBox.Size = new System.Drawing.Size(580, 540);
|
this.pictureBox.Size = new System.Drawing.Size(580, 637);
|
||||||
this.pictureBox.TabIndex = 1;
|
this.pictureBox.TabIndex = 1;
|
||||||
this.pictureBox.TabStop = false;
|
this.pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -263,14 +277,14 @@
|
|||||||
// saveToolStripMenuItem
|
// saveToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
this.saveToolStripMenuItem.Size = new System.Drawing.Size(125, 26);
|
||||||
this.saveToolStripMenuItem.Text = "Save";
|
this.saveToolStripMenuItem.Text = "Save";
|
||||||
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(224, 26);
|
this.loadToolStripMenuItem.Size = new System.Drawing.Size(125, 26);
|
||||||
this.loadToolStripMenuItem.Text = "Load";
|
this.loadToolStripMenuItem.Text = "Load";
|
||||||
this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
|
this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
@ -282,11 +296,21 @@
|
|||||||
//
|
//
|
||||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||||
//
|
//
|
||||||
|
// ButtonSortByColor
|
||||||
|
//
|
||||||
|
this.ButtonSortByColor.Location = new System.Drawing.Point(7, 491);
|
||||||
|
this.ButtonSortByColor.Name = "ButtonSortByColor";
|
||||||
|
this.ButtonSortByColor.Size = new System.Drawing.Size(207, 29);
|
||||||
|
this.ButtonSortByColor.TabIndex = 10;
|
||||||
|
this.ButtonSortByColor.Text = "Sort By Color";
|
||||||
|
this.ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||||
|
//
|
||||||
// FormMapWithSetLocomotives
|
// FormMapWithSetLocomotives
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 568);
|
this.ClientSize = new System.Drawing.Size(800, 665);
|
||||||
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);
|
||||||
@ -330,5 +354,7 @@
|
|||||||
private ToolStripMenuItem loadToolStripMenuItem;
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
private OpenFileDialog loadFileDialog;
|
private OpenFileDialog loadFileDialog;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button ButtonSortByType;
|
||||||
|
private Button ButtonSortByColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -254,5 +254,25 @@ namespace Locomotive
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new LocomotiveCompareByType());
|
||||||
|
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 LocomotiveCompareByColor());
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,6 @@
|
|||||||
<value>311, 17</value>
|
<value>311, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>33</value>
|
<value>25</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Locomotive
|
namespace Locomotive
|
||||||
{
|
{
|
||||||
internal interface IDrawningObject
|
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||||
{
|
{
|
||||||
/// Шаг перемещения объекта
|
/// Шаг перемещения объекта
|
||||||
public float Step { get; }
|
public float Step { get; }
|
||||||
|
78
Locomotive/Locomotive/LocomotiveCompareByColor.cs
Normal file
78
Locomotive/Locomotive/LocomotiveCompareByColor.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class LocomotiveCompareByColor : 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 xLocomotive = x as DrawningObjectLocomotive;
|
||||||
|
var yLocomotive = y as DrawningObjectLocomotive;
|
||||||
|
if (xLocomotive == null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (xLocomotive == null && yLocomotive != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (xLocomotive != null && yLocomotive == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xLocomotive.GetLocomotive.Locomotive.BodyColor.R.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.R) != 0)
|
||||||
|
{
|
||||||
|
return xLocomotive.GetLocomotive.Locomotive.BodyColor.R.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.R);
|
||||||
|
}
|
||||||
|
if (xLocomotive.GetLocomotive.Locomotive.BodyColor.G.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.G) != 0)
|
||||||
|
{
|
||||||
|
return xLocomotive.GetLocomotive.Locomotive.BodyColor.G.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.G);
|
||||||
|
}
|
||||||
|
if (xLocomotive.GetLocomotive.Locomotive.BodyColor.B.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.B) != 0)
|
||||||
|
{
|
||||||
|
return xLocomotive.GetLocomotive.Locomotive.BodyColor.B.CompareTo(yLocomotive.GetLocomotive.Locomotive.BodyColor.B);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xLocomotive.GetLocomotive.Locomotive is EntityWarmlyLocomotive xWarmlyEntity && yLocomotive.GetLocomotive.Locomotive is EntityWarmlyLocomotive yWarmlyEntity)
|
||||||
|
{
|
||||||
|
if (xWarmlyEntity.ExtraColor.R.CompareTo(yWarmlyEntity.ExtraColor.R) != 0)
|
||||||
|
{
|
||||||
|
return xWarmlyEntity.ExtraColor.R.CompareTo(yWarmlyEntity.ExtraColor.R);
|
||||||
|
}
|
||||||
|
if (xWarmlyEntity.ExtraColor.G.CompareTo(yWarmlyEntity.ExtraColor.G) != 0)
|
||||||
|
{
|
||||||
|
return xWarmlyEntity.ExtraColor.G.CompareTo(yWarmlyEntity.ExtraColor.G);
|
||||||
|
}
|
||||||
|
if (xWarmlyEntity.ExtraColor.B.CompareTo(yWarmlyEntity.ExtraColor.B) != 0)
|
||||||
|
{
|
||||||
|
return xWarmlyEntity.ExtraColor.B.CompareTo(yWarmlyEntity.ExtraColor.B);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
Locomotive/Locomotive/LocomotiveCompareByType.cs
Normal file
55
Locomotive/Locomotive/LocomotiveCompareByType.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Locomotive
|
||||||
|
{
|
||||||
|
internal class LocomotiveCompareByType : 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 xLocomotive = x as DrawningObjectLocomotive;
|
||||||
|
var yLocomotive = y as DrawningObjectLocomotive;
|
||||||
|
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 == "DrawningLocomotive")
|
||||||
|
{
|
||||||
|
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 Locomotive
|
namespace Locomotive
|
||||||
{
|
{
|
||||||
internal class MapWithSetLocomotivesGeneric <T, U>
|
internal class MapWithSetLocomotivesGeneric <T, U>
|
||||||
where T : class, IDrawningObject
|
where T : class, IDrawningObject, IEquatable<T>
|
||||||
where U : AbstractMap
|
where U : AbstractMap
|
||||||
{
|
{
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
@ -178,6 +178,9 @@ namespace Locomotive
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Sort(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
_setLocomotives.SortSet(comparer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||||||
namespace Locomotive
|
namespace Locomotive
|
||||||
{
|
{
|
||||||
internal class SetLocomotivesGeneric <T>
|
internal class SetLocomotivesGeneric <T>
|
||||||
where T : class
|
where T : class, IEquatable<T>
|
||||||
{
|
{
|
||||||
/// Список хранимых объектов
|
/// Список хранимых объектов
|
||||||
private readonly List<T> _places;
|
private readonly List<T> _places;
|
||||||
@ -31,6 +31,7 @@ namespace Locomotive
|
|||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
public int Insert(T locomotive, int position)
|
public int Insert(T locomotive, int position)
|
||||||
{
|
{
|
||||||
|
if (_places.Contains(locomotive)) return -1; // Проверка на уникальность
|
||||||
if (position < 0) return -1;
|
if (position < 0) return -1;
|
||||||
if (Count >= _maxCount) {
|
if (Count >= _maxCount) {
|
||||||
Log.Warning("StorageOverflowException");
|
Log.Warning("StorageOverflowException");
|
||||||
@ -76,5 +77,15 @@ namespace Locomotive
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SortSet(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
if (comparer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_places.Sort(comparer);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
Locomotive/log.clef
Normal file
17
Locomotive/log.clef
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{"@t":"2022-11-21T15:23:13.2775821Z","@mt":"Map lalaland added"}
|
||||||
|
{"@t":"2022-11-21T15:23:13.3466012Z","@mt":"Map switched to lalaland"}
|
||||||
|
{"@t":"2022-11-21T15:23:31.6565447Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||||
|
{"@t":"2022-11-21T15:23:57.7770111Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||||
|
{"@t":"2022-11-21T15:25:01.0533266Z","@mt":"Map lalaland added"}
|
||||||
|
{"@t":"2022-11-21T15:25:01.0794891Z","@mt":"Map switched to lalaland"}
|
||||||
|
{"@t":"2022-11-21T15:25:01.4998647Z","@mt":"Map switched to lalaland"}
|
||||||
|
{"@t":"2022-11-21T15:25:06.1595618Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||||
|
{"@t":"2022-11-21T15:25:18.9994738Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||||
|
{"@t":"2022-11-21T15:25:31.8129464Z","@mt":"Map lalaland added"}
|
||||||
|
{"@t":"2022-11-21T15:25:31.8344280Z","@mt":"Map switched to lalaland"}
|
||||||
|
{"@t":"2022-11-21T15:25:37.1362070Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||||
|
{"@t":"2022-11-21T15:25:46.1930394Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||||
|
{"@t":"2022-11-21T15:26:02.0790751Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||||
|
{"@t":"2022-11-21T15:26:24.6631252Z","@mt":"Object Locomotive.DrawningWarmlyLocomotive added"}
|
||||||
|
{"@t":"2022-11-21T15:26:31.0236570Z","@mt":"Object Locomotive.DrawningLocomotive added"}
|
||||||
|
{"@t":"2022-11-21T15:26:36.0331011Z","@mt":"Object Locomotive.DrawningWarmlyLocomotive added"}
|
Loading…
Reference in New Issue
Block a user