ISEbd-22 Alimova M.S. Lab Work 08 #8

Closed
malimova wants to merge 4 commits from Lab8 into Lab7
2 changed files with 96 additions and 0 deletions
Showing only changes of commit 950ea78e74 - Show all commits

View 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);
}
}
}

View 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);
}
}
}