изменения
This commit is contained in:
parent
a269d68ac5
commit
3f1df7742f
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Warship
|
namespace Warship
|
||||||
{
|
{
|
||||||
internal abstract class AbstractMap
|
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||||
{
|
{
|
||||||
private IDrawingObject _drawingObject = null;
|
private IDrawingObject _drawingObject = null;
|
||||||
protected int[,] _map = null;
|
protected int[,] _map = null;
|
||||||
@ -148,5 +148,30 @@ namespace Warship
|
|||||||
protected abstract void GenerateMap();
|
protected abstract void GenerateMap();
|
||||||
protected abstract void DrawWaterPart(Graphics gr, int i, int j);
|
protected abstract void DrawWaterPart(Graphics gr, int i, int j);
|
||||||
protected abstract void DrawLandPart(Graphics gr, int i, int j);
|
protected abstract void DrawLandPart(Graphics gr, int i, int j);
|
||||||
|
|
||||||
|
public bool Equals(AbstractMap? other)
|
||||||
|
{
|
||||||
|
if (other == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (_width != other._width)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (_height != other._height)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (_size_x != other._size_x)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (_size_y != other._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] != other._map[i, j])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,10 +64,9 @@ namespace Warship
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DrawingObjectWarship warship = new(drawingWarship);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + warship != -1)
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectWarship(drawingWarship) != -1)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Новый объект добавлен");
|
_logger.LogInformation("Новый объект добавлен");
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
|
@ -33,11 +33,14 @@ namespace Warship
|
|||||||
|
|
||||||
public int Insert(T warship, int position)
|
public int Insert(T warship, int position)
|
||||||
{
|
{
|
||||||
if (_places.Contains(warship))
|
if (Count == _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
|
||||||
|
if (position < 0 || position > Count)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (position >= _maxCount || position < 0)
|
if (_places.Contains(warship))
|
||||||
throw new StorageOverflowException(_maxCount);
|
return -1;
|
||||||
|
|
||||||
_places.Insert(position, warship);
|
_places.Insert(position, warship);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user