Batylkin.A.O.LabWork08 #10
@ -8,7 +8,8 @@ namespace ElectricLocomotive
|
||||
{
|
||||
internal class DrawningObjectLocomotive : IDrawningObject
|
||||
{
|
||||
private DrawningLocomotive _locomotive = null;
|
||||
public DrawningLocomotive _locomotive = null;
|
||||
public DrawningLocomotive GetLocomotive => _locomotive;
|
||||
public DrawningObjectLocomotive(DrawningLocomotive locomotive)
|
||||
{
|
||||
_locomotive = locomotive;
|
||||
@ -30,6 +31,33 @@ namespace ElectricLocomotive
|
||||
{
|
||||
_locomotive.DrawTransport(g);
|
||||
}
|
||||
|
||||
public bool Equals(IDrawningObject? other)
|
||||
{
|
||||
if (other is not DrawningObjectLocomotive otherShip)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var entity = _locomotive.Locomotive;
|
||||
var otherEntity = otherShip._locomotive.Locomotive;
|
||||
if (entity.GetType() != otherEntity.GetType() ||
|
||||
entity.Speed != otherEntity.Speed ||
|
||||
entity.Weight != otherEntity.Weight ||
|
||||
entity.BodyColor != otherEntity.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (entity is EntityElectricLocomotive entityWarmlyShip &&
|
||||
otherEntity is EntityElectricLocomotive otherEntityWarmlyShip && (
|
||||
entityWarmlyShip.BodyKit != otherEntityWarmlyShip.BodyKit ||
|
||||
entityWarmlyShip.DopColor != otherEntityWarmlyShip.DopColor ||
|
||||
entityWarmlyShip.SportLine != otherEntityWarmlyShip.SportLine))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public string GetInfo() => _locomotive?.GetDataForSave();
|
||||
public static IDrawningObject Create(string data) => new DrawningObjectLocomotive(data.CreateDrawningCar());
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.0" />
|
||||
<PackageReference Include="Serilog" Version="2.12.1-dev-01594" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.1-dev-10301" />
|
||||
<PackageReference Include="Serilog.Settings.AppSettings" Version="2.2.2" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.5.0-dev-00359" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00947" />
|
||||
<PackageReference Include="Serilog.Sinks.InfluxDBv2" Version="1.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -8,6 +8,11 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="ElectricLocomotive.csproj" />
|
||||
<None Include="ElectricLocomotive.csproj.user" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
|
||||
|
@ -50,6 +50,8 @@
|
||||
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.ButtonSortByType = new System.Windows.Forms.Button();
|
||||
this.ButtonSortByColor = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -148,7 +150,6 @@
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 22;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
@ -268,11 +269,33 @@
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
this.ButtonSortByType.Location = new System.Drawing.Point(837, 288);
|
||||
this.ButtonSortByType.Name = "ButtonSortByType";
|
||||
this.ButtonSortByType.Size = new System.Drawing.Size(151, 40);
|
||||
this.ButtonSortByType.TabIndex = 32;
|
||||
this.ButtonSortByType.Text = "Сортировать по типу";
|
||||
this.ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
this.ButtonSortByColor.Location = new System.Drawing.Point(837, 334);
|
||||
this.ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
this.ButtonSortByColor.Size = new System.Drawing.Size(151, 40);
|
||||
this.ButtonSortByColor.TabIndex = 33;
|
||||
this.ButtonSortByColor.Text = "Сортировать по цвету";
|
||||
this.ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// FormMapWithSetLocomotive
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1000, 722);
|
||||
this.Controls.Add(this.ButtonSortByColor);
|
||||
this.Controls.Add(this.ButtonSortByType);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.Controls.Add(this.textBoxNewMapName);
|
||||
this.Controls.Add(this.ButtonAddMap);
|
||||
@ -324,5 +347,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button ButtonSortByType;
|
||||
private Button ButtonSortByColor;
|
||||
}
|
||||
}
|
@ -13,7 +13,6 @@ namespace ElectricLocomotive
|
||||
{
|
||||
public partial class FormMapWithSetLocomotive : Form
|
||||
{
|
||||
private MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap> _mapLocomotiveCollectionGeneric;
|
||||
private readonly Dictionary<string, AbstractMap> _mapDict = new()
|
||||
{
|
||||
{"Простая карта", new SimpleMap() },
|
||||
@ -52,32 +51,7 @@ namespace ElectricLocomotive
|
||||
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 FieldMap();
|
||||
break;
|
||||
case "Карта с кустами":
|
||||
map = new BushesMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapLocomotiveCollectionGeneric = new MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap>(
|
||||
pictureBox1.Width, pictureBox1.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapLocomotiveCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
var FormLocmotiveConfig = new FormLocomotiveConfig();
|
||||
@ -271,6 +245,28 @@ namespace ElectricLocomotive
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ListBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ??
|
||||
string.Empty].Sort(new CarCompareByType());
|
||||
pictureBox1.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 ShipCompareByColor());
|
||||
pictureBox1.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
|
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal class ShipCompareByColor : IComparer<IDrawningObject>
|
||||
{
|
||||
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xShip = x as DrawningObjectLocomotive;
|
||||
var yShip = y as DrawningObjectLocomotive;
|
||||
if (xShip == null && yShip == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xShip == null && yShip != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xShip != null && yShip == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xEntityShip = xShip.GetLocomotive.Locomotive;
|
||||
var yEntityShip = yShip.GetLocomotive.Locomotive;
|
||||
var baseColorCompare = xEntityShip.BodyColor.ToArgb().CompareTo(yEntityShip.BodyColor.ToArgb());
|
||||
if (baseColorCompare != 0)
|
||||
{
|
||||
return baseColorCompare;
|
||||
}
|
||||
if (xEntityShip is EntityElectricLocomotive xWarmlyShip && yEntityShip is EntityElectricLocomotive yWarmlyShip)
|
||||
{
|
||||
var dopColorCompare = xWarmlyShip.DopColor.ToArgb().CompareTo(yWarmlyShip.DopColor.ToArgb());
|
||||
if (dopColorCompare != 0)
|
||||
{
|
||||
return dopColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = xShip.GetLocomotive.Locomotive.Speed.CompareTo(yShip.GetLocomotive.Locomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xShip.GetLocomotive.Locomotive.Weight.CompareTo(yShip.GetLocomotive.Locomotive.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal class CarCompareByType : IComparer<IDrawningObject>
|
||||
{
|
||||
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xCar = x as DrawningObjectLocomotive;
|
||||
var yCar = y as DrawningObjectLocomotive;
|
||||
if (xCar == null && yCar == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xCar == null && yCar != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xCar != null && yCar == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (xCar.GetLocomotive.GetType().Name != yCar.GetLocomotive.GetType().Name)
|
||||
{
|
||||
if (xCar.GetLocomotive.GetType().Name == "DrawningLocomotive")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var speedCompare =
|
||||
xCar.GetLocomotive.Locomotive.Speed.CompareTo(yCar.GetLocomotive.Locomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xCar.GetLocomotive.Locomotive.Weight.CompareTo(yCar.GetLocomotive.Locomotive.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal class MapWithSetLocomotivGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where T : class, IDrawningObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
// Ширина окна отрисовки
|
||||
@ -148,5 +148,10 @@
|
||||
_setLocomotive.Insert(DrawningObjectLocomotive.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setLocomotive.SortSet(comparer);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace ElectricLocomotive
|
||||
{
|
||||
internal class SetLocomotivGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
private readonly List<T> _places;
|
||||
public int Count => _places.Count;
|
||||
@ -23,11 +23,14 @@ namespace ElectricLocomotive
|
||||
}
|
||||
public int Insert(T locomotive, int position)
|
||||
{
|
||||
if (Count == _maxCount)
|
||||
if (_places.Contains(locomotive))
|
||||
{
|
||||
throw new ArgumentException($"Объект {locomotive} уже присутствует в наборе");
|
||||
}
|
||||
if (position < 0 || position > Count || _maxCount == Count)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
if (position < 0 || position > _maxCount) return -1;
|
||||
_places.Insert(position, locomotive);
|
||||
return position;
|
||||
}
|
||||
@ -75,5 +78,14 @@ namespace ElectricLocomotive
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user