diff --git a/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs b/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs index 10e953b..b69fb29 100644 --- a/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs +++ b/GasolineTanker/ProjectGasolineTanker/Drawings/DrawingTruck.cs @@ -19,7 +19,7 @@ namespace ProjectGasolineTanker.Drawings private int _pictureWidth; private int _pictureHeight; - + protected int _startPosX; protected int _startPosY; diff --git a/GasolineTanker/ProjectGasolineTanker/Drawings/ExtentionDrawingTruck.cs b/GasolineTanker/ProjectGasolineTanker/Drawings/ExtentionDrawingTruck.cs index 80ecc97..b760250 100644 --- a/GasolineTanker/ProjectGasolineTanker/Drawings/ExtentionDrawingTruck.cs +++ b/GasolineTanker/ProjectGasolineTanker/Drawings/ExtentionDrawingTruck.cs @@ -46,5 +46,5 @@ namespace ProjectGasolineTanker.Drawings } return $"{str}{separatorForObject}{GasolineTanker.Add_Color.Name}{separatorForObject}{GasolineTanker.IsTank}{separatorForObject}{GasolineTanker.IsWheel}"; } - } + } } diff --git a/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs b/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs index 6792740..c6d24cd 100644 --- a/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs +++ b/GasolineTanker/ProjectGasolineTanker/Entities/EntityTruck.cs @@ -9,9 +9,9 @@ namespace ProjectGasolineTanker.Entities public class EntityTruck { - + public int Speed { get; private set; } - + public double Weight { get; private set; } public Color BodyColor { get; private set; } diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs index 75d235a..889992d 100644 --- a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.Designer.cs @@ -46,6 +46,8 @@ this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.sort_type_button = 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(); @@ -53,7 +55,7 @@ // buttonAddTruck // this.buttonAddTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonAddTruck.Location = new System.Drawing.Point(642, 315); + this.buttonAddTruck.Location = new System.Drawing.Point(660, 315); this.buttonAddTruck.Name = "buttonAddTruck"; this.buttonAddTruck.Size = new System.Drawing.Size(137, 28); this.buttonAddTruck.TabIndex = 0; @@ -74,7 +76,7 @@ this.labelInstruments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.labelInstruments.AutoSize = true; this.labelInstruments.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.labelInstruments.Location = new System.Drawing.Point(659, 9); + this.labelInstruments.Location = new System.Drawing.Point(677, 9); this.labelInstruments.Name = "labelInstruments"; this.labelInstruments.Size = new System.Drawing.Size(108, 21); this.labelInstruments.TabIndex = 2; @@ -83,7 +85,7 @@ // buttonUpdate // this.buttonUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUpdate.Location = new System.Drawing.Point(648, 129); + this.buttonUpdate.Location = new System.Drawing.Point(666, 129); this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Size = new System.Drawing.Size(131, 25); this.buttonUpdate.TabIndex = 3; @@ -94,7 +96,7 @@ // buttonDeleteTruck // this.buttonDeleteTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDeleteTruck.Location = new System.Drawing.Point(642, 403); + this.buttonDeleteTruck.Location = new System.Drawing.Point(660, 403); this.buttonDeleteTruck.Name = "buttonDeleteTruck"; this.buttonDeleteTruck.Size = new System.Drawing.Size(137, 28); this.buttonDeleteTruck.TabIndex = 4; @@ -105,7 +107,7 @@ // maskedTextBoxNumber // this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.maskedTextBoxNumber.Location = new System.Drawing.Point(642, 360); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(660, 360); this.maskedTextBoxNumber.Mask = "00"; this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; this.maskedTextBoxNumber.Size = new System.Drawing.Size(138, 23); @@ -116,7 +118,7 @@ // this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(648, 47); + this.label1.Location = new System.Drawing.Point(666, 47); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(52, 15); this.label1.TabIndex = 7; @@ -129,7 +131,7 @@ this.listBoxStorages.Location = new System.Drawing.Point(648, 157); this.listBoxStorages.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.listBoxStorages.Name = "listBoxStorages"; - this.listBoxStorages.Size = new System.Drawing.Size(132, 109); + this.listBoxStorages.Size = new System.Drawing.Size(132, 49); this.listBoxStorages.TabIndex = 8; this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged); // @@ -169,7 +171,7 @@ this.toolStripMenuItem1}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(797, 24); + this.menuStrip.Size = new System.Drawing.Size(815, 24); this.menuStrip.TabIndex = 12; this.menuStrip.Text = "menuStrip1"; // @@ -185,14 +187,14 @@ // saveToolStripMenuItem // this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.saveToolStripMenuItem.Size = new System.Drawing.Size(133, 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(133, 22); this.loadToolStripMenuItem.Text = "Загрузить"; this.loadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); // @@ -205,11 +207,33 @@ this.openFileDialog.FileName = "openFileDialog1"; this.openFileDialog.Filter = "txt file | *.txt"; // + // sort_type_button + // + this.sort_type_button.Location = new System.Drawing.Point(649, 213); + this.sort_type_button.Name = "sort_type_button"; + this.sort_type_button.Size = new System.Drawing.Size(130, 23); + this.sort_type_button.TabIndex = 13; + this.sort_type_button.Text = "Сортировка по типу"; + this.sort_type_button.UseVisualStyleBackColor = true; + this.sort_type_button.Click += new System.EventHandler(this.buttonSortByType_Click); + // + // sort_color_button + // + this.sort_color_button.Location = new System.Drawing.Point(649, 242); + this.sort_color_button.Name = "sort_color_button"; + this.sort_color_button.Size = new System.Drawing.Size(131, 23); + 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); + // // FormTruckCollection // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(797, 465); + this.ClientSize = new System.Drawing.Size(815, 465); + this.Controls.Add(this.sort_color_button); + this.Controls.Add(this.sort_type_button); this.Controls.Add(this.textBoxStorageName); this.Controls.Add(this.buttonDeleteStorage); this.Controls.Add(this.buttonAddStorage); @@ -253,5 +277,7 @@ private ToolStripMenuItem loadToolStripMenuItem; private SaveFileDialog saveFileDialog; private OpenFileDialog openFileDialog; + private Button sort_type_button; + private Button sort_color_button; } } \ No newline at end of file diff --git a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs index 85f7a36..50b0229 100644 --- a/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs +++ b/GasolineTanker/ProjectGasolineTanker/FormTruckCollection.cs @@ -15,6 +15,7 @@ using ProjectGasolineTanker.MovementStratg; using ProjectGasolineTanker.Exceptions; using ProjectGasolineTanker; using System.Xml.Linq; +using ProjectGasolineTanker.Generics; namespace ProjectGasolineTanker { @@ -32,6 +33,27 @@ namespace ProjectGasolineTanker _logger = logger; } + + private void buttonSortByType_Click(object sender, EventArgs e) => CompareTruck(new TruckCompareByType()); + + private void Sort_Color_button_Click(object sender, EventArgs e) => CompareTruck(new TruckCompareByColor()); + + // Сортировка по сравнителю + private void CompareTruck(IComparer comparer) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + obj.Sort(comparer); + pictureBoxCollection.Image = obj.ShowTruck(); + } + // заполнение лист бокс private void ReloadObjects() { @@ -39,7 +61,7 @@ namespace ProjectGasolineTanker 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)) { @@ -90,7 +112,7 @@ namespace ProjectGasolineTanker private void buttonAddTruck_Click(object sender, EventArgs e) { - + var formTruckConfig = new FormTruckConfig(); formTruckConfig.AddEvent(AddTruck); formTruckConfig.Show(); @@ -127,6 +149,11 @@ namespace ProjectGasolineTanker MessageBox.Show(ex.Message); _logger.LogWarning(ex.Message); } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + _logger.LogWarning(ex.Message); + } } @@ -225,5 +252,6 @@ namespace ProjectGasolineTanker ReloadObjects(); } + } } diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/DrawingTruckEqutables.cs b/GasolineTanker/ProjectGasolineTanker/Generic/DrawingTruckEqutables.cs new file mode 100644 index 0000000..9aec155 --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/Generic/DrawingTruckEqutables.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Diagnostics.CodeAnalysis; +using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Entities; + +namespace ProjectGasolineTanker.Generics +{ + internal class DrawingTruckEqutables : IEqualityComparer + { + public bool Equals(DrawingTruck? x, DrawingTruck? y) + { + if (x == null && x.EntityTruck == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null && y.EntityTruck == null) + throw new ArgumentNullException(nameof(y)); + + if ((x.GetType().Name != y.GetType().Name)) + return false; + + if (x.EntityTruck.Speed != y.EntityTruck.Speed) + return false; + + if (x.EntityTruck.Weight != y.EntityTruck.Weight) + return false; + + if (x.EntityTruck.BodyColor != y.EntityTruck.BodyColor) + return false; + + if (x is DrawingGasolineTanker && y is DrawingGasolineTanker) + { + var xGasTruck = (EntityGasolineTanker)x.EntityTruck; + var yGasTruck = (EntityGasolineTanker)y.EntityTruck; + + if (xGasTruck.Add_Color != yGasTruck.Add_Color) + return false; + + if (xGasTruck.IsTank != yGasTruck.IsTank) + return false; + + if (xGasTruck.IsWheel != yGasTruck.IsWheel) + return false; + } + return true; + } + + public int GetHashCode([DisallowNull] DrawingTruck? obj) + { + return obj.GetHashCode(); + } + + } +} diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs b/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs index 89df6f7..5694784 100644 --- a/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs +++ b/GasolineTanker/ProjectGasolineTanker/Generic/SetGeneric.cs @@ -23,13 +23,15 @@ namespace ProjectGasolineTanker.Generic } // Добавление объекта в начало - public int Insert(T truck) + public int Insert(T truck, IEqualityComparer? equal = null) { - return Insert(truck, 0); + return Insert(truck, 0, equal); } - + + public void SortSet(IComparer comparer) => _places.Sort(comparer); + // Добавление объекта в набор на конкретную позицию - public int Insert(T truck, int position) + public int Insert(T truck, int position, IEqualityComparer? equal = null) { if (Count >= _maxCount) { @@ -39,6 +41,10 @@ namespace ProjectGasolineTanker.Generic { throw new IndexOutOfRangeException("Индекс вне границ коллекции"); } + if (equal != null && _places.Contains(truck, equal)) + { + throw new ArgumentException("Данный объект уже есть в коллекции"); + } _places.Insert(position, truck); return 0; } diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/TruckCollectionInfo.cs b/GasolineTanker/ProjectGasolineTanker/Generic/TruckCollectionInfo.cs new file mode 100644 index 0000000..b605abf --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/Generic/TruckCollectionInfo.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.Generics +{ + internal class TruckCollectionInfo : IEquatable + { + public string Name { get; private set; } + public string Description { get; private set; } + public TruckCollectionInfo(string name, string description) + { + Name = name; + Description = description; + } + public bool Equals(TruckCollectionInfo? other) + { + if (ReferenceEquals(other, null)) + return false; + + return Name.Equals(other.Name); + } + public override int GetHashCode() => Name.GetHashCode(); + } +} diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/TruckCompareByColor.cs b/GasolineTanker/ProjectGasolineTanker/Generic/TruckCompareByColor.cs new file mode 100644 index 0000000..9d23ca1 --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/Generic/TruckCompareByColor.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Entities; + +namespace ProjectGasolineTanker.Generics +{ + internal class TruckCompareByColor : IComparer + { + public int Compare(DrawingTruck? x, DrawingTruck? y) + { + if (x == null || x.EntityTruck == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null || y.EntityTruck == null) + throw new ArgumentNullException(nameof(y)); + + var xTruck = x.EntityTruck; + var yTruck = y.EntityTruck; + + if (xTruck.BodyColor != yTruck.BodyColor) + return xTruck.BodyColor.Name.CompareTo(yTruck.BodyColor.Name); + + var speedCompare = x.EntityTruck.Speed.CompareTo(y.EntityTruck.Speed); + if (speedCompare != 0) + return speedCompare; + return x.EntityTruck.Weight.CompareTo(y.EntityTruck.Weight); + } + } +} diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/TruckCompareByType.cs b/GasolineTanker/ProjectGasolineTanker/Generic/TruckCompareByType.cs new file mode 100644 index 0000000..dae4feb --- /dev/null +++ b/GasolineTanker/ProjectGasolineTanker/Generic/TruckCompareByType.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectGasolineTanker.Drawings; + +namespace ProjectGasolineTanker.Generics +{ + internal class TruckCompareByType : IComparer + { + public int Compare(DrawingTruck? x, DrawingTruck? y) + { + if (x == null || x.EntityTruck == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null || y.EntityTruck == null) + throw new ArgumentNullException(nameof(y)); + + if (x.GetType().Name != y.GetType().Name) + return x.GetType().Name.CompareTo(y.GetType().Name); + + var speedCompare = x.EntityTruck.Speed.CompareTo(y.EntityTruck.Speed); + if (speedCompare != 0) + return speedCompare; + + return x.EntityTruck.Weight.CompareTo(y.EntityTruck.Weight); + } + } +} \ No newline at end of file diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs index 4be4734..5aa290f 100644 --- a/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs +++ b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericCollection.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Generics; using ProjectGasolineTanker.MovementStratg; namespace ProjectGasolineTanker.Generic @@ -29,13 +30,17 @@ namespace ProjectGasolineTanker.Generic _collection = new SetGeneric(width * height); } + public void Sort(IComparer comparer) => _collection.SortSet(comparer); + + public static int operator +(TruckGenericCollection collect, T? obj) { if (obj != null) { - return collect._collection.Insert(obj); + return collect._collection.Insert(obj, new DrawingTruckEqutables()); } return -1; + } public static bool operator -(TruckGenericCollection collect, int pos) { @@ -46,14 +51,16 @@ namespace ProjectGasolineTanker.Generic return collect?._collection.Remove(pos) ?? false; } + // получение объектов коллекции public IEnumerable GetTruck => _collection.GetTruck(); - + // получение объекта IMoveableObjecr public U? GetU(int pos) { return (U?)_collection[pos]?.GetMoveableObject; } + // вывод всего набора public Bitmap ShowTruck() { Bitmap bmp = new(_pictureWidth, _pictureHeight); @@ -63,6 +70,7 @@ namespace ProjectGasolineTanker.Generic return bmp; } + // прорисовка фона private void DrawBackground(Graphics gr) { Pen pen = new(Color.Black, 3); @@ -77,7 +85,6 @@ namespace ProjectGasolineTanker.Generic } } - private void DrawObjects(Graphics g) { // координаты @@ -88,15 +95,15 @@ namespace ProjectGasolineTanker.Generic { if (truck != null) { - + // TODO получение объекта if (x > _pictureWidth / _placeSizeWidth - 1) { x = 0; --y; } - + // TODO установка позиции truck.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y); - + // TODO прорисовка объекта truck.DrawTransport(g); ++x; } diff --git a/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericStorage.cs b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericStorage.cs index 51d85d0..dddefe5 100644 --- a/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericStorage.cs +++ b/GasolineTanker/ProjectGasolineTanker/Generic/TruckGenericStorage.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.Generics; using ProjectGasolineTanker.MovementStratg; namespace ProjectGasolineTanker.Generic @@ -11,9 +13,9 @@ namespace ProjectGasolineTanker.Generic internal class TruckGenericStorage { //Словарь (хранилище) - readonly Dictionary> _TruckStorages; + readonly Dictionary> _TruckStorages; //Возвращение списка названий наборов - public List Keys => _TruckStorages.Keys.ToList(); + public List Keys => _TruckStorages.Keys.ToList(); //Ширина окна отрисовки private readonly int _pictureWidth; //Высота окна отрисовки @@ -28,34 +30,30 @@ namespace ProjectGasolineTanker.Generic public TruckGenericStorage(int pictureWidth, int pictureHeight) { - _TruckStorages = new Dictionary>(); + _TruckStorages = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } + // Добавление набора public void AddSet(string name) { - - foreach (string nameStorage in Keys) - { - if (nameStorage == name) - { - MessageBox.Show("Набор с заданным именем уже занят", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - _TruckStorages.Add(name, new TruckGenericCollection(_pictureWidth, _pictureHeight)); + TruckCollectionInfo set = new TruckCollectionInfo(name, string.Empty); + if (_TruckStorages.ContainsKey(set)) + return; + _TruckStorages.Add(set, new TruckGenericCollection(_pictureWidth, _pictureHeight)); } // Удаление набора public void DelSet(string name) { + TruckCollectionInfo set = new TruckCollectionInfo(name, string.Empty); // TODO Прописать логику для удаления - if (_TruckStorages.ContainsKey(name)) + if (!_TruckStorages.ContainsKey(set)) { - _TruckStorages.Remove(name); + return; } - + _TruckStorages.Remove(set); } // Доступ к набору @@ -63,12 +61,13 @@ namespace ProjectGasolineTanker.Generic { get { + TruckCollectionInfo set = new TruckCollectionInfo(ind, string.Empty); // TODO Продумать логику получения набора - if (_TruckStorages.ContainsKey(ind)) + if (!_TruckStorages.ContainsKey(set)) { - return _TruckStorages[ind]; + return null; } - return null; + return _TruckStorages[set]; } } @@ -79,7 +78,7 @@ namespace ProjectGasolineTanker.Generic File.Delete(filename); } StringBuilder data = new(); - foreach (KeyValuePair> record in _TruckStorages) { StringBuilder records = new(); @@ -87,7 +86,7 @@ namespace ProjectGasolineTanker.Generic { records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); } - data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); + data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}"); } if (data.Length == 0) { @@ -95,14 +94,11 @@ namespace ProjectGasolineTanker.Generic } using FileStream fs = new(filename, FileMode.Create); byte[] info = new - UTF8Encoding(true).GetBytes($"TruckStorage{Environment.NewLine}{data}"); + UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}"); fs.Write(info, 0, info.Length); return; } - - - public void LoadData(string filename) { if (!File.Exists(filename)) @@ -145,19 +141,19 @@ namespace ProjectGasolineTanker.Generic StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) { - DrawingTruck? truck = + DrawingTruck? Truck = elem?.CreateDrawingTruck(_separatorForObject, _pictureWidth, _pictureHeight); - if (truck != null) + if (Truck != null) { - if ((collection + truck) == -1) + if ((collection + Truck)==-1) { throw new Exception("Ошибка добавления в коллекцию"); } } } - _TruckStorages.Add(record[0], collection); + _TruckStorages.Add(new TruckCollectionInfo(record[0], + string.Empty), collection); } } - } } diff --git a/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs index 8ca941e..2d55443 100644 --- a/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/AbstractStrategy.cs @@ -18,7 +18,7 @@ namespace ProjectGasolineTanker.MovementStratg private Status _state = Status.NotInit; protected int FieldWidth { get; private set; } - + protected int FieldHeight { get; private set; } public Status GetStatus() { return _state; } @@ -55,7 +55,7 @@ namespace ProjectGasolineTanker.MovementStratg protected bool MoveRight() => MoveTo(DirectionType.Right); protected bool MoveUp() => MoveTo(DirectionType.Up); - + protected bool MoveDown() => MoveTo(DirectionType.Down); protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition; diff --git a/GasolineTanker/ProjectGasolineTanker/MovementStratg/DrawingObjectTruck.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/DrawingObjectTruck.cs index 6760824..1df6edb 100644 --- a/GasolineTanker/ProjectGasolineTanker/MovementStratg/DrawingObjectTruck.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/DrawingObjectTruck.cs @@ -9,7 +9,9 @@ using ProjectGasolineTanker.Entities; namespace ProjectGasolineTanker.MovementStratg { - + /// + /// Реализация интерфейса + /// public class DrawingObjectTruck : IMoveableObject { private readonly DrawingTruck? _drawingTruck = null; diff --git a/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs index e7dc0f1..7245dda 100644 --- a/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/IMoveableObject.cs @@ -14,9 +14,9 @@ namespace ProjectGasolineTanker.MovementStratg { ObjectParameters? GetObjectPosition { get; } - - int GetStep { get; } + int GetStep { get; } + bool CheckCanMove(DirectionType direction); void MoveObject(DirectionType direction); diff --git a/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs index 082acc4..f020970 100644 --- a/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/MoveToCenter.cs @@ -6,9 +6,7 @@ using System.Threading.Tasks; namespace ProjectGasolineTanker.MovementStratg { - /// - /// Стратегия перемещения объекта в центр экрана - /// + public class MoveToCenter : AbstractStrategy { protected override bool IsTargetDestinaion() diff --git a/GasolineTanker/ProjectGasolineTanker/MovementStratg/ObjectParameters.cs b/GasolineTanker/ProjectGasolineTanker/MovementStratg/ObjectParameters.cs index 8d141e5..7504755 100644 --- a/GasolineTanker/ProjectGasolineTanker/MovementStratg/ObjectParameters.cs +++ b/GasolineTanker/ProjectGasolineTanker/MovementStratg/ObjectParameters.cs @@ -21,7 +21,7 @@ namespace ProjectGasolineTanker.MovementStratg public int RightBorder => _x + _width; public int DownBorder => _y + _height; - + public int ObjectMiddleHorizontal => _x + _width / 2; public int ObjectMiddleVertical => _y + _height / 2; diff --git a/GasolineTanker/ProjectGasolineTanker/serilog.json b/GasolineTanker/ProjectGasolineTanker/serilog.json index e46b436..e42dcb6 100644 --- a/GasolineTanker/ProjectGasolineTanker/serilog.json +++ b/GasolineTanker/ProjectGasolineTanker/serilog.json @@ -8,7 +8,6 @@ "Args": { "path": "Logs/trucklog.log", "rollingInterval": "Day", - "outputTemplate": null, "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" } }