Сравнение объектов

This commit is contained in:
Володя 2022-12-02 20:40:53 +03:00
parent aa24557081
commit a145a52010
4 changed files with 34 additions and 3 deletions

View File

@ -39,5 +39,35 @@ namespace AirPlaneWithRadar
{ {
_plain.setPosition(x, y, width, height); _plain.setPosition(x, y, width, height);
} }
public bool Equals(IDrawingObject? other)
{
if (other == null)
{
return false;
}
var otherPlain = other as DrawingObjectPlane;
if (otherPlain == null)
{
return false;
}
var plain = _plain.Plain;
var otherPlainPlain = otherPlain._plain.Plain;
if (plain.Speed != otherPlainPlain.Speed)
{
return false;
}
if (plain.Weight != otherPlainPlain.Weight)
{
return false;
}
if (plain.BodyColor != otherPlainPlain.BodyColor)
{
return false;
}
return true;
}
} }
} }

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirPlaneWithRadar namespace AirPlaneWithRadar
{ {
internal interface IDrawingObject internal interface IDrawingObject : IEquatable<IDrawingObject>
{ {
public float Step { get; } public float Step { get; }
void SetObject(int x, int y, int width, int height); void SetObject(int x, int y, int width, int height);

View File

@ -8,7 +8,7 @@ namespace AirPlaneWithRadar
{ {
internal class MapWithSetPlainGeneric internal class MapWithSetPlainGeneric
<T, U> <T, U>
where T : class, IDrawingObject where T : class, IDrawingObject, IEquatable<T>
where U : AbstractMap where U : AbstractMap
{ {
private readonly int _pictureWidth; private readonly int _pictureWidth;

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace AirPlaneWithRadar namespace AirPlaneWithRadar
{ {
internal class SetPlaneGeneric<T> internal class SetPlaneGeneric<T>
where T : class where T : class, IEquatable<T>
{ {
private readonly List<T> _places; private readonly List<T> _places;
@ -26,6 +26,7 @@ namespace AirPlaneWithRadar
} }
public int Insert(T plain, int position) public int Insert(T plain, int position)
{ {
/////
if (_places.Count == _maxCount) if (_places.Count == _maxCount)
{ {
throw new StorageOverFullException(_maxCount); throw new StorageOverFullException(_maxCount);