Добавлены классы для сравнения объектов по цвету и типу
This commit is contained in:
parent
b0731d4f14
commit
d81aa61eb0
31
AirBomber/AirBomber/AirplaneCompareByColor.cs
Normal file
31
AirBomber/AirBomber/AirplaneCompareByColor.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class AirplaneCompareByColor : IComparer<IDrawningObject>
|
||||||
|
{
|
||||||
|
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||||
|
{
|
||||||
|
var xAirplane = x as DrawningObject;
|
||||||
|
var yAirplane = y as DrawningObject;
|
||||||
|
if (xAirplane == yAirplane)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (xAirplane == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (yAirplane == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var xEntity = xAirplane.Airplane.Airplane;
|
||||||
|
var yEntity = yAirplane.Airplane.Airplane;
|
||||||
|
var colorWeight = xEntity.BodyColor.ToArgb().CompareTo(yEntity.BodyColor.ToArgb());
|
||||||
|
if (colorWeight != 0 || xEntity is not EntityAirBomber || yEntity is not EntityAirBomber)
|
||||||
|
{
|
||||||
|
return colorWeight;
|
||||||
|
}
|
||||||
|
return ((EntityAirBomber)xEntity).DopColor.ToArgb().CompareTo(((EntityAirBomber)yEntity).DopColor.ToArgb());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
AirBomber/AirBomber/AirplaneCompareByType.cs
Normal file
37
AirBomber/AirBomber/AirplaneCompareByType.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
internal class AirplaneCompareByType : IComparer<IDrawningObject>
|
||||||
|
{
|
||||||
|
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||||
|
{
|
||||||
|
var xAirplane = x as DrawningObject;
|
||||||
|
var yAirplane = y as DrawningObject;
|
||||||
|
if (xAirplane == yAirplane)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (xAirplane == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (yAirplane == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (xAirplane.GetType().Name != yAirplane.Airplane.GetType().Name)
|
||||||
|
{
|
||||||
|
if (xAirplane.Airplane.GetType().Name == "DrawningAirplane")
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
var speedCompare = xAirplane.Airplane.Airplane.Speed.CompareTo(yAirplane.Airplane.Airplane.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return xAirplane.Airplane.Airplane.Weight.CompareTo(yAirplane.Airplane.Airplane.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,36 +8,36 @@ namespace AirBomber
|
|||||||
{
|
{
|
||||||
internal class DrawningObject : IDrawningObject
|
internal class DrawningObject : IDrawningObject
|
||||||
{
|
{
|
||||||
private DrawningAirplane _airplane = null;
|
|
||||||
|
|
||||||
public DrawningObject(DrawningAirplane airplane)
|
public DrawningObject(DrawningAirplane airplane)
|
||||||
{
|
{
|
||||||
_airplane = airplane;
|
Airplane = airplane;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Step => _airplane?.Airplane?.Step ?? 0;
|
public float Step => Airplane?.Airplane?.Step ?? 0;
|
||||||
|
|
||||||
|
public DrawningAirplane Airplane { get; private set; }
|
||||||
|
|
||||||
public RectangleF GetCurrentPosition()
|
public RectangleF GetCurrentPosition()
|
||||||
{
|
{
|
||||||
return _airplane.GetCurrentPosition();
|
return Airplane.GetCurrentPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveObject(Direction direction)
|
public void MoveObject(Direction direction)
|
||||||
{
|
{
|
||||||
_airplane?.MoveTransport(direction);
|
Airplane?.MoveTransport(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetObject(int x, int y, int width, int height)
|
public void SetObject(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
_airplane?.SetPosition(x, y, width, height);
|
Airplane?.SetPosition(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawObject(Graphics g)
|
public void DrawObject(Graphics g)
|
||||||
{
|
{
|
||||||
_airplane?.DrawTransport(g);
|
Airplane?.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetInfo() => _airplane?.GetDataForSave();
|
public string GetInfo() => Airplane?.GetDataForSave() ?? string.Empty;
|
||||||
|
|
||||||
public static IDrawningObject Create(string data) => new DrawningObject(data.CreateDrawningAirplane());
|
public static IDrawningObject Create(string data) => new DrawningObject(data.CreateDrawningAirplane());
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ namespace AirBomber
|
|||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
var cmp = new AirplaneCompareByType();
|
||||||
|
cmp.Compare(null, null);
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
ConfigureServices(services);
|
ConfigureServices(services);
|
||||||
|
Loading…
Reference in New Issue
Block a user