From 38def0fbc5e4e50d035a4814f1ca080f3040fc65 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 21 Nov 2022 17:38:47 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=A1=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Locomotive/DrawningObjectLocomotive.cs | 39 +++++++++++++++++++ Locomotive/Locomotive/IDrawningObject.cs | 2 +- .../MapWithSetLocomotivesGeneric.cs | 2 +- .../Locomotive/SetLocomotivesGeneric.cs | 3 +- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Locomotive/Locomotive/DrawningObjectLocomotive.cs b/Locomotive/Locomotive/DrawningObjectLocomotive.cs index ab86474..5ac2785 100644 --- a/Locomotive/Locomotive/DrawningObjectLocomotive.cs +++ b/Locomotive/Locomotive/DrawningObjectLocomotive.cs @@ -39,5 +39,44 @@ namespace Locomotive public string getInfo() => _locomotive?.getDataForSave(); 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() != otherLocomotiveLocomotive.GetType()) 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; + } } } diff --git a/Locomotive/Locomotive/IDrawningObject.cs b/Locomotive/Locomotive/IDrawningObject.cs index 37473dd..de4ff4c 100644 --- a/Locomotive/Locomotive/IDrawningObject.cs +++ b/Locomotive/Locomotive/IDrawningObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Locomotive { - internal interface IDrawningObject + internal interface IDrawningObject : IEquatable { /// Шаг перемещения объекта public float Step { get; } diff --git a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs index f533023..e6642a3 100644 --- a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Locomotive { internal class MapWithSetLocomotivesGeneric - where T : class, IDrawningObject + where T : class, IDrawningObject, IEquatable where U : AbstractMap { /// Ширина окна отрисовки diff --git a/Locomotive/Locomotive/SetLocomotivesGeneric.cs b/Locomotive/Locomotive/SetLocomotivesGeneric.cs index 104b027..add448c 100644 --- a/Locomotive/Locomotive/SetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/SetLocomotivesGeneric.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace Locomotive { internal class SetLocomotivesGeneric - where T : class + where T : class, IEquatable { /// Список хранимых объектов private readonly List _places; @@ -31,6 +31,7 @@ namespace Locomotive /// Добавление объекта в набор на конкретную позицию public int Insert(T locomotive, int position) { + if (_places.Contains(locomotive)) return -1; // Проверка на уникальность if (position < 0) return -1; if (Count >= _maxCount) { Log.Warning("StorageOverflowException"); -- 2.25.1 From 5a1cdcd4b234b1483cd4139461eabf687fd52e4b Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 21 Nov 2022 19:27:25 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=A1=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Locomotive/DrawningObjectLocomotive.cs | 4 +- .../FormMapWithSetLocomotives.Designer.cs | 44 ++++++++--- .../Locomotive/FormMapWithSetLocomotives.cs | 20 +++++ .../Locomotive/FormMapWithSetLocomotives.resx | 2 +- .../Locomotive/LocomotiveCompareByColor.cs | 78 +++++++++++++++++++ .../Locomotive/LocomotiveCompareByType.cs | 55 +++++++++++++ .../MapWithSetLocomotivesGeneric.cs | 5 +- .../Locomotive/SetLocomotivesGeneric.cs | 10 +++ Locomotive/log.clef | 17 ++++ 9 files changed, 223 insertions(+), 12 deletions(-) create mode 100644 Locomotive/Locomotive/LocomotiveCompareByColor.cs create mode 100644 Locomotive/Locomotive/LocomotiveCompareByType.cs create mode 100644 Locomotive/log.clef diff --git a/Locomotive/Locomotive/DrawningObjectLocomotive.cs b/Locomotive/Locomotive/DrawningObjectLocomotive.cs index 5ac2785..8abd23b 100644 --- a/Locomotive/Locomotive/DrawningObjectLocomotive.cs +++ b/Locomotive/Locomotive/DrawningObjectLocomotive.cs @@ -17,6 +17,8 @@ namespace Locomotive public float Step => _locomotive?.Locomotive?.Step ?? 0; + public DrawningLocomotive GetLocomotive => _locomotive; + public void DrawningObject(Graphics g) { _locomotive?.DrawTransport(g); @@ -54,7 +56,7 @@ namespace Locomotive var locomotive = _locomotive.Locomotive; var otherLocomotiveLocomotive = otherLocomotive._locomotive.Locomotive; - if (locomotive.GetType() != otherLocomotiveLocomotive.GetType()) return false; + if (locomotive.GetType().Name != otherLocomotiveLocomotive.GetType().Name) return false; if (locomotive.Speed != otherLocomotiveLocomotive.Speed) { diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs index 5242822..3397daa 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs @@ -29,6 +29,7 @@ private void InitializeComponent() { this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.ButtonSortByType = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.buttonDeleteMap = new System.Windows.Forms.Button(); this.listBoxMaps = new System.Windows.Forms.ListBox(); @@ -51,6 +52,7 @@ this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.loadFileDialog = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.ButtonSortByColor = new System.Windows.Forms.Button(); this.groupBoxTools.SuspendLayout(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); @@ -59,6 +61,8 @@ // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.ButtonSortByColor); + this.groupBoxTools.Controls.Add(this.ButtonSortByType); this.groupBoxTools.Controls.Add(this.groupBox1); this.groupBoxTools.Controls.Add(this.buttonLeft); this.groupBoxTools.Controls.Add(this.buttonRight); @@ -72,11 +76,21 @@ this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Location = new System.Drawing.Point(580, 28); 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.TabStop = false; 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 // this.groupBox1.Controls.Add(this.buttonDeleteMap); @@ -144,7 +158,7 @@ // this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow; 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.Size = new System.Drawing.Size(40, 40); this.buttonLeft.TabIndex = 7; @@ -155,7 +169,7 @@ // this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow; 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.Size = new System.Drawing.Size(40, 40); this.buttonRight.TabIndex = 7; @@ -166,7 +180,7 @@ // this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow; 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.Size = new System.Drawing.Size(40, 40); this.buttonDown.TabIndex = 7; @@ -177,7 +191,7 @@ // this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow; 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.Size = new System.Drawing.Size(40, 40); this.buttonUp.TabIndex = 6; @@ -237,7 +251,7 @@ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 28); 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.TabStop = false; // @@ -263,14 +277,14 @@ // 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.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); // // 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.Click += new System.EventHandler(this.loadToolStripMenuItem_Click); // @@ -282,11 +296,21 @@ // 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); 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.groupBoxTools); this.Controls.Add(this.menuStrip); @@ -330,5 +354,7 @@ private ToolStripMenuItem loadToolStripMenuItem; private OpenFileDialog loadFileDialog; private SaveFileDialog saveFileDialog; + private Button ButtonSortByType; + private Button ButtonSortByColor; } } \ No newline at end of file diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs index a4d16e9..ef12bc4 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs @@ -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(); + } } } diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.resx b/Locomotive/Locomotive/FormMapWithSetLocomotives.resx index a0c7756..3f94c35 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.resx +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.resx @@ -67,6 +67,6 @@ 311, 17 - 33 + 25 \ No newline at end of file diff --git a/Locomotive/Locomotive/LocomotiveCompareByColor.cs b/Locomotive/Locomotive/LocomotiveCompareByColor.cs new file mode 100644 index 0000000..53342fa --- /dev/null +++ b/Locomotive/Locomotive/LocomotiveCompareByColor.cs @@ -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 + { + 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); + + } + } +} diff --git a/Locomotive/Locomotive/LocomotiveCompareByType.cs b/Locomotive/Locomotive/LocomotiveCompareByType.cs new file mode 100644 index 0000000..a324498 --- /dev/null +++ b/Locomotive/Locomotive/LocomotiveCompareByType.cs @@ -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 + { + 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); + } + } +} diff --git a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs index e6642a3..d58cab9 100644 --- a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs @@ -178,6 +178,9 @@ namespace Locomotive } } - + public void Sort(IComparer comparer) + { + _setLocomotives.SortSet(comparer); + } } } diff --git a/Locomotive/Locomotive/SetLocomotivesGeneric.cs b/Locomotive/Locomotive/SetLocomotivesGeneric.cs index add448c..eafee89 100644 --- a/Locomotive/Locomotive/SetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/SetLocomotivesGeneric.cs @@ -77,5 +77,15 @@ namespace Locomotive } } + + public void SortSet(IComparer comparer) + { + if (comparer == null) + { + return; + } + _places.Sort(comparer); + } + } } diff --git a/Locomotive/log.clef b/Locomotive/log.clef new file mode 100644 index 0000000..2507a53 --- /dev/null +++ b/Locomotive/log.clef @@ -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"} -- 2.25.1 From a7027333d8b3bfd3386b3d442f375dfb9382e843 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 21 Nov 2022 19:43:07 +0400 Subject: [PATCH 3/5] IEquatable AbstractMap --- Locomotive/Locomotive/AbstractMap.cs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Locomotive/Locomotive/AbstractMap.cs b/Locomotive/Locomotive/AbstractMap.cs index d83050c..1fe18fb 100644 --- a/Locomotive/Locomotive/AbstractMap.cs +++ b/Locomotive/Locomotive/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Locomotive { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawningObject _drawningObject = null; protected int[,] _map = null; @@ -164,5 +164,30 @@ namespace Locomotive protected abstract void DrawRoadPart(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; + } } } -- 2.25.1 From 155ebec8ffdb7014f79ba0d403513ed7875cc6e5 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 21 Nov 2022 20:29:49 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=B1=D0=B0=D0=B3=20=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/AbstractMap.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Locomotive/Locomotive/AbstractMap.cs b/Locomotive/Locomotive/AbstractMap.cs index 1fe18fb..3b0c731 100644 --- a/Locomotive/Locomotive/AbstractMap.cs +++ b/Locomotive/Locomotive/AbstractMap.cs @@ -170,21 +170,20 @@ namespace Locomotive { return false; } - var otherMap = other as AbstractMap; - if (otherMap == null) + if (other == 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; + if (_width != other._width) return false; + if (_height != other._height) return false; + if (_size_x != other._size_x) return false; + if (_size_y != other._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; + if (_map[i,j] != other._map[i,j]) return false; } } return true; -- 2.25.1 From ef7754bdf9a76502c1288b66524cb15610f84b85 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Tue, 22 Nov 2022 16:15:15 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=9B=D0=B0=D0=B18=20=D1=81=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/MapsCollection.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Locomotive/Locomotive/MapsCollection.cs b/Locomotive/Locomotive/MapsCollection.cs index 01faa30..f97d40a 100644 --- a/Locomotive/Locomotive/MapsCollection.cs +++ b/Locomotive/Locomotive/MapsCollection.cs @@ -31,6 +31,7 @@ namespace Locomotive _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } + /// Добавление карты public void AddMap(string name, AbstractMap map) { @@ -117,7 +118,7 @@ namespace Locomotive } } - } + } } -- 2.25.1