реализация IEquatable для AbstractMap

This commit is contained in:
Мельников Игорь 2022-12-08 18:19:03 +04:00
parent f866ee1024
commit 1bec916bb1

View File

@ -1,6 +1,6 @@
namespace Locomotives
{
internal abstract class AbstractMap
internal abstract class AbstractMap : IEquatable<AbstractMap>
{
/// <summary>
/// Поле от интерфейса прорисовки
@ -60,7 +60,7 @@
/// <returns></returns>
public (int Top, int Bottom, int Left, int Right) GetObjectCoordinates()
{
return
return
(
(int)(_drawningObject.GetCurrentPosition().Top / _size_y),
(int)(_drawningObject.GetCurrentPosition().Bottom / _size_y),
@ -239,5 +239,35 @@
/// <param name="i"></param>
/// <param name="j"></param>
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
/// <summary>
/// Реализация сравнения
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(AbstractMap? other)
{
if (other == null)
{
return false;
}
if (_map.GetLength(0) == other._map.GetLength(0) && _map.GetLength(1) == other._map.GetLength(1))
{
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;
}
}
}
}
else
{
return false;
}
return true;
}
}
}