PIbd22_Kuznetsov.A.V._lab8
This commit is contained in:
parent
3cd45efd33
commit
0014705a2f
@ -10,11 +10,11 @@ namespace Excavator.Drawing
|
||||
{
|
||||
public class DrawingExcavator : DrawingMash
|
||||
{
|
||||
public DrawingExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool buket, bool supports, int width, int height) : base(speed, weight, bodyColor, width, height, 180, 110)
|
||||
public DrawingExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool supports, int width, int height) : base(speed, weight, bodyColor, width, height, 180, 110)
|
||||
{
|
||||
if (EntityMash != null)
|
||||
{
|
||||
EntityMash = new EntityExcavator(speed, weight, bodyColor, additionalColor, buket, supports);
|
||||
EntityMash = new EntityExcavator(speed, weight, bodyColor, additionalColor, bucket, supports);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ namespace Excavator.Drawing
|
||||
public int GetHeight => _mashHeight;
|
||||
public DrawingMash(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
|
||||
if (width < _mashWidth || height < _mashHeight)
|
||||
{
|
||||
return;
|
||||
@ -36,7 +35,6 @@ namespace Excavator.Drawing
|
||||
}
|
||||
protected DrawingMash(int speed, double weight, Color bodyColor, int width, int height, int mashWidth, int mashHeight)
|
||||
{
|
||||
|
||||
if (width < _mashWidth || height < _mashHeight)
|
||||
{
|
||||
return;
|
||||
@ -123,8 +121,7 @@ namespace Excavator.Drawing
|
||||
g.DrawLine(blackPen, _startPosX + 27, _startPosY + 69, _startPosX + 165, _startPosY + 69);
|
||||
g.DrawLine(blackPen, _startPosX + 27, _startPosY + 99, _startPosX + 165, _startPosY + 99);
|
||||
}
|
||||
|
||||
public bool CanMove(DirectionType direction)
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityMash == null)
|
||||
{
|
||||
|
@ -13,10 +13,10 @@ namespace Excavator.Entities
|
||||
public bool IsBucket { get; private set; }
|
||||
public bool IsSupports { get; private set; }
|
||||
|
||||
public EntityExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool buket, bool supports) : base(speed, weight, bodyColor)
|
||||
public EntityExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool supports) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AddColor = additionalColor;
|
||||
IsBucket = buket;
|
||||
IsBucket = bucket;
|
||||
IsSupports = supports;
|
||||
}
|
||||
|
||||
|
82
Excavator/FormExcavatorCollection.Designer.cs
generated
82
Excavator/FormExcavatorCollection.Designer.cs
generated
@ -28,11 +28,11 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonAddBus = new System.Windows.Forms.Button();
|
||||
this.buttonAddMash = new System.Windows.Forms.Button();
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.labelInstruments = new System.Windows.Forms.Label();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
this.buttonDeleteBus = new System.Windows.Forms.Button();
|
||||
this.buttonDeleteMash = new System.Windows.Forms.Button();
|
||||
this.colorDialog = new System.Windows.Forms.ColorDialog();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
@ -46,21 +46,23 @@
|
||||
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.Sort_color_button = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonAddBus
|
||||
// buttonAddMash
|
||||
//
|
||||
this.buttonAddBus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonAddBus.Location = new System.Drawing.Point(982, 441);
|
||||
this.buttonAddBus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonAddBus.Name = "buttonAddBus";
|
||||
this.buttonAddBus.Size = new System.Drawing.Size(135, 37);
|
||||
this.buttonAddBus.TabIndex = 0;
|
||||
this.buttonAddBus.Text = "Добавить автобус";
|
||||
this.buttonAddBus.UseVisualStyleBackColor = true;
|
||||
this.buttonAddBus.Click += new System.EventHandler(this.buttonAddMash_Click);
|
||||
this.buttonAddMash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonAddMash.Location = new System.Drawing.Point(982, 441);
|
||||
this.buttonAddMash.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonAddMash.Name = "buttonAddMash";
|
||||
this.buttonAddMash.Size = new System.Drawing.Size(135, 37);
|
||||
this.buttonAddMash.TabIndex = 0;
|
||||
this.buttonAddMash.Text = "Добавить автобус";
|
||||
this.buttonAddMash.UseVisualStyleBackColor = true;
|
||||
this.buttonAddMash.Click += new System.EventHandler(this.buttonAddMash_Click);
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
@ -94,17 +96,17 @@
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
|
||||
//
|
||||
// buttonDeleteBus
|
||||
// buttonDeleteMash
|
||||
//
|
||||
this.buttonDeleteBus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDeleteBus.Location = new System.Drawing.Point(982, 525);
|
||||
this.buttonDeleteBus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDeleteBus.Name = "buttonDeleteBus";
|
||||
this.buttonDeleteBus.Size = new System.Drawing.Size(135, 37);
|
||||
this.buttonDeleteBus.TabIndex = 4;
|
||||
this.buttonDeleteBus.Text = "Удалить";
|
||||
this.buttonDeleteBus.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteBus.Click += new System.EventHandler(this.buttonDeleteMash_Click);
|
||||
this.buttonDeleteMash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDeleteMash.Location = new System.Drawing.Point(982, 525);
|
||||
this.buttonDeleteMash.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDeleteMash.Name = "buttonDeleteMash";
|
||||
this.buttonDeleteMash.Size = new System.Drawing.Size(135, 37);
|
||||
this.buttonDeleteMash.TabIndex = 4;
|
||||
this.buttonDeleteMash.Text = "Удалить";
|
||||
this.buttonDeleteMash.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteMash.Click += new System.EventHandler(this.buttonDeleteMash_Click);
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
@ -133,7 +135,7 @@
|
||||
this.listBoxStorages.ItemHeight = 20;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(971, 213);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(150, 144);
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(150, 44);
|
||||
this.listBoxStorages.TabIndex = 8;
|
||||
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged);
|
||||
//
|
||||
@ -208,19 +210,43 @@
|
||||
this.openFileDialog.FileName = "openFileDialog1";
|
||||
this.openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(966, 265);
|
||||
this.button1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(164, 31);
|
||||
this.button1.TabIndex = 13;
|
||||
this.button1.Text = "Сортировка по типу";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.buttonSortByType_Click);
|
||||
//
|
||||
// Sort_color_button
|
||||
//
|
||||
this.Sort_color_button.Location = new System.Drawing.Point(966, 304);
|
||||
this.Sort_color_button.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Sort_color_button.Name = "Sort_color_button";
|
||||
this.Sort_color_button.Size = new System.Drawing.Size(165, 31);
|
||||
this.Sort_color_button.TabIndex = 14;
|
||||
this.Sort_color_button.Text = "Сортировка по цвету";
|
||||
this.Sort_color_button.UseVisualStyleBackColor = true;
|
||||
this.Sort_color_button.Click += new System.EventHandler(this.Sort_Color_button_Click);
|
||||
//
|
||||
// FormExcavatorCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1146, 672);
|
||||
this.Controls.Add(this.Sort_color_button);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.textBoxStorageName);
|
||||
this.Controls.Add(this.buttonDeleteStorage);
|
||||
this.Controls.Add(this.buttonAddStorage);
|
||||
this.Controls.Add(this.listBoxStorages);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.buttonAddBus);
|
||||
this.Controls.Add(this.buttonAddMash);
|
||||
this.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.Controls.Add(this.buttonDeleteBus);
|
||||
this.Controls.Add(this.buttonDeleteMash);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.labelInstruments);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
@ -239,11 +265,11 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonAddBus;
|
||||
private Button buttonAddMash;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Label labelInstruments;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonDeleteBus;
|
||||
private Button buttonDeleteMash;
|
||||
private ColorDialog colorDialog;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Label label1;
|
||||
@ -257,5 +283,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button button1;
|
||||
private Button Sort_color_button;
|
||||
}
|
||||
}
|
@ -12,8 +12,7 @@ using Excavator.Drawing;
|
||||
using Excavator.Move_Strategy;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Excavator.Exceptions;
|
||||
|
||||
|
||||
using Excavator.Generics;
|
||||
|
||||
namespace Excavator
|
||||
{
|
||||
@ -27,13 +26,31 @@ namespace Excavator
|
||||
_storage = new MashsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private void buttonSortByType_Click(object sender, EventArgs e) => CompareMash(new MashCompareByType());
|
||||
|
||||
private void Sort_Color_button_Click(object sender, EventArgs e) => CompareMash(new MashCompareByColor());
|
||||
private void CompareMash(IComparer<DrawingMash?> comparer)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowMash();
|
||||
}
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
listBoxStorages.Items.Add(_storage.Keys[i].Name);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||
{
|
||||
@ -82,7 +99,7 @@ namespace Excavator
|
||||
FormMashConfig.Show();
|
||||
}
|
||||
|
||||
private void AddMash(DrawingMash SelectedMash)
|
||||
private void AddMash(DrawingMash selectedMash)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
@ -94,14 +111,14 @@ namespace Excavator
|
||||
{
|
||||
return;
|
||||
}
|
||||
SelectedMash.ChangeBordersPicture(Width, Height);
|
||||
selectedMash.ChangeBordersPicture(Width, Height);
|
||||
try
|
||||
{
|
||||
if (obj + SelectedMash != -1)
|
||||
if (obj + selectedMash != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowMash();
|
||||
_logger.LogInformation($"Добавлен объект: {SelectedMash.EntityMash.BodyColor}");
|
||||
_logger.LogInformation($"Добавлен объект: {selectedMash.EntityMash.BodyColor}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -113,7 +130,13 @@ namespace Excavator
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDeleteMash_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
@ -168,7 +191,6 @@ namespace Excavator
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowMash();
|
||||
}
|
||||
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
|
@ -14,6 +14,7 @@ namespace Excavator
|
||||
{
|
||||
public partial class FormMashConfig : Form
|
||||
{
|
||||
|
||||
DrawingMash? _mash = null;
|
||||
private event Action<DrawingMash>? EventAddMash;
|
||||
public FormMashConfig()
|
||||
@ -88,6 +89,7 @@ namespace Excavator
|
||||
}
|
||||
DrawMash();
|
||||
}
|
||||
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
||||
|
55
Excavator/Generic/DrawingMashEqutables.cs
Normal file
55
Excavator/Generic/DrawingMashEqutables.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Excavator.Drawing;
|
||||
using Excavator.Entities;
|
||||
|
||||
namespace Excavator.Generics
|
||||
{
|
||||
internal class DrawingMashEqutables : IEqualityComparer<DrawingMash?>
|
||||
{
|
||||
public bool Equals(DrawingMash? x, DrawingMash? y)
|
||||
{
|
||||
if (x == null && x.EntityMash == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
|
||||
if (y == null && y.EntityMash == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
|
||||
if ((x.GetType().Name != y.GetType().Name))
|
||||
return false;
|
||||
|
||||
if (x.EntityMash.Speed != y.EntityMash.Speed)
|
||||
return false;
|
||||
|
||||
if (x.EntityMash.Weight != y.EntityMash.Weight)
|
||||
return false;
|
||||
|
||||
if (x.EntityMash.BodyColor != y.EntityMash.BodyColor)
|
||||
return false;
|
||||
|
||||
if (x is DrawingExcavator && y is DrawingExcavator)
|
||||
{
|
||||
var xExcavator = (EntityExcavator)x.EntityMash;
|
||||
var yExcavator = (EntityExcavator)y.EntityMash;
|
||||
|
||||
if (xExcavator.AddColor != yExcavator.AddColor)
|
||||
return false;
|
||||
|
||||
if (xExcavator.IsBucket != yExcavator.IsBucket)
|
||||
return false;
|
||||
|
||||
if (xExcavator.IsSupports != yExcavator.IsSupports)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawingMash? obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
27
Excavator/Generic/MashCollectionInfo.cs
Normal file
27
Excavator/Generic/MashCollectionInfo.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Excavator.Generics
|
||||
{
|
||||
internal class MashCollectionInfo : IEquatable<MashCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public MashCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(MashCollectionInfo? other)
|
||||
{
|
||||
if (ReferenceEquals(other, null))
|
||||
return false;
|
||||
|
||||
return Name.Equals(other.Name);
|
||||
}
|
||||
public override int GetHashCode() => Name.GetHashCode();
|
||||
}
|
||||
}
|
34
Excavator/Generic/MashCompareByColor.cs
Normal file
34
Excavator/Generic/MashCompareByColor.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Excavator.Drawing;
|
||||
using Excavator.Entities;
|
||||
|
||||
namespace Excavator.Generics
|
||||
{
|
||||
internal class MashCompareByColor : IComparer<DrawingMash>
|
||||
{
|
||||
public int Compare(DrawingMash? x, DrawingMash? y)
|
||||
{
|
||||
if (x == null || x.EntityMash == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
|
||||
if (y == null || y.EntityMash == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
|
||||
var xMash = x.EntityMash;
|
||||
var yMash = y.EntityMash;
|
||||
|
||||
if (xMash.BodyColor != yMash.BodyColor)
|
||||
return xMash.BodyColor.Name.CompareTo(yMash.BodyColor.Name);
|
||||
|
||||
var speedCompare = x.EntityMash.Speed.CompareTo(y.EntityMash.Speed);
|
||||
if (speedCompare != 0)
|
||||
return speedCompare;
|
||||
|
||||
return x.EntityMash.Weight.CompareTo(y.EntityMash.Weight);
|
||||
}
|
||||
}
|
||||
}
|
30
Excavator/Generic/MashCompareByType.cs
Normal file
30
Excavator/Generic/MashCompareByType.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Excavator.Drawing;
|
||||
|
||||
namespace Excavator.Generics
|
||||
{
|
||||
internal class MashCompareByType : IComparer<DrawingMash>
|
||||
{
|
||||
public int Compare(DrawingMash? x, DrawingMash? y)
|
||||
{
|
||||
if (x == null || x.EntityMash == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
|
||||
if (y == null || y.EntityMash == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
|
||||
var speedCompare = x.EntityMash.Speed.CompareTo(y.EntityMash.Speed);
|
||||
if (speedCompare != 0)
|
||||
return speedCompare;
|
||||
|
||||
return x.EntityMash.Weight.CompareTo(y.EntityMash.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Excavator.Drawing;
|
||||
using Excavator.Generics;
|
||||
using Excavator.Move_Strategy;
|
||||
|
||||
namespace Excavator.Generic
|
||||
@ -27,13 +28,16 @@ namespace Excavator.Generic
|
||||
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
|
||||
public static int operator +(MashGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Insert(obj);
|
||||
return collect._collection.Insert(obj, new DrawingMashEqutables());
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
public static bool operator -(MashGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
@ -45,7 +49,6 @@ namespace Excavator.Generic
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetMash => _collection.GetMash();
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
|
@ -3,15 +3,17 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Excavator.Generics;
|
||||
using Excavator.Drawing;
|
||||
using Excavator.Generics;
|
||||
using Excavator.Move_Strategy;
|
||||
|
||||
namespace Excavator.Generic
|
||||
{
|
||||
internal class MashsGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, MashGenericCollection<DrawingMash, DrawingObjectMash>> _mashStorages;
|
||||
public List<string> Keys => _mashStorages.Keys.ToList();
|
||||
readonly Dictionary<MashCollectionInfo, MashGenericCollection<DrawingMash, DrawingObjectMash>> _mashStorages;
|
||||
public List<MashCollectionInfo> Keys => _mashStorages.Keys.ToList();
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
@ -20,38 +22,39 @@ namespace Excavator.Generic
|
||||
|
||||
public MashsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mashStorages = new Dictionary<string, MashGenericCollection<DrawingMash, DrawingObjectMash>>();
|
||||
_mashStorages = new Dictionary<MashCollectionInfo, MashGenericCollection<DrawingMash, DrawingObjectMash>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
public void AddSet(string name)
|
||||
{
|
||||
foreach (string nameStorage in Keys)
|
||||
{
|
||||
if (nameStorage == name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
_mashStorages.Add(name, new MashGenericCollection<DrawingMash, DrawingObjectMash>(_pictureWidth, _pictureHeight));
|
||||
MashCollectionInfo set = new MashCollectionInfo(name, string.Empty);
|
||||
|
||||
if (_mashStorages.ContainsKey(set))
|
||||
return;
|
||||
|
||||
_mashStorages.Add(set, new MashGenericCollection<DrawingMash, DrawingObjectMash>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_mashStorages.ContainsKey(name))
|
||||
{
|
||||
_mashStorages.Remove(name);
|
||||
}
|
||||
MashCollectionInfo set = new MashCollectionInfo(name, string.Empty);
|
||||
if (!_mashStorages.ContainsKey(set))
|
||||
return;
|
||||
|
||||
_mashStorages.Remove(set);
|
||||
|
||||
}
|
||||
public MashGenericCollection<DrawingMash, DrawingObjectMash>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mashStorages.ContainsKey(ind))
|
||||
MashCollectionInfo set = new MashCollectionInfo(ind, string.Empty);
|
||||
|
||||
if (!_mashStorages.ContainsKey(set))
|
||||
{
|
||||
return _mashStorages[ind];
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return _mashStorages[set];
|
||||
}
|
||||
}
|
||||
public void SaveData(string filename)
|
||||
@ -61,7 +64,7 @@ namespace Excavator.Generic
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string,
|
||||
foreach (KeyValuePair<MashCollectionInfo,
|
||||
MashGenericCollection<DrawingMash, DrawingObjectMash>> record in _mashStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
@ -103,7 +106,7 @@ namespace Excavator.Generic
|
||||
{
|
||||
throw new Exception("Нет данных для загрузки");
|
||||
}
|
||||
if (!strs[0].StartsWith("BusStorage"))
|
||||
if (!strs[0].StartsWith("MashStorage"))
|
||||
{
|
||||
throw new Exception("Неверный формат данных");
|
||||
}
|
||||
@ -132,7 +135,7 @@ namespace Excavator.Generic
|
||||
}
|
||||
}
|
||||
}
|
||||
_mashStorages.Add(record[0], collection);
|
||||
_mashStorages.Add(new MashCollectionInfo(record[0], string.Empty), collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Excavator.Generic
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
@ -18,11 +19,13 @@ namespace Excavator.Generic
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
public int Insert(T bus)
|
||||
public int Insert(T mash, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
return Insert(bus, 0);
|
||||
return Insert(mash, 0, equal);
|
||||
}
|
||||
public int Insert(T mash, int position)
|
||||
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
public int Insert(T mash, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (Count >= _maxCount)
|
||||
{
|
||||
@ -32,6 +35,10 @@ namespace Excavator.Generic
|
||||
{
|
||||
throw new IndexOutOfRangeException("Индекс вне границ коллекции");
|
||||
}
|
||||
if (equal != null && _places.Contains(mash, equal))
|
||||
{
|
||||
throw new ArgumentException("Данный объект уже есть в коллекции");
|
||||
}
|
||||
_places.Insert(position, mash);
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ using System.Threading.Tasks;
|
||||
using Excavator.Entities;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
|
||||
|
||||
namespace Excavator.Move_Strategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
|
Loading…
Reference in New Issue
Block a user