IEquatable AbstractMap
This commit is contained in:
parent
5a1cdcd4b2
commit
a7027333d8
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Locomotive
|
namespace Locomotive
|
||||||
{
|
{
|
||||||
internal abstract class AbstractMap
|
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||||
{
|
{
|
||||||
private IDrawningObject _drawningObject = null;
|
private IDrawningObject _drawningObject = null;
|
||||||
protected int[,] _map = null;
|
protected int[,] _map = null;
|
||||||
@ -164,5 +164,30 @@ namespace Locomotive
|
|||||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||||
|
|
||||||
|
public bool Equals(AbstractMap? other)
|
||||||
|
{
|
||||||
|
if (other == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var otherMap = other as AbstractMap;
|
||||||
|
if (otherMap == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_width != otherMap._width) return false;
|
||||||
|
if (_height != otherMap._height) return false;
|
||||||
|
if (_size_x != otherMap._size_x) return false;
|
||||||
|
if (_size_y != otherMap._size_y) return false;
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i,j] != otherMap._map[i,j]) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user