Этап 1. Смена массива на список
This commit is contained in:
parent
8545247498
commit
2e12e1f2e1
@ -93,14 +93,11 @@ namespace WarmlyShip
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setWarmlyShip.Count; i++)
|
||||
foreach (var ship in _setWarmlyShip.GetShip())
|
||||
{
|
||||
var car = _setWarmlyShip.Get(i);
|
||||
if (car != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||
}
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, ship);
|
||||
}
|
||||
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
@ -124,11 +121,11 @@ namespace WarmlyShip
|
||||
int j = _setWarmlyShip.Count - 1;
|
||||
for (int i = 0; i < _setWarmlyShip.Count; i++)
|
||||
{
|
||||
if (_setWarmlyShip.Get(i) == null)
|
||||
if (_setWarmlyShip[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setWarmlyShip.Get(j);
|
||||
var car = _setWarmlyShip[j];
|
||||
if (car != null)
|
||||
{
|
||||
_setWarmlyShip.Insert(car, i);
|
||||
@ -167,23 +164,12 @@ namespace WarmlyShip
|
||||
/// <param name="g"></param>
|
||||
private void DrawWarmlyShip(Graphics g)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (int k = 0; k < _setWarmlyShip.Count; k++)
|
||||
foreach (var ship in _setWarmlyShip.GetShip())
|
||||
{
|
||||
_setWarmlyShip.Get(k)?.SetObject(j + 10, i + 20, _pictureWidth, _pictureHeight);
|
||||
_setWarmlyShip.Get(k)?.DrawningObject(g);
|
||||
|
||||
if (j >= _pictureWidth - 2 * _placeSizeWidth)
|
||||
{
|
||||
j = 0;
|
||||
i += _placeSizeHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
j += _placeSizeWidth;
|
||||
}
|
||||
// TODO установка позиции
|
||||
ship.DrawningObject(g);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,20 +14,23 @@ namespace WarmlyShip
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
private readonly List<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
public int Count => _places.Count;
|
||||
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetWarmlyShipGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@ -36,6 +39,8 @@ namespace WarmlyShip
|
||||
/// <returns></returns>
|
||||
public int Insert(T ship)
|
||||
{
|
||||
// + проверка на _maxCount
|
||||
|
||||
if (ship == null)
|
||||
{
|
||||
return -1;
|
||||
@ -55,6 +60,7 @@ namespace WarmlyShip
|
||||
/// <returns></returns>
|
||||
public int Insert(T ship, int position)
|
||||
{
|
||||
//кое что убрать (проверка позиции)
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return -1;
|
||||
@ -83,6 +89,7 @@ namespace WarmlyShip
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
// убрать удаление объекта
|
||||
if (_places[position] == null)
|
||||
{
|
||||
return null;
|
||||
@ -96,13 +103,36 @@ namespace WarmlyShip
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
if (_places[position] != null)
|
||||
get
|
||||
{
|
||||
// TODO проверка позиции
|
||||
return _places[position];
|
||||
}
|
||||
return null;
|
||||
set
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO вставка в список по позиции
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetShip()
|
||||
{
|
||||
foreach (var ship in _places)
|
||||
{
|
||||
if (ship != null)
|
||||
{
|
||||
yield return ship;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user