diff --git a/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.cs b/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.cs
index b06332b..b2a3453 100644
--- a/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.cs
+++ b/AircraftCarrier/AircraftCarrier/FormMapWithSetWarships.cs
@@ -177,10 +177,11 @@ namespace AircraftCarrier
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
try
{
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ var deletedWarship = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
+ if (deletedWarship != null)
{
MessageBox.Show("Объект удален");
- _logger.LogInformation("Из текущей карты удален объект {@ship}", (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos));
+ _logger.LogInformation("Из текущей карты удален объект {@ship}", deletedWarship);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
diff --git a/AircraftCarrier/AircraftCarrier/MapWithSetWarshipsGeneric.cs b/AircraftCarrier/AircraftCarrier/MapWithSetWarshipsGeneric.cs
index e2eb3cd..0fbb68b 100644
--- a/AircraftCarrier/AircraftCarrier/MapWithSetWarshipsGeneric.cs
+++ b/AircraftCarrier/AircraftCarrier/MapWithSetWarshipsGeneric.cs
@@ -149,10 +149,10 @@ namespace AircraftCarrier
{
for (; j > i; j--)
{
- var car = _setWarships[j];
- if (car != null)
+ var warship = _setWarships[j];
+ if (warship != null)
{
- _setWarships.Insert(car, i);
+ _setWarships.Insert(warship, i);
_setWarships.Remove(j);
break;
}
@@ -189,14 +189,33 @@ namespace AircraftCarrier
///
private void DrawWarships(Graphics g)
{
- int width = _pictureWidth / _placeSizeWidth;
+ int countInLine = _pictureWidth / _placeSizeWidth;
+ int countInColumn = _pictureHeight / _placeSizeHeight;
+
+ int maxLeft = (countInLine - 1) * _placeSizeWidth;
+ int maxDown = (countInColumn - 1) * _placeSizeHeight;
+ for (int i = 0; i < _setWarships.Count; i++)
+ {
+ var warship = _setWarships[i];
+ warship?.SetObject(i % countInLine * _placeSizeWidth, maxDown - i / countInLine * _placeSizeHeight + 7, _pictureWidth, _pictureHeight);
+
+
+ //warship?.SetObject(i % countInLine * _placeSizeWidth - 3, i / countInLine * _placeSizeHeight, _pictureWidth, _pictureHeight);
+
+ //warship?.SetObject(i % countInLine * _placeSizeWidth - 3, maxDown - i * countInColumn * _placeSizeHeight, _pictureWidth, _pictureHeight);
+ //warship?.SetObject(i % _pictureWidth * _placeSizeWidth, (countInColumn - 1 - i / countInLine) * _placeSizeHeight + 5, _pictureWidth, _pictureHeight);
+ warship?.DrawningObject(g);
+ }
+
+
+ /*int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _setWarships.Count; i++)
{
var warship = _setWarships[i];
warship?.SetObject(i % _pictureWidth * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight + 4, _pictureWidth, _pictureHeight);
warship?.DrawningObject(g);
- }
+ }*/
}
}
}
diff --git a/AircraftCarrier/AircraftCarrier/SetWarshipsGeneric.cs b/AircraftCarrier/AircraftCarrier/SetWarshipsGeneric.cs
index 538aad5..b896fc5 100644
--- a/AircraftCarrier/AircraftCarrier/SetWarshipsGeneric.cs
+++ b/AircraftCarrier/AircraftCarrier/SetWarshipsGeneric.cs
@@ -52,10 +52,16 @@ namespace AircraftCarrier
if (Count == _maxCount)
throw new StorageOverflowException(_maxCount);
- if (position >= _maxCount || position < 0) return -1;
+ if (!isCorrectPosition(position)) return -1;
_places.Insert(position, warship);
return 1;
}
+
+ private bool isCorrectPosition(int position)
+ {
+ return 0 <= position && position < _maxCount;
+ }
+
///
/// Удаление объекта из набора с конкретной позиции
///
@@ -63,11 +69,10 @@ namespace AircraftCarrier
///
public T Remove(int position)
{
- if (position >= _maxCount || position < 0)
+ if (!isCorrectPosition(position))
return null;
-
- var result = _places[position];
- if(result == null)
+ var result = this[position];
+ if (result == null)
throw new WarshipNotFoundException(position);
_places.RemoveAt(position);
return result;
@@ -81,8 +86,7 @@ namespace AircraftCarrier
{
get
{
- if (position >= _maxCount || position < 0) return null;
- return _places[position];
+ return isCorrectPosition(position) && position < Count ? _places[position] : null;
}
set
{