Dolgov D.A. Lab Work 4 #4

Closed
devil_1nc wants to merge 6 commits from LabWork04 into LabWork03
2 changed files with 51 additions and 52 deletions
Showing only changes of commit fc3a2e91d5 - Show all commits

View File

@ -89,14 +89,9 @@ namespace ProjectPlane
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setPlanes.Count; i++)
{
var plane = _setPlanes.Get(i);
if (plane != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
}
}
foreach (var plane in _setPlanes.GetPlanes())
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
@ -120,11 +115,11 @@ namespace ProjectPlane
int j = _setPlanes.Count - 1;
for (int i = 0; i < _setPlanes.Count; i++)
{
if (_setPlanes.Get(i) == null)
if (_setPlanes[i] == null)
{
for (; j > i; j--)
{
var plane = _setPlanes.Get(j);
var plane = _setPlanes[j];
if (plane != null)
{
_setPlanes.Insert(plane, i);
@ -169,10 +164,10 @@ namespace ProjectPlane
int width = _pictureWidth / _placeSizeWidth - 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);
_setPlanes.Get(i)?.DrawingObject(g);
plane?.SetObject((width) * _placeSizeWidth + 10, (height) * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
plane?.DrawingObject(g);
if (width <= 0)
{

View File

@ -9,20 +9,22 @@ namespace ProjectPlane
internal class SetPlanesGeneric<T> 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 SetPlanesGeneric(int count)
{
_places = new T[count];
_maxCount = count;
_places = new List<T>();
}
/// <summary>
/// Добавление объекта в набор
@ -43,33 +45,8 @@ namespace ProjectPlane
{
bool isNull = false;
int nullElem = 0;
if (position < 0 || position >= Count)
{
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;
if (position < 0 || position >= _maxCount) return -1;
_places.Insert(position, plane);
return position;
}
/// <summary>
@ -79,12 +56,12 @@ namespace ProjectPlane
/// <returns></returns>
public T Remove(int position)
{
if (position < 0 || position >= Count)
if (position < 0 || position >= _maxCount)
{
return null;
}
}
T temp = _places[position];
_places[position] = null;
_places.RemoveAt(position);
return temp;
}
/// <summary>
@ -92,13 +69,40 @@ namespace ProjectPlane
/// </summary>
/// <param name="position"></param>
/// <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];
}
}
}