Реализация индексатора по картам и объектам карты

This commit is contained in:
Данияр Аглиуллов 2022-10-01 04:30:10 +04:00
parent d35ac5bb0a
commit 67fcdb8118
2 changed files with 23 additions and 14 deletions

View File

@ -29,7 +29,7 @@ namespace AirBomber
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetAirplanesGeneric<T> _setAirplanes;
public SetAirplanesGeneric<T> SetAirplanes { get; private set; }
/// <summary>
/// Карта
/// </summary>
@ -44,7 +44,7 @@ namespace AirBomber
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setAirplanes = new SetAirplanesGeneric<T>(width * height);
SetAirplanes = new SetAirplanesGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
@ -57,7 +57,7 @@ namespace AirBomber
/// <returns></returns>
public static bool operator +(MapWithSetAirplanesGeneric<T, U> map, T airplane)
{
return map._setAirplanes.Insert(airplane);
return map.SetAirplanes.Insert(airplane);
}
/// <summary>
/// Перегрузка оператора вычитания
@ -67,7 +67,7 @@ namespace AirBomber
/// <returns></returns>
public static bool operator -(MapWithSetAirplanesGeneric<T, U> map, int position)
{
return map._setAirplanes.Remove(position);
return map.SetAirplanes.Remove(position);
}
/// <summary>
/// Вывод всего набора объектов
@ -88,9 +88,9 @@ namespace AirBomber
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setAirplanes.Count; i++)
for (int i = 0; i < SetAirplanes.Count; i++)
{
var airplane = _setAirplanes[i];
var airplane = SetAirplanes[i];
if (airplane != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, airplane);
@ -116,18 +116,18 @@ namespace AirBomber
/// </summary>
private void Shaking()
{
int j = _setAirplanes.Count - 1;
for (int i = 0; i < _setAirplanes.Count; i++)
int j = SetAirplanes.Count - 1;
for (int i = 0; i < SetAirplanes.Count; i++)
{
if (_setAirplanes[i] == null)
if (SetAirplanes[i] == null)
{
for (; j > i; j--)
{
var airplane = _setAirplanes[j];
var airplane = SetAirplanes[j];
if (airplane != null)
{
_setAirplanes.Insert(airplane, i);
_setAirplanes.Remove(j);
SetAirplanes.Insert(airplane, i);
SetAirplanes.Remove(j);
break;
}
}
@ -172,9 +172,9 @@ namespace AirBomber
{
int countInLine = _pictureWidth / _placeSizeWidth;
int maxLeft = (countInLine - 1) * _placeSizeWidth;
for (int i = 0; i < _setAirplanes.Count; i++)
for (int i = 0; i < SetAirplanes.Count; i++)
{
var airplane = _setAirplanes[i];
var airplane = SetAirplanes[i];
airplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight);
airplane?.DrawningObject(g);
}

View File

@ -71,5 +71,14 @@ namespace AirBomber
return mapWithSetAirplanesGeneric;
}
}
public DrawningObject this[string ind, int indDrawningObject]
{
get
{
_mapStorages.TryGetValue(ind, out var mapWithSetAirplanesGeneric);
return mapWithSetAirplanesGeneric?.SetAirplanes[indDrawningObject];
}
}
}
}