исправленно

This commit is contained in:
Макс Бондаренко 2022-10-30 01:09:29 +04:00
parent 6e509b6d07
commit f5df18ed71
2 changed files with 4 additions and 36 deletions

View File

@ -49,9 +49,9 @@ namespace WarmlyShip
public Bitmap ShowOnMap() public Bitmap ShowOnMap()
{ {
Shaking(); Shaking();
foreach (var car in _setShips.GetShips()) foreach (var ship in _setShips.GetShips())
{ {
return _map.CreateMap(_pictureWidth, _pictureHeight, car); return _map.CreateMap(_pictureWidth, _pictureHeight, ship);
} }
return new(_pictureWidth, _pictureHeight); return new(_pictureWidth, _pictureHeight);
} }

View File

@ -20,47 +20,15 @@ namespace WarmlyShip
_places = new List<T>(); _places = new List<T>();
} }
private bool CanInsert(int position)
{
for (int i = position; i < Count; ++i)
if (_places[i] == null) return true;
return false;
}
public int Insert(T ship) public int Insert(T ship)
{ {
if (CanInsert(0)) _places.Insert(0, ship);
{ return 1;
for (int i = Count - 1; i > 0; --i)
{
if (_places[i] == null)
{
_places[i] = _places[i - 1];
_places[i - 1] = null;
}
}
_places[0] = ship;
return 1;
}
return 0;
} }
public int Insert(T ship, int position) public int Insert(T ship, int position)
{ {
if (position < 0 || position > Count || Count == _maxCount) return 0; if (position < 0 || position > Count || Count == _maxCount) return 0;
/*if (_places[position] != null && CanInsert(position))
{
for (int i = _places.Count - 1; i > position; --i)
{
if (_places[i] == null)
{
_places[i] = _places[i - 1];
_places[i - 1] = null;
}
}
}
_places[position] = ship;
return 1;*/
_places.Insert(position, ship); _places.Insert(position, ship);
return 1; return 1;
} }