Начала и закончила 8 лабу
This commit is contained in:
parent
34fb706739
commit
f03d4d88a4
53
WarmlyLocomotive/DrawingWarmlyLocomotiveEqutables.cs
Normal file
53
WarmlyLocomotive/DrawingWarmlyLocomotiveEqutables.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
using WarmlyLocomotive.Entities;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class DrawingWarmlyLocomotiveEqutables : IEqualityComparer<DrawningWarmlyLocomotive?>
|
||||
{
|
||||
public bool Equals(DrawningWarmlyLocomotive? x, DrawningWarmlyLocomotive? y)
|
||||
{
|
||||
if (x == null || x.EntityWarmlyLocomotive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityWarmlyLocomotive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityWarmlyLocomotive.Speed != y.EntityWarmlyLocomotive.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityWarmlyLocomotive.Weight != y.EntityWarmlyLocomotive.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityWarmlyLocomotive.BodyColor != y.EntityWarmlyLocomotive.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningWarmlyLocomotiveWithTrumpet && y is DrawningWarmlyLocomotiveWithTrumpet)
|
||||
{
|
||||
EntityWarmlyLocomotiveWithTrumpet EntityX = (EntityWarmlyLocomotiveWithTrumpet)x.EntityWarmlyLocomotive;
|
||||
EntityWarmlyLocomotiveWithTrumpet EntityY = (EntityWarmlyLocomotiveWithTrumpet)y.EntityWarmlyLocomotive;
|
||||
if (EntityX.Trumpet != EntityY.Trumpet)
|
||||
return false;
|
||||
if (EntityX.Luggage != EntityY.Luggage)
|
||||
return false;
|
||||
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningWarmlyLocomotive? obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
35
WarmlyLocomotive/DrawningEqutables.cs
Normal file
35
WarmlyLocomotive/DrawningEqutables.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WarmlyLocomotive.Generics;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class DrawningEqutables : IEqualityComparer<WarmlyLocomotiveGenericStorage?>
|
||||
{
|
||||
public bool Equals(WarmlyLocomotiveGenericStorage? x, WarmlyLocomotiveGenericStorage? y)
|
||||
{
|
||||
if (x == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.Keys.Count != y.Keys.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] WarmlyLocomotiveGenericStorage? obj)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,8 @@
|
||||
file = new ToolStripMenuItem();
|
||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||
buttonSortByType = new Button();
|
||||
buttonSortByColor = new Button();
|
||||
panelCollectionWarmlyLocomotive.SuspendLayout();
|
||||
panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollectionWarmlyLocomotive).BeginInit();
|
||||
@ -90,6 +92,8 @@
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.Controls.Add(buttonSortByColor);
|
||||
panel1.Controls.Add(buttonSortByType);
|
||||
panel1.Controls.Add(buttonDelObject);
|
||||
panel1.Controls.Add(textBoxStorageName);
|
||||
panel1.Controls.Add(listBoxStorages);
|
||||
@ -97,7 +101,7 @@
|
||||
panel1.Location = new Point(6, 34);
|
||||
panel1.Margin = new Padding(6);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(266, 446);
|
||||
panel1.Size = new Size(293, 526);
|
||||
panel1.TabIndex = 4;
|
||||
//
|
||||
// buttonDelObject
|
||||
@ -172,7 +176,7 @@
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(11, 527);
|
||||
buttonAdd.Location = new Point(7, 572);
|
||||
buttonAdd.Margin = new Padding(6);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(266, 47);
|
||||
@ -200,7 +204,7 @@
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { file });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(1528, 42);
|
||||
menuStrip.Size = new Size(1528, 40);
|
||||
menuStrip.TabIndex = 3;
|
||||
menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
@ -208,23 +212,43 @@
|
||||
//
|
||||
file.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||
file.Name = "file";
|
||||
file.Size = new Size(90, 38);
|
||||
file.Size = new Size(90, 36);
|
||||
file.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
SaveToolStripMenuItem.Size = new Size(359, 44);
|
||||
SaveToolStripMenuItem.Size = new Size(263, 44);
|
||||
SaveToolStripMenuItem.Text = "Сохранить";
|
||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
LoadToolStripMenuItem.Size = new Size(359, 44);
|
||||
LoadToolStripMenuItem.Size = new Size(263, 44);
|
||||
LoadToolStripMenuItem.Text = "Загрузить";
|
||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Location = new Point(5, 434);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(258, 41);
|
||||
buttonSortByType.TabIndex = 4;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += buttonSortByType_Click;
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Location = new Point(3, 477);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(265, 46);
|
||||
buttonSortByColor.TabIndex = 5;
|
||||
buttonSortByColor.Text = "Сортировка по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||
//
|
||||
// FormWarmlyLocomotiveCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
@ -270,5 +294,7 @@
|
||||
private ToolStripMenuItem file;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -5,16 +5,17 @@ using System.Windows.Forms;
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
using Serilog;
|
||||
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
public partial class FormWarmlyLocomotiveCollection : Form
|
||||
{
|
||||
private readonly WarmlyLocomotivesGenericStorage _storage;
|
||||
private readonly WarmlyLocomotiveGenericStorage _storage;
|
||||
|
||||
public FormWarmlyLocomotiveCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new WarmlyLocomotivesGenericStorage(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height);
|
||||
_storage = new WarmlyLocomotiveGenericStorage(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height);
|
||||
}
|
||||
private void ReloadObjects()
|
||||
{
|
||||
@ -22,7 +23,7 @@ namespace WarmlyLocomotive
|
||||
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))
|
||||
@ -95,6 +96,11 @@ namespace WarmlyLocomotive
|
||||
Log.Warning($"Коллекция {listBoxStorages.SelectedItem.ToString() ?? string.Empty} переполнена");
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Log.Warning($"Добавляемый объект уже существует в коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||
MessageBox.Show("Добавляемый объект уже сущесвует в коллекции");
|
||||
}
|
||||
});
|
||||
Action<Color>? ColorDelegate = new((ship) =>
|
||||
{
|
||||
@ -127,6 +133,7 @@ namespace WarmlyLocomotive
|
||||
Log.Information($"Удален объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty} по номеру {pos}");
|
||||
pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
|
||||
}
|
||||
|
||||
catch (WarmlyLocomotiveNotFoundException ex)
|
||||
{
|
||||
Log.Warning($"Не получилось удалить объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||
@ -137,6 +144,7 @@ namespace WarmlyLocomotive
|
||||
Log.Warning($"Было введено не число");
|
||||
MessageBox.Show("Введите число");
|
||||
}
|
||||
|
||||
}
|
||||
private void buttonreFreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -194,5 +202,22 @@ namespace WarmlyLocomotive
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e) => CompareWarmlyLocomotive(new WarmlyLocomotiveCompareByColor());
|
||||
private void buttonSortByType_Click(object sender, EventArgs e) => CompareWarmlyLocomotive(new WarmlyLocomotiveCompareByType());
|
||||
private void CompareWarmlyLocomotive(IComparer<DrawningWarmlyLocomotive?> comparer)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
using WarmlyLocomotive.Exceptions;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace WarmlyLocomotive.Generics
|
||||
|
||||
@ -23,28 +24,32 @@ namespace WarmlyLocomotive.Generics
|
||||
_places = new List<T?>(count);
|
||||
countMax = count;
|
||||
}
|
||||
public bool Insert(T ship)
|
||||
public bool Insert(T ship, IEqualityComparer<T>? equal = null)
|
||||
{
|
||||
if (_places.Count == countMax)
|
||||
throw new StorageOverflowException(countMax);
|
||||
Insert(ship, 0);
|
||||
Insert(ship, 0, equal);
|
||||
return true;
|
||||
}
|
||||
public bool Insert(T ship, int position)
|
||||
public void Insert(T ship, int position, IEqualityComparer<T>? equal = null)
|
||||
{
|
||||
if (_places.Count == countMax)
|
||||
throw new StorageOverflowException(countMax);
|
||||
if (!(position >= 0 && position <= Count && _places.Count < countMax))
|
||||
return false;
|
||||
if (!(position >= 0 && position <= Count))
|
||||
throw new Exception($"Неверная позиция для вставки");
|
||||
if (equal != null)
|
||||
{
|
||||
if (_places.Contains(ship, equal))
|
||||
throw new ArgumentException(nameof(ship));
|
||||
}
|
||||
_places.Insert(position, ship);
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
public void Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
throw new WarmlyLocomotiveNotFoundException(position);
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
public T? this[int position]
|
||||
{
|
||||
|
23
WarmlyLocomotive/WarmlyLocomotiveCompareByColor.cs
Normal file
23
WarmlyLocomotive/WarmlyLocomotiveCompareByColor.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class WarmlyLocomotiveCompareByColor : IComparer<DrawningWarmlyLocomotive?>
|
||||
{
|
||||
public int Compare(DrawningWarmlyLocomotive? x, DrawningWarmlyLocomotive? y)
|
||||
{
|
||||
if (x == null || x.EntityWarmlyLocomotive == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
if (y == null || y.EntityWarmlyLocomotive == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
if (x.EntityWarmlyLocomotive.BodyColor.Name != y.EntityWarmlyLocomotive.BodyColor.Name)
|
||||
{
|
||||
return x.EntityWarmlyLocomotive.BodyColor.Name.CompareTo(y.EntityWarmlyLocomotive.BodyColor.Name);
|
||||
}
|
||||
var speedCompare = x.EntityWarmlyLocomotive.Speed.CompareTo(y.EntityWarmlyLocomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
return speedCompare;
|
||||
return x.EntityWarmlyLocomotive.Weight.CompareTo(y.EntityWarmlyLocomotive.Weight);
|
||||
}
|
||||
}
|
||||
}
|
22
WarmlyLocomotive/WarmlyLocomotiveCompareByType.cs
Normal file
22
WarmlyLocomotive/WarmlyLocomotiveCompareByType.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class WarmlyLocomotiveCompareByType : IComparer<DrawningWarmlyLocomotive?>
|
||||
{
|
||||
public int Compare(DrawningWarmlyLocomotive? x, DrawningWarmlyLocomotive? y)
|
||||
{
|
||||
if (x == null || x.EntityWarmlyLocomotive == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
if (y == null || y.EntityWarmlyLocomotive == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityWarmlyLocomotive.Speed.CompareTo(y.EntityWarmlyLocomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
return speedCompare;
|
||||
return x.EntityWarmlyLocomotive.Weight.CompareTo(y.EntityWarmlyLocomotive.Weight);
|
||||
}
|
||||
}
|
||||
}
|
25
WarmlyLocomotive/WarmlyLocomotivesCollectionInfo.cs
Normal file
25
WarmlyLocomotive/WarmlyLocomotivesCollectionInfo.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using WarmlyLocomotive.Generics;
|
||||
|
||||
namespace WarmlyLocomotive
|
||||
{
|
||||
internal class WarmlyLocomotivesCollectionInfo : IEquatable<WarmlyLocomotivesCollectionInfo?>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public WarmlyLocomotivesCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(WarmlyLocomotivesCollectionInfo? other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
return Name == other.Name;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +1,29 @@
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WarmlyLocomotive.Generics;
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
using WarmlyLocomotive.Entities;
|
||||
using WarmlyLocomotive.MovementStrategy;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using WarmlyLocomotive;
|
||||
|
||||
namespace WarmlyLocomotive.Generics
|
||||
{
|
||||
internal class WarmlyLocomotivesGenericCollection<T, U>
|
||||
internal class WarmlyLocomotiveGenericCollection<T, U>
|
||||
|
||||
where T : DrawningWarmlyLocomotive
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetWarmlyLocomotives => _collection.GetWarmlyLocomotive();
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 270;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 100;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public WarmlyLocomotivesGenericCollection(int picWidth, int picHeight)
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
public WarmlyLocomotiveGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
@ -43,48 +31,23 @@ namespace WarmlyLocomotive.Generics
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(WarmlyLocomotivesGenericCollection<T, U> collect, T? obj)
|
||||
public static bool operator +(WarmlyLocomotiveGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
if (obj == null || collect == null)
|
||||
return false;
|
||||
}
|
||||
return (bool)collect?._collection.Insert(obj);
|
||||
collect._collection.Insert(obj, new DrawingWarmlyLocomotiveEqutables());
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(WarmlyLocomotivesGenericCollection<T, U> collect, int pos)
|
||||
public static T? operator -(WarmlyLocomotiveGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
collect._collection.Remove(pos);
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowWarmlyLocomotives()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
@ -93,10 +56,6 @@ namespace WarmlyLocomotive.Generics
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
@ -104,7 +63,7 @@ namespace WarmlyLocomotive.Generics
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{
|
||||
{//линия разметки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
@ -113,10 +72,6 @@ namespace WarmlyLocomotive.Generics
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int i = 0;
|
||||
@ -131,5 +86,6 @@ namespace WarmlyLocomotive.Generics
|
||||
i++;
|
||||
}
|
||||
}
|
||||
public IEnumerable<T?> GetWarmlyLocomotive => _collection.GetWarmlyLocomotive();
|
||||
}
|
||||
}
|
||||
|
@ -5,43 +5,42 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WarmlyLocomotive.DrawningObjects;
|
||||
using WarmlyLocomotive.MovementStrategy;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace WarmlyLocomotive.Generics
|
||||
{
|
||||
internal class WarmlyLocomotivesGenericStorage
|
||||
internal class WarmlyLocomotiveGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive,
|
||||
DrawningObjectWarmlyLocomotive>> _warmlylocomotiveStorages;
|
||||
public List<string> Keys => _warmlylocomotiveStorages.Keys.ToList();
|
||||
readonly Dictionary<WarmlyLocomotivesCollectionInfo, WarmlyLocomotiveGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>> _warmlylocomotiveStorages;
|
||||
public List<WarmlyLocomotivesCollectionInfo> Keys => _warmlylocomotiveStorages.Keys.ToList();
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
private readonly char _separatorRecords = ';';
|
||||
private static readonly char _separatorForObject = ':';
|
||||
public WarmlyLocomotivesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
public WarmlyLocomotiveGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_warmlylocomotiveStorages = new Dictionary<string, WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>>();
|
||||
_warmlylocomotiveStorages = new Dictionary<WarmlyLocomotivesCollectionInfo, WarmlyLocomotiveGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_warmlylocomotiveStorages.Add(name, new WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>(_pictureWidth, _pictureHeight));
|
||||
_warmlylocomotiveStorages.Add(new WarmlyLocomotivesCollectionInfo(name, string.Empty), new WarmlyLocomotiveGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_warmlylocomotiveStorages.ContainsKey(name))
|
||||
if (!_warmlylocomotiveStorages.ContainsKey(new WarmlyLocomotivesCollectionInfo(name, string.Empty)))
|
||||
return;
|
||||
_warmlylocomotiveStorages.Remove(name);
|
||||
_warmlylocomotiveStorages.Remove(new WarmlyLocomotivesCollectionInfo(name, string.Empty));
|
||||
}
|
||||
public WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>? this[string ind]
|
||||
public WarmlyLocomotiveGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_warmlylocomotiveStorages.ContainsKey(ind))
|
||||
{
|
||||
return _warmlylocomotiveStorages[ind];
|
||||
}
|
||||
WarmlyLocomotivesCollectionInfo index = new WarmlyLocomotivesCollectionInfo(ind, string.Empty);
|
||||
if (_warmlylocomotiveStorages.ContainsKey(index))
|
||||
return _warmlylocomotiveStorages[index];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -52,14 +51,14 @@ namespace WarmlyLocomotive.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string,WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>> record in _warmlylocomotiveStorages)
|
||||
foreach (KeyValuePair<WarmlyLocomotivesCollectionInfo,WarmlyLocomotiveGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive>> record in _warmlylocomotiveStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningWarmlyLocomotive? elem in record.Value.GetWarmlyLocomotives)
|
||||
foreach (DrawningWarmlyLocomotive? elem in record.Value.GetWarmlyLocomotive)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
|
||||
if (data.Length == 0)
|
||||
@ -105,7 +104,7 @@ namespace WarmlyLocomotive.Generics
|
||||
str = sr.ReadLine();
|
||||
continue;
|
||||
}
|
||||
WarmlyLocomotivesGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive> collection = new(_pictureWidth, _pictureHeight);
|
||||
WarmlyLocomotiveGenericCollection<DrawningWarmlyLocomotive, DrawningObjectWarmlyLocomotive> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
@ -118,7 +117,7 @@ namespace WarmlyLocomotive.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
_warmlylocomotiveStorages.Add(record[0], collection);
|
||||
_warmlylocomotiveStorages.Add(new WarmlyLocomotivesCollectionInfo(record[0], string.Empty), collection);
|
||||
|
||||
str = sr.ReadLine();
|
||||
} while (str != null);
|
||||
@ -126,4 +125,4 @@ namespace WarmlyLocomotive.Generics
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user