diff --git a/WarmlyShip/WarmlyShip/FormShipCollection.cs b/WarmlyShip/WarmlyShip/FormShipCollection.cs
index 7cc7a20..3b27b13 100644
--- a/WarmlyShip/WarmlyShip/FormShipCollection.cs
+++ b/WarmlyShip/WarmlyShip/FormShipCollection.cs
@@ -79,7 +79,7 @@ namespace WarmlyShip
EventArgs e)
{
pictureBoxCollection.Image =
- _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowShips();
+ _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowShips();
}
///
/// Удаление набора
@@ -92,11 +92,9 @@ namespace WarmlyShip
{
return;
}
- if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
- MessageBoxIcon.Question) == DialogResult.Yes)
+ if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
- _storage.DelSet(listBoxStorages.SelectedItem.ToString()
- ?? string.Empty);
+ _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
ReloadObjects();
}
}
@@ -143,14 +141,12 @@ namespace WarmlyShip
{
return;
}
- var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
- string.Empty];
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
- if (MessageBox.Show("Удалить объект?", "Удаление",
- MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
diff --git a/WarmlyShip/WarmlyShip/SetGeneric.cs b/WarmlyShip/WarmlyShip/SetGeneric.cs
index ea50ab6..80b0d47 100644
--- a/WarmlyShip/WarmlyShip/SetGeneric.cs
+++ b/WarmlyShip/WarmlyShip/SetGeneric.cs
@@ -14,7 +14,7 @@ namespace WarmlyShip.Generics
///
private readonly List _places;
///
- /// Количество объектов в массиве
+ /// Количество объектов в списке
///
public int Count => _places.Count;
///
@@ -37,39 +37,26 @@ namespace WarmlyShip.Generics
///
public bool Insert(T warmlyship)
{
- // TODO вставка в начало набора
+ if (_places.Count == _maxCount)
+ {
+ return false;
+ }
+ Insert(warmlyship, 0);
return true;
}
///
/// Добавление объекта в набор на конкретную позицию
///
- /// Добавляемый теплоход
+ /// Добавляемый теплоход
/// Позиция
///
public bool Insert(T warmlyship, int position)
{
- int nullIndex = -1;
- int i;
-
- if (position < 0 || position >= Count)
- return false;
-
- for (i = position; i < Count; i++)
+ if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
{
- if (_places[i] == null)
- {
- nullIndex = i;
- break;
- }
- }
- if (nullIndex < 0)
return false;
-
- for (i = nullIndex; i > position; i--)
- {
- _places[i] = _places[i - 1];
}
- _places[position] = warmlyship;
+ _places.Insert(position, warmlyship);
return true;
}
///
@@ -83,7 +70,7 @@ namespace WarmlyShip.Generics
{
return false;
}
- _places.RemoveAt(position);
+ _places[position] = null;
return true;
}
///
diff --git a/WarmlyShip/WarmlyShip/ShipsGenericCollection.cs b/WarmlyShip/WarmlyShip/ShipsGenericCollection.cs
index 9533c11..55af291 100644
--- a/WarmlyShip/WarmlyShip/ShipsGenericCollection.cs
+++ b/WarmlyShip/WarmlyShip/ShipsGenericCollection.cs
@@ -110,7 +110,7 @@ namespace WarmlyShip.Generics
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
- {//линия рамзетки места
+ {
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
@@ -128,9 +128,6 @@ namespace WarmlyShip.Generics
int i = 0;
foreach (var ship in _collection.GetShips())
{
- // TODO получение объекта
- // TODO установка позиции
- // TODO прорисовка объекта
if (ship != null)
{
int width = _pictureWidth / _placeSizeWidth;
diff --git a/WarmlyShip/WarmlyShip/ShipsGenericStorage.cs b/WarmlyShip/WarmlyShip/ShipsGenericStorage.cs
index b6354e2..f839f50 100644
--- a/WarmlyShip/WarmlyShip/ShipsGenericStorage.cs
+++ b/WarmlyShip/WarmlyShip/ShipsGenericStorage.cs
@@ -45,7 +45,11 @@ namespace WarmlyShip.Generics
/// Название набора
public void AddSet(string name)
{
- _shipStorages.Add(name, new ShipsGenericCollection(_pictureWidth, _pictureHeight));
+ if (_shipStorages.ContainsKey(name))
+ {
+ return;
+ }
+ _shipStorages[name] = new ShipsGenericCollection(_pictureWidth, _pictureHeight);
}
///
/// Удаление набора
@@ -53,7 +57,6 @@ namespace WarmlyShip.Generics
/// Название набора
public void DelSet(string name)
{
- // TODO Прописать логику для удаления
if (!_shipStorages.ContainsKey(name))
{
return;
@@ -71,7 +74,6 @@ namespace WarmlyShip.Generics
{
get
{
- // TODO Продумать логику получения набора
if (_shipStorages.ContainsKey(ind))
{
return _shipStorages[ind];