Изменения

This commit is contained in:
crum61kg 2023-01-23 00:00:11 +04:00
parent 68db88d4c4
commit c7de4f3d1d
3 changed files with 26 additions and 42 deletions

View File

@ -164,10 +164,13 @@ namespace WarmlyShip
/// <param name="g"></param> /// <param name="g"></param>
private void DrawWarmlyShip(Graphics g) private void DrawWarmlyShip(Graphics g)
{ {
int width = _pictureWidth / _placeSizeWidth;
int k = 0;
foreach (var ship in _setWarmlyShip.GetShip()) foreach (var ship in _setWarmlyShip.GetShip())
{ {
// TODO установка позиции ship.SetObject(k % width * _placeSizeWidth + 10, k / width * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
ship.DrawningObject(g); ship.DrawningObject(g);
k++;
} }
} }

View File

@ -6,6 +6,9 @@ using System.Threading.Tasks;
namespace WarmlyShip namespace WarmlyShip
{ {
/// <summary>
/// Класс для хранения коллекции карт
/// </summary>
internal class MapsCollection internal class MapsCollection
{ {
/// <summary> /// <summary>
@ -42,7 +45,8 @@ namespace WarmlyShip
/// <param name="map">Карта</param> /// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map) public void AddMap(string name, AbstractMap map)
{ {
if (!Keys.Contains(name))
_mapStorages.Add(name, new MapWithSetWarmlyShipGeneric<DrawningObjectShip, AbstractMap>(_pictureWidth, _pictureHeight, map));
} }
/// <summary> /// <summary>
/// Удаление карты /// Удаление карты
@ -50,7 +54,8 @@ namespace WarmlyShip
/// <param name="name">Название карты</param> /// <param name="name">Название карты</param>
public void DelMap(string name) public void DelMap(string name)
{ {
// TODO Прописать логику для удаления if (Keys.Contains(name))
_mapStorages.Remove(name);
} }
/// <summary> /// <summary>
/// Доступ к парковке /// Доступ к парковке
@ -62,10 +67,10 @@ namespace WarmlyShip
{ {
get get
{ {
// TODO Продумать логику получения объекта if (Keys.Contains(ind))
return _mapStorages[ind];
return null; return null;
} }
} }
} }
} }

View File

@ -39,18 +39,9 @@ namespace WarmlyShip
/// <returns></returns> /// <returns></returns>
public int Insert(T ship) public int Insert(T ship)
{ {
// + проверка на _maxCount if (Count < _maxCount)
return Insert(ship, 0);
if (ship == null) return -1;
{
return -1;
}
for (int i = Count - 1; i > 0; i--)
{
_places[i] = _places[i - 1];
}
_places[0] = ship;
return 0;
} }
/// <summary> /// <summary>
/// Добавление объекта в набор на конкретную позицию /// Добавление объекта в набор на конкретную позицию
@ -60,27 +51,12 @@ namespace WarmlyShip
/// <returns></returns> /// <returns></returns>
public int Insert(T ship, int position) public int Insert(T ship, int position)
{ {
//кое что убрать (проверка позиции)
if (position < 0 || position > Count) if (position < 0 || position > Count)
{ {
return -1; return -1;
} }
int firstNullElementIndex = position; _places.Insert(position, ship);
while (_places[firstNullElementIndex] != null) return position;
{
if (firstNullElementIndex >= Count)
{
return -1;
}
firstNullElementIndex++;
}
for (int i = firstNullElementIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = ship;
return 0;
} }
/// <summary> /// <summary>
/// Удаление объекта из набора с конкретной позиции /// Удаление объекта из набора с конкретной позиции
@ -89,14 +65,12 @@ namespace WarmlyShip
/// <returns></returns> /// <returns></returns>
public T Remove(int position) public T Remove(int position)
{ {
// убрать удаление объекта if (position < 0 || position >= Count)
if (_places[position] == null)
{
return null; return null;
}
var result = _places[position]; var result = _places[position];
_places[position] = null; _places.RemoveAt(position);
return result; return result;
} }
/// <summary> /// <summary>
/// Получение объекта из набора по позиции /// Получение объекта из набора по позиции
@ -107,13 +81,15 @@ namespace WarmlyShip
{ {
get get
{ {
// TODO проверка позиции if (position < 0 || position >= Count)
return null;
return _places[position]; return _places[position];
} }
set set
{ {
// TODO проверка позиции if (position < 0 || position >= _maxCount)
// TODO вставка в список по позиции return;
_places.Add(value);
} }
} }
/// <summary> /// <summary>