Komlev_S.I. Lab8 #10
@ -17,6 +17,8 @@ namespace GasolineTanker
|
||||
|
||||
public float Step => _Tanker?.Tanker?.Step ?? 0;
|
||||
|
||||
public DrawningTanker GetTanker => _Tanker;
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _Tanker?.GetCurrentPosition() ?? default;
|
||||
|
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||
this.buttonSortColor = new System.Windows.Forms.Button();
|
||||
this.buttonSortType = new System.Windows.Forms.Button();
|
||||
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||
this.buttonAddMap = new System.Windows.Forms.Button();
|
||||
this.buttonDeleteMap = new System.Windows.Forms.Button();
|
||||
@ -59,6 +61,8 @@
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.buttonSortColor);
|
||||
this.groupBoxTools.Controls.Add(this.buttonSortType);
|
||||
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemoveTanker);
|
||||
@ -77,6 +81,26 @@
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonSortColor
|
||||
//
|
||||
this.buttonSortColor.Location = new System.Drawing.Point(17, 308);
|
||||
this.buttonSortColor.Name = "buttonSortColor";
|
||||
this.buttonSortColor.Size = new System.Drawing.Size(175, 29);
|
||||
this.buttonSortColor.TabIndex = 20;
|
||||
this.buttonSortColor.Text = "Сортировать по цвету";
|
||||
this.buttonSortColor.UseVisualStyleBackColor = true;
|
||||
this.buttonSortColor.Click += new System.EventHandler(this.ButtonSortColor_Click);
|
||||
//
|
||||
// buttonSortType
|
||||
//
|
||||
this.buttonSortType.Location = new System.Drawing.Point(17, 273);
|
||||
this.buttonSortType.Name = "buttonSortType";
|
||||
this.buttonSortType.Size = new System.Drawing.Size(175, 29);
|
||||
this.buttonSortType.TabIndex = 19;
|
||||
this.buttonSortType.Text = "Сортировать по типу";
|
||||
this.buttonSortType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortType.Click += new System.EventHandler(this.ButtonSortType_Click);
|
||||
//
|
||||
// groupBoxMaps
|
||||
//
|
||||
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
|
||||
@ -143,7 +167,7 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 355);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 384);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||
@ -152,7 +176,7 @@
|
||||
//
|
||||
// buttonRemoveTanker
|
||||
//
|
||||
this.buttonRemoveTanker.Location = new System.Drawing.Point(17, 384);
|
||||
this.buttonRemoveTanker.Location = new System.Drawing.Point(17, 413);
|
||||
this.buttonRemoveTanker.Name = "buttonRemoveTanker";
|
||||
this.buttonRemoveTanker.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonRemoveTanker.TabIndex = 3;
|
||||
@ -162,7 +186,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 437);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 454);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
@ -175,7 +199,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::GasolineTanker.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(91, 558);
|
||||
this.buttonDown.Location = new System.Drawing.Point(91, 572);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 10;
|
||||
@ -187,7 +211,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::GasolineTanker.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(127, 558);
|
||||
this.buttonRight.Location = new System.Drawing.Point(127, 572);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 9;
|
||||
@ -199,7 +223,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(55, 558);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(55, 572);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 8;
|
||||
@ -211,7 +235,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::GasolineTanker.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(91, 522);
|
||||
this.buttonUp.Location = new System.Drawing.Point(91, 536);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 7;
|
||||
@ -220,7 +244,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 487);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 495);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
@ -230,7 +254,7 @@
|
||||
//
|
||||
// buttonAddTanker
|
||||
//
|
||||
this.buttonAddTanker.Location = new System.Drawing.Point(17, 314);
|
||||
this.buttonAddTanker.Location = new System.Drawing.Point(17, 343);
|
||||
this.buttonAddTanker.Name = "buttonAddTanker";
|
||||
this.buttonAddTanker.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonAddTanker.TabIndex = 1;
|
||||
@ -261,21 +285,21 @@
|
||||
this.FileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.SaveToolStripMenuItem,
|
||||
this.LoadToolStripMenuItem});
|
||||
this.FileToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
this.FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
||||
this.FileToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
|
||||
this.FileToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранение";
|
||||
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(141, 22);
|
||||
this.LoadToolStripMenuItem.Text = "Загрузка";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
@ -287,7 +311,7 @@
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormMapWithSetCars
|
||||
// FormMapWithSetTankers
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
@ -296,7 +320,7 @@
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormMapWithSetCars";
|
||||
this.Name = "FormMapWithSetTankers";
|
||||
this.Text = "Карта с набором объектов";
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
@ -335,5 +359,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortColor;
|
||||
private Button buttonSortType;
|
||||
}
|
||||
}
|
@ -256,6 +256,25 @@ namespace GasolineTanker
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new TankerCompareByType());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
private void ButtonSortColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new TankerCompareByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void menuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
|
||||
|
@ -66,7 +66,4 @@
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>258, 17</value>
|
||||
</metadata>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>387, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -130,6 +130,11 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setTankers.SortSet(comparer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -80,5 +80,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
71
GasolineTanker/GasolineTanker/TankerCompareByColor.cs
Normal file
71
GasolineTanker/GasolineTanker/TankerCompareByColor.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GasolineTanker
|
||||
{
|
||||
internal class TankerCompareByColor : IComparer<IDrawningObject>
|
||||
{
|
||||
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xTanker = x as DrawningObjectTanker;
|
||||
var yTanker = y as DrawningObjectTanker;
|
||||
if (xTanker == null && yTanker == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xTanker == null && yTanker != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xTanker != null && yTanker == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
string xTankerColor = xTanker.GetTanker.Tanker.BodyColor.Name;
|
||||
string yTankerColor = yTanker.GetTanker.Tanker.BodyColor.Name;
|
||||
if (xTankerColor != yTankerColor)
|
||||
{
|
||||
return xTankerColor.CompareTo(yTankerColor);
|
||||
}
|
||||
if (xTanker.GetTanker.GetType().Name != yTanker.GetTanker.GetType().Name)
|
||||
{
|
||||
if (xTanker.GetTanker.GetType().Name == "DrawningTanker")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (xTanker.GetTanker.Tanker is EntityGasolineTanker xGasolineTanker && yTanker.GetTanker.Tanker is EntityGasolineTanker yGasolineTanker)
|
||||
{
|
||||
string xTankerDopColor = xGasolineTanker.DopColor.Name;
|
||||
string yTankerDopColor = yGasolineTanker.DopColor.Name;
|
||||
var dopColorCompare = xTankerDopColor.CompareTo(yTankerDopColor);
|
||||
if (dopColorCompare != 0)
|
||||
{
|
||||
return dopColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = xTanker.GetTanker.Tanker.Speed.CompareTo(yTanker.GetTanker.Tanker.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xTanker.GetTanker.Tanker.Weight.CompareTo(yTanker.GetTanker.Tanker.Weight);
|
||||
}
|
||||
}
|
||||
}
|
55
GasolineTanker/GasolineTanker/TankerCompareByType.cs
Normal file
55
GasolineTanker/GasolineTanker/TankerCompareByType.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GasolineTanker
|
||||
{
|
||||
internal class TankerCompareByType : IComparer<IDrawningObject>
|
||||
{
|
||||
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xTanker = x as DrawningObjectTanker;
|
||||
var yTanker = y as DrawningObjectTanker;
|
||||
if (xTanker == null && yTanker == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xTanker == null && yTanker != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xTanker != null && yTanker == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (xTanker.GetTanker.GetType().Name != yTanker.GetTanker.GetType().Name)
|
||||
{
|
||||
if (xTanker.GetTanker.GetType().Name == "DrawningTanker")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var speedCompare = xTanker.GetTanker.Tanker.Speed.CompareTo(yTanker.GetTanker.Tanker.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xTanker.GetTanker.Tanker.Weight.CompareTo(yTanker.GetTanker.Tanker.Weight);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user