создание 2 классов сортировки

This commit is contained in:
Артем Харламов 2022-12-17 18:00:44 +04:00
parent 165d0d1392
commit d74a447e56
2 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class StormtrooperCompareByColor : 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 xStorm = x as DrawningObjectStorm;
var yStorm = y as DrawningObjectStorm;
if (xStorm == null && yStorm == null)
{
return 0;
}
if (xStorm == null && yStorm != null)
{
return 1;
}
if (xStorm != null && yStorm == null)
{
return -1;
}
var baseColorCompare = xStorm.GetStormtrooper.Storm.BodyColor.ToString().CompareTo(yStorm.GetStormtrooper.Storm.BodyColor.ToString());
if (baseColorCompare != 0)
{
return baseColorCompare;
}
if (xStorm.GetStormtrooper.Storm is EntityMilitaryStormtrooper xDDB && yStorm.GetStormtrooper.Storm is EntityMilitaryStormtrooper yDDB)
{
var extraColorCompare = xDDB.BodyColor.ToString().CompareTo(yDDB.BodyColor.ToString());
if (extraColorCompare != 0)
{
return extraColorCompare;
}
}
return 0;
}
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class StormtrooperCompareByType : 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 xStorm = x as DrawningObjectStorm;
var yStorm = y as DrawningObjectStorm;
if (xStorm == null && yStorm == null)
{
return 0;
}
if (xStorm == null && yStorm != null)
{
return 1;
}
if (xStorm != null && yStorm == null)
{
return -1;
}
if (xStorm.GetStormtrooper.GetType().Name != yStorm.GetStormtrooper.GetType().Name)
{
if (xStorm.GetStormtrooper.GetType().Name == "Drawning")
{
return -1;
}
return 1;
}
var speedCompare = xStorm.GetStormtrooper.Storm.Speed.CompareTo(yStorm.GetStormtrooper.Storm.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xStorm.GetStormtrooper.Storm.Weight.CompareTo(yStorm.GetStormtrooper.Storm.Weight);
}
}
}