first commit
This commit is contained in:
parent
01370364b6
commit
fc3a2e91d5
@ -89,14 +89,9 @@ namespace ProjectPlane
|
|||||||
public Bitmap ShowOnMap()
|
public Bitmap ShowOnMap()
|
||||||
{
|
{
|
||||||
Shaking();
|
Shaking();
|
||||||
for (int i = 0; i < _setPlanes.Count; i++)
|
foreach (var plane in _setPlanes.GetPlanes())
|
||||||
{
|
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
|
||||||
var plane = _setPlanes.Get(i);
|
|
||||||
if (plane != null)
|
|
||||||
{
|
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new(_pictureWidth, _pictureHeight);
|
return new(_pictureWidth, _pictureHeight);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -120,11 +115,11 @@ namespace ProjectPlane
|
|||||||
int j = _setPlanes.Count - 1;
|
int j = _setPlanes.Count - 1;
|
||||||
for (int i = 0; i < _setPlanes.Count; i++)
|
for (int i = 0; i < _setPlanes.Count; i++)
|
||||||
{
|
{
|
||||||
if (_setPlanes.Get(i) == null)
|
if (_setPlanes[i] == null)
|
||||||
{
|
{
|
||||||
for (; j > i; j--)
|
for (; j > i; j--)
|
||||||
{
|
{
|
||||||
var plane = _setPlanes.Get(j);
|
var plane = _setPlanes[j];
|
||||||
if (plane != null)
|
if (plane != null)
|
||||||
{
|
{
|
||||||
_setPlanes.Insert(plane, i);
|
_setPlanes.Insert(plane, i);
|
||||||
@ -169,10 +164,10 @@ namespace ProjectPlane
|
|||||||
int width = _pictureWidth / _placeSizeWidth - 1;
|
int width = _pictureWidth / _placeSizeWidth - 1;
|
||||||
int height = _pictureHeight / _placeSizeHeight - 1;
|
int height = _pictureHeight / _placeSizeHeight - 1;
|
||||||
|
|
||||||
for (int i = 0; i < _setPlanes.Count; i++)
|
foreach (var plane in _setPlanes.GetPlanes())
|
||||||
{
|
{
|
||||||
_setPlanes.Get(i)?.SetObject((width) * _placeSizeWidth + 10, (height) * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
|
plane?.SetObject((width) * _placeSizeWidth + 10, (height) * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
|
||||||
_setPlanes.Get(i)?.DrawingObject(g);
|
plane?.DrawingObject(g);
|
||||||
|
|
||||||
if (width <= 0)
|
if (width <= 0)
|
||||||
{
|
{
|
||||||
|
@ -9,20 +9,22 @@ namespace ProjectPlane
|
|||||||
internal class SetPlanesGeneric<T> where T : class
|
internal class SetPlanesGeneric<T> 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 SetPlanesGeneric(int count)
|
public SetPlanesGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T>();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@ -43,33 +45,8 @@ namespace ProjectPlane
|
|||||||
{
|
{
|
||||||
bool isNull = false;
|
bool isNull = false;
|
||||||
int nullElem = 0;
|
int nullElem = 0;
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= _maxCount) return -1;
|
||||||
{
|
_places.Insert(position, plane);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (_places[position] == null)
|
|
||||||
{
|
|
||||||
_places[position] = plane;
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
for (int i = position + 1; i < Count; i ++)
|
|
||||||
{
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
isNull = true;
|
|
||||||
nullElem = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isNull)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
for (int i = nullElem; i > position; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
_places[position] = plane;
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -79,12 +56,12 @@ namespace ProjectPlane
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= _maxCount)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
T temp = _places[position];
|
T temp = _places[position];
|
||||||
_places[position] = null;
|
_places.RemoveAt(position);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -92,13 +69,40 @@ namespace ProjectPlane
|
|||||||
/// </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 (position < 0 || position >= Count)
|
get
|
||||||
{
|
{
|
||||||
return null;
|
if (position < 0 || position >= _maxCount)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _maxCount)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по набору до первого пустого
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T> GetPlanes()
|
||||||
|
{
|
||||||
|
foreach (var plane in _places)
|
||||||
|
{
|
||||||
|
if (plane != null)
|
||||||
|
{
|
||||||
|
yield return plane;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return _places[position];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user