From d628bda63b101e4506e4965406c1306b34a39a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 29 Nov 2022 11:11:20 +0400 Subject: [PATCH 1/6] 5 min --- .../DrawingObjectGasolineTanker.cs | 27 +++++++++++++++++++ .../GasolineTanker/IDrawingObject.cs | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs index 16f50af..9c650c3 100644 --- a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs @@ -38,5 +38,32 @@ namespace GasolineTanker } public string GetInfo() => _gasolineTanker?.GetDataForSave(); public static IDrawingObject Create(string data) => new DrawingObjectGasolineTanker(data.CreateDrawingGasolineTanker()); + + public bool Equals(IDrawingObject? other) + { + if (other is not DrawingObjectGasolineTanker otherGasolineTanker) + { + return false; + } + var entity = ; + var otherEntity = otherGasolineTanker.; + if (entity.GetType() != otherEntity.GetType() || + entity.Speed != otherEntity.Speed || + entity.Weight != otherEntity.Weight || + entity.BodyColor != otherEntity.BodyColor) + { + return false; + } + if (entity is EntityImprovedGasolineTanker entityImprovedGasolineTanker && + otherEntity is EntityImprovedGasolineTanker otherEntityWarmlyShip && ( + entityImprovedGasolineTanker.BodyColor != otherEntityWarmlyShip.BodyColor || + entityImprovedGasolineTanker.DopColor != otherEntityWarmlyShip.DopColor || + entityImprovedGasolineTanker.BodyKit != otherEntityWarmlyShip.BodyKit)) + { + return false; + } + return true; + } } } +} diff --git a/GasolineTanker/GasolineTanker/IDrawingObject.cs b/GasolineTanker/GasolineTanker/IDrawingObject.cs index 8697e99..4215fa0 100644 --- a/GasolineTanker/GasolineTanker/IDrawingObject.cs +++ b/GasolineTanker/GasolineTanker/IDrawingObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace GasolineTanker { - internal interface IDrawingObject + internal interface IDrawingObject : IEquatable { public float Step { get; } void SetObject(int x, int y, int width, int height); -- 2.25.1 From eb5bbe7f69283d2a108ea13efd50738ea0aaebbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 29 Nov 2022 21:29:56 +0400 Subject: [PATCH 2/6] Mb fix --- GasolineTanker/GasolineTanker/AbstractMap.cs | 29 +++- .../DrawingObjectGasolineTanker.cs | 7 +- .../FormMapWithSetGasolineTanker.Designer.cs | 138 +++++++++++------- .../FormMapWithSetGasolineTanker.cs | 42 +++--- .../GasolineTankerCompareByColor.cs | 39 +++++ .../GasolineTankerCompareByType.cs | 44 ++++++ .../MapWithSetGasolienTankerGeneric.cs | 6 +- .../SetGasolineTankerGeneric.cs | 12 +- 8 files changed, 234 insertions(+), 83 deletions(-) create mode 100644 GasolineTanker/GasolineTanker/GasolineTankerCompareByColor.cs create mode 100644 GasolineTanker/GasolineTanker/GasolineTankerCompareByType.cs diff --git a/GasolineTanker/GasolineTanker/AbstractMap.cs b/GasolineTanker/GasolineTanker/AbstractMap.cs index 8b1c8a5..8c61fa8 100644 --- a/GasolineTanker/GasolineTanker/AbstractMap.cs +++ b/GasolineTanker/GasolineTanker/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace GasolineTanker { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawingObject _drawningObject = null; protected int[,] _map = null; @@ -143,6 +143,33 @@ namespace GasolineTanker return bmp; } + public bool Equals(AbstractMap? other) + { + if (other == null || + _map != other._map || + _width != other._width || + _size_x != other._size_x || + _size_y != other._size_y || + _height != other._height || + GetType() != other.GetType() || + _map.GetLength(0) != other._map.GetLength(0) || + _map.GetLength(1) != other._map.GetLength(1)) + { + return false; + } + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] != other._map[i, j]) + { + return false; + } + } + } + return true; + } + protected abstract void GenerateMap(); protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j); diff --git a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs index 9c650c3..32be3ce 100644 --- a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs @@ -15,6 +15,8 @@ namespace GasolineTanker _gasolineTanker = gasolineTanker; } + public DrawingGasolineTanker GetGasolineTanker => _gasolineTanker; + public float Step => _gasolineTanker?.GasolineTanker?.Step ?? 0; public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() @@ -45,8 +47,8 @@ namespace GasolineTanker { return false; } - var entity = ; - var otherEntity = otherGasolineTanker.; + var entity = _gasolineTanker.GasolineTanker; + var otherEntity = otherGasolineTanker._gasolineTanker.GasolineTanker; if (entity.GetType() != otherEntity.GetType() || entity.Speed != otherEntity.Speed || entity.Weight != otherEntity.Weight || @@ -66,4 +68,3 @@ namespace GasolineTanker } } } -} diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs index fb24cb3..690e840 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs @@ -51,6 +51,8 @@ this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.buttonSortByType = new System.Windows.Forms.Button(); + this.buttonSortByColor = new System.Windows.Forms.Button(); this.groupBoxTools.SuspendLayout(); this.groupBoxMaps.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.groupBoxMaps); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.keyRight); @@ -70,9 +74,11 @@ this.groupBoxTools.Controls.Add(this.buttonRemoveGasolineTanker); this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(694, 24); + this.groupBoxTools.Location = new System.Drawing.Point(793, 30); + this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(200, 631); + this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxTools.Size = new System.Drawing.Size(229, 924); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Tools"; @@ -84,18 +90,21 @@ this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); - this.groupBoxMaps.Location = new System.Drawing.Point(6, 22); + this.groupBoxMaps.Location = new System.Drawing.Point(7, 29); + this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxMaps.Name = "groupBoxMaps"; - this.groupBoxMaps.Size = new System.Drawing.Size(190, 305); + this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxMaps.Size = new System.Drawing.Size(217, 407); this.groupBoxMaps.TabIndex = 13; this.groupBoxMaps.TabStop = false; this.groupBoxMaps.Text = "Maps"; // // buttonDeleteMap // - this.buttonDeleteMap.Location = new System.Drawing.Point(6, 241); + this.buttonDeleteMap.Location = new System.Drawing.Point(7, 321); + this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonDeleteMap.Name = "buttonDeleteMap"; - this.buttonDeleteMap.Size = new System.Drawing.Size(175, 49); + this.buttonDeleteMap.Size = new System.Drawing.Size(200, 65); this.buttonDeleteMap.TabIndex = 16; this.buttonDeleteMap.Text = "Delete Map"; this.buttonDeleteMap.UseVisualStyleBackColor = true; @@ -104,18 +113,20 @@ // listBoxMaps // this.listBoxMaps.FormattingEnabled = true; - this.listBoxMaps.ItemHeight = 15; - this.listBoxMaps.Location = new System.Drawing.Point(6, 141); + this.listBoxMaps.ItemHeight = 20; + this.listBoxMaps.Location = new System.Drawing.Point(7, 188); + this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.listBoxMaps.Name = "listBoxMaps"; - this.listBoxMaps.Size = new System.Drawing.Size(176, 94); + this.listBoxMaps.Size = new System.Drawing.Size(201, 124); this.listBoxMaps.TabIndex = 15; this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged); // // buttonAddMap // - this.buttonAddMap.Location = new System.Drawing.Point(6, 84); + this.buttonAddMap.Location = new System.Drawing.Point(7, 112); + this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonAddMap.Name = "buttonAddMap"; - this.buttonAddMap.Size = new System.Drawing.Size(176, 51); + this.buttonAddMap.Size = new System.Drawing.Size(201, 68); this.buttonAddMap.TabIndex = 14; this.buttonAddMap.Text = "Add Map"; this.buttonAddMap.UseVisualStyleBackColor = true; @@ -123,30 +134,19 @@ // // textBoxNewMapName // - this.textBoxNewMapName.Location = new System.Drawing.Point(6, 24); + this.textBoxNewMapName.Location = new System.Drawing.Point(7, 32); + this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.textBoxNewMapName.Name = "textBoxNewMapName"; - this.textBoxNewMapName.Size = new System.Drawing.Size(178, 23); + this.textBoxNewMapName.Size = new System.Drawing.Size(203, 27); this.textBoxNewMapName.TabIndex = 13; // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Simple map", - "Long map"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 53); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(178, 23); - this.comboBoxSelectorMap.TabIndex = 12; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); - // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 391); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(16, 611); + this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 23); + this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27); this.maskedTextBoxPosition.TabIndex = 11; // // keyRight @@ -154,9 +154,10 @@ this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyRight.Location = new System.Drawing.Point(122, 589); + this.keyRight.Location = new System.Drawing.Point(139, 868); + this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyRight.Name = "keyRight"; - this.keyRight.Size = new System.Drawing.Size(30, 30); + this.keyRight.Size = new System.Drawing.Size(34, 40); this.keyRight.TabIndex = 10; this.keyRight.UseVisualStyleBackColor = true; this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); @@ -166,9 +167,10 @@ this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyLeft.Location = new System.Drawing.Point(50, 589); + this.keyLeft.Location = new System.Drawing.Point(57, 868); + this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyLeft.Name = "keyLeft"; - this.keyLeft.Size = new System.Drawing.Size(30, 30); + this.keyLeft.Size = new System.Drawing.Size(34, 40); this.keyLeft.TabIndex = 9; this.keyLeft.UseVisualStyleBackColor = true; this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); @@ -178,9 +180,10 @@ this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyUp.Location = new System.Drawing.Point(86, 553); + this.keyUp.Location = new System.Drawing.Point(98, 820); + this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyUp.Name = "keyUp"; - this.keyUp.Size = new System.Drawing.Size(30, 30); + this.keyUp.Size = new System.Drawing.Size(34, 40); this.keyUp.TabIndex = 8; this.keyUp.UseVisualStyleBackColor = true; this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); @@ -190,18 +193,20 @@ this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyDown.Location = new System.Drawing.Point(86, 589); + this.keyDown.Location = new System.Drawing.Point(98, 868); + this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyDown.Name = "keyDown"; - this.keyDown.Size = new System.Drawing.Size(30, 30); + this.keyDown.Size = new System.Drawing.Size(34, 40); this.keyDown.TabIndex = 7; this.keyDown.UseVisualStyleBackColor = true; this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(8, 500); + this.buttonShowOnMap.Location = new System.Drawing.Point(14, 757); + this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowOnMap.Name = "buttonShowOnMap"; - this.buttonShowOnMap.Size = new System.Drawing.Size(186, 34); + this.buttonShowOnMap.Size = new System.Drawing.Size(213, 45); this.buttonShowOnMap.TabIndex = 4; this.buttonShowOnMap.Text = "Show on map"; this.buttonShowOnMap.UseVisualStyleBackColor = true; @@ -209,9 +214,10 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(8, 460); + this.buttonShowStorage.Location = new System.Drawing.Point(14, 703); + this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowStorage.Name = "buttonShowStorage"; - this.buttonShowStorage.Size = new System.Drawing.Size(186, 34); + this.buttonShowStorage.Size = new System.Drawing.Size(213, 45); this.buttonShowStorage.TabIndex = 3; this.buttonShowStorage.Text = "Show storage"; this.buttonShowStorage.UseVisualStyleBackColor = true; @@ -219,9 +225,10 @@ // // buttonRemoveGasolineTanker // - this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(8, 420); + this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(14, 650); + this.buttonRemoveGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker"; - this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(186, 34); + this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(213, 45); this.buttonRemoveGasolineTanker.TabIndex = 2; this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker"; this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true; @@ -229,9 +236,10 @@ // // buttonAddGasolineTanker // - this.buttonAddGasolineTanker.Location = new System.Drawing.Point(10, 351); + this.buttonAddGasolineTanker.Location = new System.Drawing.Point(16, 558); + this.buttonAddGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker"; - this.buttonAddGasolineTanker.Size = new System.Drawing.Size(186, 34); + this.buttonAddGasolineTanker.Size = new System.Drawing.Size(213, 45); this.buttonAddGasolineTanker.TabIndex = 1; this.buttonAddGasolineTanker.Text = "Add gasoline tanker"; this.buttonAddGasolineTanker.UseVisualStyleBackColor = true; @@ -240,19 +248,22 @@ // pictureBox // 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, 30); + this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(694, 631); + this.pictureBox.Size = new System.Drawing.Size(793, 924); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // // menuStrip // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(894, 24); + this.menuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3); + this.menuStrip.Size = new System.Drawing.Size(1022, 30); this.menuStrip.TabIndex = 2; // // fileToolStripMenuItem @@ -261,20 +272,20 @@ this.SaveToolStripMenuItem, this.LoadToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); + this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24); this.fileToolStripMenuItem.Text = "File"; // // SaveToolStripMenuItem // this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; - this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + 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(180, 22); + this.LoadToolStripMenuItem.Size = new System.Drawing.Size(125, 26); this.LoadToolStripMenuItem.Text = "Load"; this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); // @@ -286,15 +297,36 @@ // this.saveFileDialog.Filter = "txt file | *.txt"; // + // buttonSortByType + // + this.buttonSortByType.Location = new System.Drawing.Point(16, 457); + this.buttonSortByType.Name = "buttonSortByType"; + this.buttonSortByType.Size = new System.Drawing.Size(198, 29); + this.buttonSortByType.TabIndex = 14; + this.buttonSortByType.Text = "Sort by type"; + this.buttonSortByType.UseVisualStyleBackColor = true; + this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click); + // + // buttonSortByColor + // + this.buttonSortByColor.Location = new System.Drawing.Point(16, 504); + this.buttonSortByColor.Name = "buttonSortByColor"; + this.buttonSortByColor.Size = new System.Drawing.Size(198, 29); + this.buttonSortByColor.TabIndex = 15; + this.buttonSortByColor.Text = "Sort by color"; + this.buttonSortByColor.UseVisualStyleBackColor = true; + this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click); + // // FormMapWithSetGasolineTanker // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(894, 655); + this.ClientSize = new System.Drawing.Size(1022, 954); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.menuStrip); this.MainMenuStrip = this.menuStrip; + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormMapWithSetGasolineTanker"; this.Text = "FormMapWithSetGasolineTanker"; this.groupBoxTools.ResumeLayout(false); @@ -334,5 +366,7 @@ private ToolStripMenuItem LoadToolStripMenuItem; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; + private Button buttonSortByColor; + private Button buttonSortByType; } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs index bc4fcb1..f7fc28e 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs @@ -17,7 +17,6 @@ namespace GasolineTanker { "Simple map", new SimpleMap() }, { "Long map", new LongMap() } }; - private MapWithSetGasolienTankerGeneric _mapGasolineTankerCollectionGeneric; private readonly MapsCollection _mapsCollection; private readonly ILogger _logger; public FormMapWithSetGasolineTanker(ILogger logger) @@ -106,6 +105,7 @@ namespace GasolineTanker _logger.LogWarning($"Storage full error: {ex.Message}"); MessageBox.Show($"Storage full error: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } + } private void ButtonShowStorage_Click(object sender, EventArgs e) @@ -114,7 +114,7 @@ namespace GasolineTanker { return; } - pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } private void ButtonShowOnMap_Click(object sender, EventArgs e) @@ -148,30 +148,9 @@ namespace GasolineTanker dir = Direction.Right; break; } - pictureBox.Image = _mapGasolineTankerCollectionGeneric.MoveObject(dir); - } - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - AbstractMap map = null; - switch (comboBoxSelectorMap.Text) - { - case "Simple map": - map = new SimpleMap(); - break; - case "Long map": - map = new LongMap(); - break; - } - if (map != null) - { - _mapGasolineTankerCollectionGeneric = new MapWithSetGasolienTankerGeneric( - pictureBox.Width, pictureBox.Height, map); - } - else - { - _mapGasolineTankerCollectionGeneric = null; - } + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); } + private void buttonAddMap_Click(object sender, EventArgs e) { if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) @@ -287,5 +266,18 @@ namespace GasolineTanker } } } + private void SortBy(IComparer comparer) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(comparer); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + private void buttonSortByType_Click(object sender, EventArgs e) => SortBy(new GasolineTankerCompareByType()); + + private void buttonSortByColor_Click(object sender, EventArgs e) => SortBy(new GasolineTankerCompareByColor()); + } } diff --git a/GasolineTanker/GasolineTanker/GasolineTankerCompareByColor.cs b/GasolineTanker/GasolineTanker/GasolineTankerCompareByColor.cs new file mode 100644 index 0000000..190bc28 --- /dev/null +++ b/GasolineTanker/GasolineTanker/GasolineTankerCompareByColor.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class GasolineTankerCompareByColor : IComparer + { + public int Compare(IDrawingObject? x, IDrawingObject? y) + { + var xGasolineTanker = x as DrawingObjectGasolineTanker; + var yGasolineTanker = y as DrawingObjectGasolineTanker; + if (xGasolineTanker == yGasolineTanker) + { + return 0; + } + if (xGasolineTanker == null) + { + return 1; + } + if (yGasolineTanker == null) + { + return -1; + } + var xEntity = xGasolineTanker.GetGasolineTanker.GasolineTanker; + var yEntity = yGasolineTanker.GetGasolineTanker.GasolineTanker; + var colorWeight = xEntity.BodyColor.ToArgb().CompareTo(yEntity.BodyColor.ToArgb()); + if (colorWeight != 0 || + xEntity is not EntityImprovedGasolineTanker xEntityImprovedGasolineTanker || + yEntity is not EntityImprovedGasolineTanker yEntityImprovedGasolineTanker) + { + return colorWeight; + } + return xEntityImprovedGasolineTanker.DopColor.ToArgb().CompareTo(yEntityImprovedGasolineTanker.DopColor.ToArgb()); + } + } +} diff --git a/GasolineTanker/GasolineTanker/GasolineTankerCompareByType.cs b/GasolineTanker/GasolineTanker/GasolineTankerCompareByType.cs new file mode 100644 index 0000000..a7dc938 --- /dev/null +++ b/GasolineTanker/GasolineTanker/GasolineTankerCompareByType.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + internal class GasolineTankerCompareByType : IComparer + { + public int Compare(IDrawingObject? x, IDrawingObject? y) + { + var xGasolineTanker = x as DrawingObjectGasolineTanker; + var yGasolineTanker = y as DrawingObjectGasolineTanker; + if (xGasolineTanker == yGasolineTanker) + { + return 0; + } + if (xGasolineTanker == null) + { + return 1; + } + if (yGasolineTanker == null) + { + return -1; + } + if (xGasolineTanker.GetGasolineTanker.GetType().Name != yGasolineTanker.GetGasolineTanker.GetType().Name) + { + if (xGasolineTanker.GetGasolineTanker.GetType() == typeof(DrawingGasolineTanker)) + { + return -1; + } + return 1; + } + var speedCompare = xGasolineTanker.GetGasolineTanker.GasolineTanker.Speed.CompareTo(yGasolineTanker.GetGasolineTanker.GasolineTanker.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xGasolineTanker.GetGasolineTanker.GasolineTanker.Weight.CompareTo(yGasolineTanker.GetGasolineTanker.GasolineTanker.Weight); + } + } +} + diff --git a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs index 6db5ac2..5cacba4 100644 --- a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace GasolineTanker { internal class MapWithSetGasolienTankerGeneric - where T : class, IDrawingObject + where T : class, IEquatable, IDrawingObject where U : AbstractMap { private readonly int _pictureWidth; @@ -134,5 +134,9 @@ namespace GasolineTanker i++; } } + public void Sort(IComparer comparer) + { + _setGasolineTanker.SortSet(comparer); + } } } diff --git a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs index db88432..e12d64b 100644 --- a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace GasolineTanker { internal class SetGasolineTankerGeneric - where T : class + where T : class, IEquatable { private readonly List _places; public int Count => _places.Count; @@ -35,6 +35,8 @@ namespace GasolineTanker } public int Insert(T gasolineTanker, int position) { + if (_places.Contains(gasolineTanker)) + throw new ArgumentException($"Объект {gasolineTanker} уже есть в наборе"); if (Count == _maxCount) throw new StorageOverflowException(_maxCount); if (!isCorrectPosition(position)) @@ -81,5 +83,13 @@ namespace GasolineTanker } } } + public void SortSet(IComparer comparer) + { + if (comparer == null) + { + return; + } + _places.Sort(comparer); + } } } -- 2.25.1 From 75cbdc81761f26fc4488a6aa06dbd37d6f0c61b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 29 Nov 2022 21:35:34 +0400 Subject: [PATCH 3/6] FixForm --- .../FormMapWithSetGasolineTanker.Designer.cs | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs index 690e840..0f0f537 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs @@ -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(); @@ -51,8 +53,6 @@ this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); - this.buttonSortByType = new System.Windows.Forms.Button(); - this.buttonSortByColor = new System.Windows.Forms.Button(); this.groupBoxTools.SuspendLayout(); this.groupBoxMaps.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); @@ -83,6 +83,26 @@ this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Tools"; // + // buttonSortByColor + // + this.buttonSortByColor.Location = new System.Drawing.Point(16, 504); + this.buttonSortByColor.Name = "buttonSortByColor"; + this.buttonSortByColor.Size = new System.Drawing.Size(198, 29); + this.buttonSortByColor.TabIndex = 15; + this.buttonSortByColor.Text = "Sort by color"; + this.buttonSortByColor.UseVisualStyleBackColor = true; + this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click); + // + // buttonSortByType + // + this.buttonSortByType.Location = new System.Drawing.Point(16, 457); + this.buttonSortByType.Name = "buttonSortByType"; + this.buttonSortByType.Size = new System.Drawing.Size(198, 29); + this.buttonSortByType.TabIndex = 14; + this.buttonSortByType.Text = "Sort by type"; + this.buttonSortByType.UseVisualStyleBackColor = true; + this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click); + // // groupBoxMaps // this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); @@ -134,12 +154,19 @@ // // textBoxNewMapName // - this.textBoxNewMapName.Location = new System.Drawing.Point(7, 32); + this.textBoxNewMapName.Location = new System.Drawing.Point(4, 68); this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.textBoxNewMapName.Name = "textBoxNewMapName"; this.textBoxNewMapName.Size = new System.Drawing.Size(203, 27); this.textBoxNewMapName.TabIndex = 13; // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.Location = new System.Drawing.Point(4, 33); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(204, 28); + this.comboBoxSelectorMap.TabIndex = 17; + // // maskedTextBoxPosition // this.maskedTextBoxPosition.Location = new System.Drawing.Point(16, 611); @@ -297,26 +324,6 @@ // this.saveFileDialog.Filter = "txt file | *.txt"; // - // buttonSortByType - // - this.buttonSortByType.Location = new System.Drawing.Point(16, 457); - this.buttonSortByType.Name = "buttonSortByType"; - this.buttonSortByType.Size = new System.Drawing.Size(198, 29); - this.buttonSortByType.TabIndex = 14; - this.buttonSortByType.Text = "Sort by type"; - this.buttonSortByType.UseVisualStyleBackColor = true; - this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click); - // - // buttonSortByColor - // - this.buttonSortByColor.Location = new System.Drawing.Point(16, 504); - this.buttonSortByColor.Name = "buttonSortByColor"; - this.buttonSortByColor.Size = new System.Drawing.Size(198, 29); - this.buttonSortByColor.TabIndex = 15; - this.buttonSortByColor.Text = "Sort by color"; - this.buttonSortByColor.UseVisualStyleBackColor = true; - this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click); - // // FormMapWithSetGasolineTanker // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); -- 2.25.1 From e8a4f802def8f17a73ff44366d8e85f8a2c0efcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Thu, 1 Dec 2022 23:43:38 +0400 Subject: [PATCH 4/6] fix --- .../GasolineTanker/SetGasolineTankerGeneric.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs index e12d64b..c782a6a 100644 --- a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs @@ -19,15 +19,7 @@ namespace GasolineTanker } public int Insert(T gasolineTanker) { - if (_places.Count < _maxCount) - { - _places.Add(gasolineTanker); - for (int i = 0; i < _places.Count; i++) - { - if (_places[i] == gasolineTanker) return i; - } - } - return -1; + return Insert(gasolineTanker, 0); } private bool isCorrectPosition(int position) { @@ -36,7 +28,7 @@ namespace GasolineTanker public int Insert(T gasolineTanker, int position) { if (_places.Contains(gasolineTanker)) - throw new ArgumentException($"Объект {gasolineTanker} уже есть в наборе"); + throw new ArgumentException($"The {gasolineTanker} object is already in the set"); if (Count == _maxCount) throw new StorageOverflowException(_maxCount); if (!isCorrectPosition(position)) -- 2.25.1 From d83fc2dc2b8dfc8e62f166d67d24673d7efa7fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Thu, 1 Dec 2022 23:49:16 +0400 Subject: [PATCH 5/6] Fix fix 2 --- GasolineTanker/GasolineTanker/Program.cs | 2 +- .../GasolineTanker/SetGasolineTankerGeneric.cs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/GasolineTanker/GasolineTanker/Program.cs b/GasolineTanker/GasolineTanker/Program.cs index 8a03804..46291d9 100644 --- a/GasolineTanker/GasolineTanker/Program.cs +++ b/GasolineTanker/GasolineTanker/Program.cs @@ -30,7 +30,7 @@ namespace GasolineTanker { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile(path: "C:\\Users\\kashi\\Desktop\\RPP\\GasolineTankerBase\\Base\\GasolineTanker\\GasolineTanker\\appSetting.json", optional: false, reloadOnChange: true) + .AddJsonFile(path: "C:\\Users\\kashi\\Desktop\\RPP\\GasolineTanker\\GasolineTanker\\GasolineTanker\\appSetting.json", optional: false, reloadOnChange: true) .Build(); var logger = new LoggerConfiguration() diff --git a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs index c782a6a..0063d66 100644 --- a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs @@ -27,15 +27,17 @@ namespace GasolineTanker } public int Insert(T gasolineTanker, int position) { - if (_places.Contains(gasolineTanker)) - throw new ArgumentException($"The {gasolineTanker} object is already in the set"); if (Count == _maxCount) throw new StorageOverflowException(_maxCount); - if (!isCorrectPosition(position)) - { + + if (position < 0 || position > Count) return -1; - } + + if (_places.Contains(gasolineTanker)) + return -1; + _places.Insert(position, gasolineTanker); + return position; } public T Remove(int position) -- 2.25.1 From c3d2d0bd4b61dc471ee88af10fbbd5d44665376f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Thu, 1 Dec 2022 23:53:48 +0400 Subject: [PATCH 6/6] Fix object --- .../GasolineTanker/DrawingObjectGasolineTanker.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs index 32be3ce..7d5dfb5 100644 --- a/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawingObjectGasolineTanker.cs @@ -57,10 +57,10 @@ namespace GasolineTanker return false; } if (entity is EntityImprovedGasolineTanker entityImprovedGasolineTanker && - otherEntity is EntityImprovedGasolineTanker otherEntityWarmlyShip && ( - entityImprovedGasolineTanker.BodyColor != otherEntityWarmlyShip.BodyColor || - entityImprovedGasolineTanker.DopColor != otherEntityWarmlyShip.DopColor || - entityImprovedGasolineTanker.BodyKit != otherEntityWarmlyShip.BodyKit)) + otherEntity is EntityImprovedGasolineTanker otherEntityWarmlyGasolineTanker && ( + entityImprovedGasolineTanker.BodyColor != otherEntityWarmlyGasolineTanker.BodyColor || + entityImprovedGasolineTanker.DopColor != otherEntityWarmlyGasolineTanker.DopColor || + entityImprovedGasolineTanker.BodyKit != otherEntityWarmlyGasolineTanker.BodyKit)) { return false; } -- 2.25.1