This commit is contained in:
Кашин Максим 2022-11-29 21:29:56 +04:00
parent d628bda63b
commit eb5bbe7f69
8 changed files with 234 additions and 83 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace GasolineTanker namespace GasolineTanker
{ {
internal abstract class AbstractMap internal abstract class AbstractMap : IEquatable<AbstractMap>
{ {
private IDrawingObject _drawningObject = null; private IDrawingObject _drawningObject = null;
protected int[,] _map = null; protected int[,] _map = null;
@ -143,6 +143,33 @@ namespace GasolineTanker
return bmp; 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 GenerateMap();
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);

View File

@ -15,6 +15,8 @@ namespace GasolineTanker
_gasolineTanker = gasolineTanker; _gasolineTanker = gasolineTanker;
} }
public DrawingGasolineTanker GetGasolineTanker => _gasolineTanker;
public float Step => _gasolineTanker?.GasolineTanker?.Step ?? 0; public float Step => _gasolineTanker?.GasolineTanker?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
@ -45,8 +47,8 @@ namespace GasolineTanker
{ {
return false; return false;
} }
var entity = ; var entity = _gasolineTanker.GasolineTanker;
var otherEntity = otherGasolineTanker.; var otherEntity = otherGasolineTanker._gasolineTanker.GasolineTanker;
if (entity.GetType() != otherEntity.GetType() || if (entity.GetType() != otherEntity.GetType() ||
entity.Speed != otherEntity.Speed || entity.Speed != otherEntity.Speed ||
entity.Weight != otherEntity.Weight || entity.Weight != otherEntity.Weight ||
@ -66,4 +68,3 @@ namespace GasolineTanker
} }
} }
} }
}

View File

@ -51,6 +51,8 @@
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); 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.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout(); this.groupBoxMaps.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.groupBoxMaps); this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.keyRight); this.groupBoxTools.Controls.Add(this.keyRight);
@ -70,9 +74,11 @@
this.groupBoxTools.Controls.Add(this.buttonRemoveGasolineTanker); this.groupBoxTools.Controls.Add(this.buttonRemoveGasolineTanker);
this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker); this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; 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.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.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools"; this.groupBoxTools.Text = "Tools";
@ -84,18 +90,21 @@
this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); 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.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.TabIndex = 13;
this.groupBoxMaps.TabStop = false; this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Maps"; this.groupBoxMaps.Text = "Maps";
// //
// buttonDeleteMap // 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.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.TabIndex = 16;
this.buttonDeleteMap.Text = "Delete Map"; this.buttonDeleteMap.Text = "Delete Map";
this.buttonDeleteMap.UseVisualStyleBackColor = true; this.buttonDeleteMap.UseVisualStyleBackColor = true;
@ -104,18 +113,20 @@
// listBoxMaps // listBoxMaps
// //
this.listBoxMaps.FormattingEnabled = true; this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 15; this.listBoxMaps.ItemHeight = 20;
this.listBoxMaps.Location = new System.Drawing.Point(6, 141); 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.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.TabIndex = 15;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged); this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
// //
// buttonAddMap // 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.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.TabIndex = 14;
this.buttonAddMap.Text = "Add Map"; this.buttonAddMap.Text = "Add Map";
this.buttonAddMap.UseVisualStyleBackColor = true; this.buttonAddMap.UseVisualStyleBackColor = true;
@ -123,30 +134,19 @@
// //
// textBoxNewMapName // 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.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(178, 23); this.textBoxNewMapName.Size = new System.Drawing.Size(203, 27);
this.textBoxNewMapName.TabIndex = 13; 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 // 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.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; 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; this.maskedTextBoxPosition.TabIndex = 11;
// //
// keyRight // keyRight
@ -154,9 +154,10 @@
this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight;
this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.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.TabIndex = 10;
this.keyRight.UseVisualStyleBackColor = true; this.keyRight.UseVisualStyleBackColor = true;
this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); 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.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.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft;
this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.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.TabIndex = 9;
this.keyLeft.UseVisualStyleBackColor = true; this.keyLeft.UseVisualStyleBackColor = true;
this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); 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.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.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp;
this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.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.TabIndex = 8;
this.keyUp.UseVisualStyleBackColor = true; this.keyUp.UseVisualStyleBackColor = true;
this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); 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.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.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown;
this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 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.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.TabIndex = 7;
this.keyDown.UseVisualStyleBackColor = true; this.keyDown.UseVisualStyleBackColor = true;
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonShowOnMap // 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.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.TabIndex = 4;
this.buttonShowOnMap.Text = "Show on map"; this.buttonShowOnMap.Text = "Show on map";
this.buttonShowOnMap.UseVisualStyleBackColor = true; this.buttonShowOnMap.UseVisualStyleBackColor = true;
@ -209,9 +214,10 @@
// //
// buttonShowStorage // 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.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.TabIndex = 3;
this.buttonShowStorage.Text = "Show storage"; this.buttonShowStorage.Text = "Show storage";
this.buttonShowStorage.UseVisualStyleBackColor = true; this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -219,9 +225,10 @@
// //
// buttonRemoveGasolineTanker // 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.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.TabIndex = 2;
this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker"; this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker";
this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true; this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true;
@ -229,9 +236,10 @@
// //
// buttonAddGasolineTanker // 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.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.TabIndex = 1;
this.buttonAddGasolineTanker.Text = "Add gasoline tanker"; this.buttonAddGasolineTanker.Text = "Add gasoline tanker";
this.buttonAddGasolineTanker.UseVisualStyleBackColor = true; this.buttonAddGasolineTanker.UseVisualStyleBackColor = true;
@ -240,19 +248,22 @@
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; 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.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.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
// menuStrip // menuStrip
// //
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem}); this.fileToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip"; 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; this.menuStrip.TabIndex = 2;
// //
// fileToolStripMenuItem // fileToolStripMenuItem
@ -261,20 +272,20 @@
this.SaveToolStripMenuItem, this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem}); this.LoadToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; 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"; this.fileToolStripMenuItem.Text = "File";
// //
// SaveToolStripMenuItem // SaveToolStripMenuItem
// //
this.SaveToolStripMenuItem.Name = "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.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(180, 22); 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);
// //
@ -286,15 +297,36 @@
// //
this.saveFileDialog.Filter = "txt file | *.txt"; 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 // 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.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.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.menuStrip); this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip; this.MainMenuStrip = this.menuStrip;
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMapWithSetGasolineTanker"; this.Name = "FormMapWithSetGasolineTanker";
this.Text = "FormMapWithSetGasolineTanker"; this.Text = "FormMapWithSetGasolineTanker";
this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.ResumeLayout(false);
@ -334,5 +366,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;
} }
} }

View File

@ -17,7 +17,6 @@ namespace GasolineTanker
{ "Simple map", new SimpleMap() }, { "Simple map", new SimpleMap() },
{ "Long map", new LongMap() } { "Long map", new LongMap() }
}; };
private MapWithSetGasolienTankerGeneric<DrawingObjectGasolineTanker, AbstractMap> _mapGasolineTankerCollectionGeneric;
private readonly MapsCollection _mapsCollection; private readonly MapsCollection _mapsCollection;
private readonly ILogger _logger; private readonly ILogger _logger;
public FormMapWithSetGasolineTanker(ILogger<FormMapWithSetGasolineTanker> logger) public FormMapWithSetGasolineTanker(ILogger<FormMapWithSetGasolineTanker> logger)
@ -106,6 +105,7 @@ namespace GasolineTanker
_logger.LogWarning($"Storage full error: {ex.Message}"); _logger.LogWarning($"Storage full error: {ex.Message}");
MessageBox.Show($"Storage full error: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show($"Storage full error: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void ButtonShowStorage_Click(object sender, EventArgs e) private void ButtonShowStorage_Click(object sender, EventArgs e)
@ -114,7 +114,7 @@ namespace GasolineTanker
{ {
return; return;
} }
pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
@ -148,30 +148,9 @@ namespace GasolineTanker
dir = Direction.Right; dir = Direction.Right;
break; break;
} }
pictureBox.Image = _mapGasolineTankerCollectionGeneric.MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].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<DrawingObjectGasolineTanker, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapGasolineTankerCollectionGeneric = null;
}
} }
private void buttonAddMap_Click(object sender, EventArgs e) private void buttonAddMap_Click(object sender, EventArgs e)
{ {
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
@ -287,5 +266,18 @@ namespace GasolineTanker
} }
} }
} }
private void SortBy(IComparer<IDrawingObject> 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());
} }
} }

View File

@ -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<IDrawingObject>
{
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());
}
}
}

View File

@ -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<IDrawingObject>
{
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);
}
}
}

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace GasolineTanker namespace GasolineTanker
{ {
internal class MapWithSetGasolienTankerGeneric<T, U> internal class MapWithSetGasolienTankerGeneric<T, U>
where T : class, IDrawingObject where T : class, IEquatable<T>, IDrawingObject
where U : AbstractMap where U : AbstractMap
{ {
private readonly int _pictureWidth; private readonly int _pictureWidth;
@ -134,5 +134,9 @@ namespace GasolineTanker
i++; i++;
} }
} }
public void Sort(IComparer<T> comparer)
{
_setGasolineTanker.SortSet(comparer);
}
} }
} }

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace GasolineTanker namespace GasolineTanker
{ {
internal class SetGasolineTankerGeneric<T> internal class SetGasolineTankerGeneric<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;
@ -35,6 +35,8 @@ namespace GasolineTanker
} }
public int Insert(T gasolineTanker, int position) public int Insert(T gasolineTanker, int position)
{ {
if (_places.Contains(gasolineTanker))
throw new ArgumentException($"Объект {gasolineTanker} уже есть в наборе");
if (Count == _maxCount) if (Count == _maxCount)
throw new StorageOverflowException(_maxCount); throw new StorageOverflowException(_maxCount);
if (!isCorrectPosition(position)) if (!isCorrectPosition(position))
@ -81,5 +83,13 @@ namespace GasolineTanker
} }
} }
} }
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
} }
} }