8 лаба

This commit is contained in:
10Г Егор Романов 2022-12-05 01:25:25 +04:00
parent 069691bec5
commit e85c542e3f
12 changed files with 256 additions and 76 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

View File

@ -21,7 +21,7 @@ namespace HoistingCrane
}
Pen pen = new(Color.Black, 3);
Brush dopBrush = new SolidBrush(advancedHoistingCrane.DopColor);
if (advancedHoistingCrane.Сounterweight)
if (advancedHoistingCrane.Counterweight)
{
g.DrawLine(pen, _startPosX + 15, _startPosY + 60, _startPosX + 40, _startPosY + 75);
g.DrawLine(pen, _startPosX + 15, _startPosY + 45, _startPosX + 45, _startPosY + 65);

View File

@ -8,11 +8,46 @@ namespace HoistingCrane
{
_hoistingCrane = hoistingCrane;
}
public DrawingHoistingCrane GetHoistingCrane => _hoistingCrane;
public float Step => _hoistingCrane?.HoistingCrane?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _hoistingCrane?.GetCurrentPosition() ?? default;
}
public bool Equals(IDrawingObject? other)
{
if (other == null)
{
return false;
}
var otherHoistingCrane = other as DrawingObjectHoistingCrane;
if (otherHoistingCrane == null)
{
return false;
}
var hoistingCrane = _hoistingCrane.HoistingCrane;
var otherHoistingCraneHoistingCrane = otherHoistingCrane._hoistingCrane.HoistingCrane;
if (hoistingCrane.Speed != otherHoistingCraneHoistingCrane.Speed)
{
return false;
}
if (hoistingCrane.Weight != otherHoistingCraneHoistingCrane.Weight)
{
return false;
}
if (hoistingCrane.BodyColor != otherHoistingCraneHoistingCrane.BodyColor)
{
return false;
}
var hoistingcrane = hoistingCrane as EntityAdvancedHoistingCrane;
var otherhoistingcrane = otherHoistingCraneHoistingCrane as EntityAdvancedHoistingCrane;
if (hoistingcrane == null && otherhoistingcrane == null) return true;
if (hoistingcrane == null || otherhoistingcrane == null) return false;
if (hoistingcrane.DopColor != otherhoistingcrane.DopColor) return false;
if (hoistingcrane.Counterweight != otherhoistingcrane.Counterweight) return false;
if (hoistingcrane.Crane != otherhoistingcrane.Crane) return false;
return true;
}
public void MoveObject(Direction direction)
{
_hoistingCrane?.MoveTransport(direction);

View File

@ -11,14 +11,14 @@ namespace HoistingCrane
// наличие крана
public bool Crane { get; private set; }
// наличие противовеса
public bool Сounterweight { get; private set; }
public bool Counterweight { get; private set; }
public Color DopColor { get; set; }
public EntityAdvancedHoistingCrane(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool counterWeight) :
base(speed, weight, bodyColor)
{
Crane = crane;
Сounterweight = counterWeight;
Counterweight = counterWeight;
DopColor = dopColor;
}
}

View File

@ -47,7 +47,7 @@ namespace HoistingCrane
{
return str;
}
return $"{str}{_separatorForObject}{HoistingCrane.DopColor.Name}{_separatorForObject}{HoistingCrane.Crane}{_separatorForObject}{HoistingCrane.Сounterweight}";
return $"{str}{_separatorForObject}{HoistingCrane.DopColor.Name}{_separatorForObject}{HoistingCrane.Crane}{_separatorForObject}{HoistingCrane.Counterweight}";
}
}
}

View File

@ -37,6 +37,8 @@
this.buttonAddMap = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.ButtonSortByColor = new System.Windows.Forms.Button();
this.ButtonSortByType = new System.Windows.Forms.Button();
this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemoveHoistingCrane = new System.Windows.Forms.Button();
@ -67,11 +69,11 @@
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Location = new System.Drawing.Point(13, 28);
this.groupBoxMaps.Location = new System.Drawing.Point(0, 0);
this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Size = new System.Drawing.Size(229, 326);
this.groupBoxMaps.Size = new System.Drawing.Size(213, 267);
this.groupBoxMaps.TabIndex = 11;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты";
@ -121,7 +123,6 @@
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(200, 28);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// textBoxNewMapName
//
@ -131,8 +132,30 @@
this.textBoxNewMapName.Size = new System.Drawing.Size(200, 27);
this.textBoxNewMapName.TabIndex = 0;
//
// ButtonSortByColor
//
this.ButtonSortByColor.Location = new System.Drawing.Point(7, 316);
this.ButtonSortByColor.Name = "ButtonSortByColor";
this.ButtonSortByColor.Size = new System.Drawing.Size(206, 26);
this.ButtonSortByColor.TabIndex = 7;
this.ButtonSortByColor.Text = "SortByColor";
this.ButtonSortByColor.UseVisualStyleBackColor = true;
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
//
// ButtonSortByType
//
this.ButtonSortByType.Location = new System.Drawing.Point(7, 279);
this.ButtonSortByType.Name = "ButtonSortByType";
this.ButtonSortByType.Size = new System.Drawing.Size(206, 31);
this.ButtonSortByType.TabIndex = 6;
this.ButtonSortByType.Text = "SortByType";
this.ButtonSortByType.UseVisualStyleBackColor = true;
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
//
// 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.buttonRemoveHoistingCrane);
@ -155,20 +178,20 @@
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 436);
this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 424);
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(199, 27);
this.maskedTextBoxPosition.Size = new System.Drawing.Size(206, 27);
this.maskedTextBoxPosition.TabIndex = 2;
this.maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonRemoveHoistingCrane
//
this.buttonRemoveHoistingCrane.Location = new System.Drawing.Point(20, 471);
this.buttonRemoveHoistingCrane.Location = new System.Drawing.Point(7, 471);
this.buttonRemoveHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemoveHoistingCrane.Name = "buttonRemoveHoistingCrane";
this.buttonRemoveHoistingCrane.Size = new System.Drawing.Size(199, 47);
this.buttonRemoveHoistingCrane.Size = new System.Drawing.Size(206, 47);
this.buttonRemoveHoistingCrane.TabIndex = 3;
this.buttonRemoveHoistingCrane.Text = "Удалить подъёмный кран";
this.buttonRemoveHoistingCrane.UseVisualStyleBackColor = true;
@ -176,10 +199,10 @@
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(20, 526);
this.buttonShowStorage.Location = new System.Drawing.Point(7, 526);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(199, 47);
this.buttonShowStorage.Size = new System.Drawing.Size(206, 47);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -239,10 +262,10 @@
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(21, 584);
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 584);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(198, 47);
this.buttonShowOnMap.Size = new System.Drawing.Size(206, 47);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
@ -250,10 +273,10 @@
//
// buttonAddHoistingCrane
//
this.buttonAddHoistingCrane.Location = new System.Drawing.Point(20, 381);
this.buttonAddHoistingCrane.Location = new System.Drawing.Point(7, 349);
this.buttonAddHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddHoistingCrane.Name = "buttonAddHoistingCrane";
this.buttonAddHoistingCrane.Size = new System.Drawing.Size(199, 47);
this.buttonAddHoistingCrane.Size = new System.Drawing.Size(206, 67);
this.buttonAddHoistingCrane.TabIndex = 1;
this.buttonAddHoistingCrane.Text = "Добавить подъёмный кран";
this.buttonAddHoistingCrane.UseVisualStyleBackColor = true;
@ -356,5 +379,7 @@
private System.Windows.Forms.ToolStripMenuItem loadToolStripMenuItem;
private System.Windows.Forms.OpenFileDialog openFileDialog;
private System.Windows.Forms.SaveFileDialog saveFileDialog;
private System.Windows.Forms.Button ButtonSortByColor;
private System.Windows.Forms.Button ButtonSortByType;
}
}

View File

@ -29,7 +29,6 @@ namespace HoistingCrane
/// <summary>
private readonly MapsCollection _mapsCollection;
/// <summary>
private MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap> _mapHoistingCraneCollectionGeneric;
public FormMapWithSetHoistingCrane(ILogger<FormMapWithSetHoistingCrane> logger)
{
InitializeComponent();
@ -63,29 +62,6 @@ namespace HoistingCrane
listBoxMaps.SelectedIndex = index;
}
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Вторая карта":
map = new SecondMap();
break;
}
if (map != null)
{
_mapHoistingCraneCollectionGeneric = new MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapHoistingCraneCollectionGeneric = null;
}
}
/// <summary>
/// Добавление карты
/// </summary>
@ -245,7 +221,7 @@ namespace HoistingCrane
enums = Direction.Right;
break;
}
pictureBox.Image = _mapHoistingCraneCollectionGeneric.MoveObject(enums);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(enums);
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
@ -287,5 +263,24 @@ namespace HoistingCrane
}
}
}
private void ButtonSortByType_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new HoistingCraneCompareByType());
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 HoistingCraneCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane
{
internal class HoistingCraneCompareByType : IComparer<IDrawingObject>
{
public int Compare(IDrawingObject x, IDrawingObject y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xHoistingCrane = x as DrawingObjectHoistingCrane;
var yHoistingCrane = y as DrawingObjectHoistingCrane;
if (xHoistingCrane == null && yHoistingCrane == null)
{
return 0;
}
if (xHoistingCrane == null && yHoistingCrane != null)
{
return 1;
}
if (xHoistingCrane != null && yHoistingCrane == null)
{
return -1;
}
if (xHoistingCrane.GetHoistingCrane.GetType().Name != yHoistingCrane.GetHoistingCrane.GetType().Name)
{
if (xHoistingCrane.GetHoistingCrane.GetType().Name == "DrawingHoistingCrane")
{
return -1;
}
return 1;
}
var speedCompare =
xHoistingCrane.GetHoistingCrane.HoistingCrane.Speed.CompareTo(yHoistingCrane.GetHoistingCrane.HoistingCrane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xHoistingCrane.GetHoistingCrane.HoistingCrane.Weight.CompareTo(yHoistingCrane.GetHoistingCrane.HoistingCrane.Weight);
}
}
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane
{
internal class HoistingCraneCompareByColor : IComparer<IDrawingObject>
{
public int Compare(IDrawingObject x, IDrawingObject y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xHoistingCrane = x as DrawingObjectHoistingCrane;
var yHoistingCrane = y as DrawingObjectHoistingCrane;
if (xHoistingCrane == null && yHoistingCrane == null)
{
return 0;
}
if (xHoistingCrane == null && yHoistingCrane != null)
{
return 1;
}
if (xHoistingCrane != null && yHoistingCrane == null)
{
return -1;
}
int colorCompare = string.Compare(xHoistingCrane.GetHoistingCrane.HoistingCrane.BodyColor.Name, yHoistingCrane.GetHoistingCrane.HoistingCrane.BodyColor.Name);
if (colorCompare != 0)
{
return colorCompare;
}
var speedCompare = xHoistingCrane.GetHoistingCrane.HoistingCrane.Speed.CompareTo(yHoistingCrane.GetHoistingCrane.HoistingCrane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xHoistingCrane.GetHoistingCrane.HoistingCrane.Weight.CompareTo(yHoistingCrane.GetHoistingCrane.HoistingCrane.Weight);
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace HoistingCrane
{
internal interface IDrawingObject
internal interface IDrawingObject : IEquatable<IDrawingObject>
{
public float Step { get; }
void SetObject(int x, int y, int width, int height);

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace HoistingCrane
{
internal class MapWithSetHoistingCraneGeneric<T, U>
where T : class, IDrawingObject
where T : class, IDrawingObject, IEquatable<T>
where U : AbstractMap
{
private readonly int _pictureWidth;
@ -140,5 +140,13 @@ namespace HoistingCrane
_setHoistingCranes.Insert(DrawingObjectHoistingCrane.Create(rec) as T);
}
}
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer"></param>
public void Sort(IComparer<T> comparer)
{
_setHoistingCranes.SortSet(comparer);
}
}
}

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace HoistingCrane
{
internal class SetHoistingCraneGeneric<T>
where T : class
where T : class, IEquatable<T>
{
private readonly List<T> _places;
public int Count => _places.Count;
@ -19,6 +19,7 @@ namespace HoistingCrane
}
public int Insert(T hoistingCrane)
{
if (_places.Contains(hoistingCrane)) return -1;
for (int i = 0; i < _maxCount; i++)
{
if (i == Count)
@ -95,5 +96,13 @@ namespace HoistingCrane
}
}
}
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
}
}