реализовано сравнение
This commit is contained in:
parent
075103c116
commit
950ea78e74
57
AirBomber/AirBomber/PlaneCompareByColor.cs
Normal file
57
AirBomber/AirBomber/PlaneCompareByColor.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.DrawningObjects;
|
||||
using AirBomber.Entities;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
internal class PlaneCompareByColor: IComparer<DrawningAirPlane?>
|
||||
{
|
||||
public int Compare(DrawningAirPlane? x, DrawningAirPlane? y)
|
||||
{
|
||||
if (x == null || x.EntityAirPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
|
||||
if (y == null || y.EntityAirPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
|
||||
var bodyColorCompare = x.EntityAirPlane.BodyColor.Name.CompareTo(y.EntityAirPlane.BodyColor.Name);
|
||||
|
||||
if (bodyColorCompare != 0)
|
||||
{
|
||||
return bodyColorCompare;
|
||||
}
|
||||
|
||||
if (x.EntityAirPlane is EntityAirBomber xEntitySailCatamaran && y.EntityAirPlane is EntityAirBomber yEntitySailCatamaran)
|
||||
{
|
||||
var BodyColorCompare = xEntitySailCatamaran.BodyColor.Name.CompareTo(yEntitySailCatamaran.BodyColor.Name);
|
||||
if (BodyColorCompare != 0)
|
||||
{
|
||||
return BodyColorCompare;
|
||||
}
|
||||
var AdditionalColorCompare = xEntitySailCatamaran.AdditionalColor.Name.CompareTo(yEntitySailCatamaran.AdditionalColor.Name);
|
||||
if (AdditionalColorCompare != 0)
|
||||
{
|
||||
return AdditionalColorCompare;
|
||||
}
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityAirPlane.Speed.CompareTo(y.EntityAirPlane.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityAirPlane.Weight.CompareTo(y.EntityAirPlane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
39
AirBomber/AirBomber/PlaneCompareByType.cs
Normal file
39
AirBomber/AirBomber/PlaneCompareByType.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.DrawningObjects;
|
||||
|
||||
namespace AirBomber.Generics
|
||||
{
|
||||
internal class PlaneCompareByType: IComparer<DrawningAirPlane?>
|
||||
{
|
||||
public int Compare(DrawningAirPlane? x, DrawningAirPlane? y)
|
||||
{
|
||||
if (x == null || x.EntityAirPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
|
||||
if (y == null || y.EntityAirPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityAirPlane.Speed.CompareTo(y.EntityAirPlane.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityAirPlane.Weight.CompareTo(y.EntityAirPlane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user