Первый шаг готов

This commit is contained in:
Сергей Полевой 2022-11-21 19:58:14 +04:00
parent a66e4d604a
commit 8aa272b0cb
3 changed files with 65 additions and 2 deletions

View File

@ -40,5 +40,63 @@ namespace Artilleries
public string GetInfo() => _artillery?.GetDateForSave(); public string GetInfo() => _artillery?.GetDateForSave();
public static IDrawingObject Create(string data) => new DrawingObjectArtillery(data.CreateDrawingArtillery()); public static IDrawingObject Create(string data) => new DrawingObjectArtillery(data.CreateDrawingArtillery());
public bool Equals(IDrawingObject? other)
{
if (other == null)
{
return false;
}
var otherArtillery = other as DrawingObjectArtillery;
if (otherArtillery == null)
{
return false;
}
var artillery = _artillery.Artillery;
var otherArtilleryArtillery = otherArtillery._artillery.Artillery;
if (artillery.GetType() != otherArtilleryArtillery.GetType())
{
return false;
}
if (artillery.Speed != otherArtilleryArtillery.Speed)
{
return false;
}
if (artillery.Weight != otherArtilleryArtillery.Weight)
{
return false;
}
if (artillery.BodyColor != otherArtilleryArtillery.BodyColor)
{
return false;
}
if (artillery is EntityAdvancedArtillery advanced && otherArtilleryArtillery is EntityAdvancedArtillery otherAdvanced)
{
if (advanced.DopColor != otherAdvanced.DopColor)
{
return false;
}
if (advanced.Weapon != otherAdvanced.Weapon)
{
return false;
}
if (advanced.SalvoBattery != otherAdvanced.SalvoBattery)
{
return false;
}
}
return true;
}
} }
} }

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Artilleries namespace Artilleries
{ {
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

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Artilleries namespace Artilleries
{ {
internal class SetArtilleriesGeneric<T> internal class SetArtilleriesGeneric<T>
where T : class where T : class, IEquatable<T>
{ {
private readonly List<T> _places; private readonly List<T> _places;
public int Count => _places.Count; public int Count => _places.Count;
@ -36,6 +36,11 @@ namespace Artilleries
return -1; return -1;
} }
if (_places.Contains(artillery))
{
return -1;
}
_places.Insert(position, artillery); _places.Insert(position, artillery);
return position; return position;