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