Сделанная лаба

This commit is contained in:
ArtemEmelyanov 2022-12-09 12:39:15 +04:00
parent 7aab615e91
commit 2f7700a12e
2 changed files with 76 additions and 2 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Airbus
{
internal abstract class AbstractMap
internal abstract class AbstractMap : IEquatable<AbstractMap>
{
private IDrawningObject _drawningObject = null;
protected int[,] _map = null;
@ -121,5 +121,32 @@ namespace Airbus
protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
public bool Equals(AbstractMap? other)
{
if (other == null ||
_map != other._map ||
_width != other._width ||
_size_x != other._size_x ||
_size_y != other._size_y ||
_height != other._height ||
GetType() != other.GetType() ||
_map.GetLength(0) != other._map.GetLength(0) ||
_map.GetLength(1) != other._map.GetLength(1))
{
return false;
}
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] != other._map[i, j])
{
return false;
}
}
}
return true;
}
}
}

View File

@ -10,7 +10,54 @@ namespace Airbus
{
public int Compare(IDrawningObject? x, IDrawningObject? y)
{
throw new NotImplementedException();
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xPlane = x as DrawningObjectPlane;
var yPlane = y as DrawningObjectPlane;
if (xPlane == null && yPlane == null)
{
return 0;
}
if (xPlane == null && yPlane != null)
{
return 1;
}
if (xPlane != null && yPlane == null)
{
return -1;
}
string xShipColor = xPlane.GetPlane.Plane.BodyColor.Name;
string yShipColor = yPlane.GetPlane.Plane.BodyColor.Name;
if (xShipColor != yShipColor)
{
return xShipColor.CompareTo(yShipColor);
}
if (xPlane.GetPlane.Plane is EntityAirbus xAirbus && yPlane.GetPlane.Plane is EntityAirbus yAirbus)
{
string xShipDopColor = xAirbus.DopColor.Name;
string yShipDopColor = yAirbus.DopColor.Name;
var dopColorCompare = xShipDopColor.CompareTo(yShipDopColor);
if (dopColorCompare != 0)
{
return dopColorCompare;
}
}
var speedCompare = xPlane.GetPlane.Plane.Speed.CompareTo(yPlane.GetPlane.Plane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xPlane.GetPlane.Plane.Weight.CompareTo(yPlane.GetPlane.Plane.Weight);
}
}
}